Skip to content

Commit

Permalink
Switch to rustc-hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstange committed Mar 3, 2025
1 parent 18f72ad commit 1ca9292
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 56 deletions.
13 changes: 2 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion etw-reader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bitflags = "2.8"
num-traits = "0.2"
num-derive = "0.4"
once_cell = "1.8.0"
fxhash = "0.2.1"
rustc-hash = "2"
memoffset = "0.9"

[dependencies.windows]
Expand Down
3 changes: 2 additions & 1 deletion etw-reader/src/etw_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::ops::Deref;
use std::rc::Rc;

use once_cell::unsync::OnceCell;
use rustc_hash::FxHashMap;
use windows::core::{GUID, PCWSTR};
use windows::Win32::System::Diagnostics::Etw::{self, PropertyStruct};

Expand Down Expand Up @@ -198,7 +199,7 @@ impl TraceEventInfoRaw {
{
let is_bitmap =
map_info.Flag == super::Etw::EVENTMAP_INFO_FLAG_MANIFEST_BITMAP;
let mut map = super::FastHashMap::default();
let mut map = FxHashMap::default();
assert!(
map_info.Anonymous.MapEntryValueType
== super::Etw::EVENTMAP_ENTRY_VALUETYPE_ULONG
Expand Down
4 changes: 0 additions & 4 deletions etw-reader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use fxhash::FxHasher;
use memoffset::offset_of;
pub use windows::core::GUID;
use windows::core::{h, HSTRING, PWSTR};
Expand All @@ -13,8 +12,6 @@ use windows::Win32::System::Diagnostics::Etw::{
};

use std::borrow::Cow;
use std::collections::HashMap;
use std::hash::BuildHasherDefault;
use std::mem;
use std::path::Path;

Expand Down Expand Up @@ -44,7 +41,6 @@ use tdh_types::{PrimitiveDesc, PropertyDesc, TdhInType};
use tdh_types::{Property, TdhOutType};
use traits::EncodeUtf16;

pub type FastHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
#[repr(C)]
#[derive(Clone)]
pub struct EventTraceLogfile(Etw::EVENT_TRACE_LOGFILEW);
Expand Down
8 changes: 5 additions & 3 deletions etw-reader/src/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
//!
//! The `property` module expose the basic structures that represent the Properties an Event contains
//! based on it's Schema. This Properties can then be used to parse accordingly their values.
use rustc_hash::FxHashMap;

use super::schema::Schema;
use super::tdh_types::Property;
use super::FastHashMap;

/// Event Property information
#[derive(Clone, Debug)]
Expand All @@ -28,14 +30,14 @@ impl<'a> PropertyInfo<'a> {

pub(crate) struct PropertyIter {
properties: Vec<Property>,
pub(crate) name_to_indx: FastHashMap<String, usize>,
pub(crate) name_to_indx: FxHashMap<String, usize>,
}

impl PropertyIter {
pub fn new(schema: &Schema) -> Self {
let prop_count = schema.event_schema.property_count();
let mut properties = Vec::new();
let mut name_to_indx = FastHashMap::default();
let mut name_to_indx = FxHashMap::default();
for i in 0..prop_count {
let prop = schema.event_schema.property(i);
name_to_indx.insert(prop.name.clone(), i as usize);
Expand Down
15 changes: 8 additions & 7 deletions etw-reader/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ use std::rc::Rc;
use once_cell::unsync::OnceCell;
use windows::core::GUID;
use windows::Win32::System::Diagnostics::Etw::{self, EVENT_HEADER_FLAG_64_BIT_HEADER};
use rustc_hash::FxHashMap;

use super::etw_types::{DecodingSource, EventRecord, TraceEventInfoRaw};
use super::property::PropertyIter;
use super::tdh;
use super::tdh_types::Property;
use super::{tdh, FastHashMap};

/// Schema module errors
#[derive(Debug)]
Expand Down Expand Up @@ -46,15 +47,15 @@ struct SchemaKey {

// A map from tracelogging schema metdata to ids
struct TraceLoggingProviderIds {
ids: FastHashMap<Vec<u8>, u16>,
ids: FxHashMap<Vec<u8>, u16>,
next_id: u16,
}

impl TraceLoggingProviderIds {
fn new() -> Self {
// start the ids at 1 because of 0 is typically the value stored
TraceLoggingProviderIds {
ids: FastHashMap::default(),
ids: FxHashMap::default(),
next_id: 1,
}
}
Expand Down Expand Up @@ -114,8 +115,8 @@ impl SchemaKey {
/// Credits: [KrabsETW::schema_locator](https://github.com/microsoft/krabsetw/blob/master/krabs/krabs/schema_locator.hpp)
#[derive(Default)]
pub struct SchemaLocator {
schemas: FastHashMap<SchemaKey, Rc<Schema>>,
tracelogging_providers: FastHashMap<GUID, TraceLoggingProviderIds>,
schemas: FxHashMap<SchemaKey, Rc<Schema>>,
tracelogging_providers: FxHashMap<GUID, TraceLoggingProviderIds>,
}

pub trait EventSchema {
Expand Down Expand Up @@ -150,8 +151,8 @@ impl std::fmt::Debug for SchemaLocator {
impl SchemaLocator {
pub fn new() -> Self {
SchemaLocator {
schemas: FastHashMap::default(),
tracelogging_providers: FastHashMap::default(),
schemas: FxHashMap::default(),
tracelogging_providers: FxHashMap::default(),
}
}

Expand Down
3 changes: 2 additions & 1 deletion etw-reader/src/tdh_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ use std::rc::Rc;
use bitflags::bitflags;
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::FromPrimitive;
use rustc_hash::FxHashMap;
use windows::Win32::System::Diagnostics::Etw;

use super::etw_types::EventPropertyInfo;

#[derive(Debug, Clone, Default)]
pub struct PropertyMapInfo {
pub is_bitmap: bool,
pub map: super::FastHashMap<u32, String>,
pub map: FxHashMap<u32, String>,
}
#[derive(Debug, Clone)]
pub struct PrimitiveDesc {
Expand Down
2 changes: 1 addition & 1 deletion fxprof-processed-profile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ serde_json = "1.0"
serde = "1.0.204"
serde_derive = "1.0.188"
debugid = "0.8.0"
fxhash = "0.2.1"
rustc-hash = "2"

[dev-dependencies]
assert-json-diff = "2.0.1"
7 changes: 2 additions & 5 deletions fxprof-processed-profile/src/fast_hash_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::collections::HashMap;
use std::hash::BuildHasherDefault;
use rustc_hash::FxHashMap;

use fxhash::FxHasher;

pub type FastHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FastHashMap<K, V> = FxHashMap<K, V>;
2 changes: 1 addition & 1 deletion samply/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ serde = "1.0.204"
wholesym = { version = "0.8.0", path = "../wholesym", features = ["api"]}
platform-dirs = "0.3"
once_cell = "1.17"
fxhash = "0.2.1"
rustc-hash = "2"
mio = { version = "1", features = ["os-ext", "os-poll"] }
ctrlc = "3.4.4"
log = "0.4.21"
Expand Down
6 changes: 1 addition & 5 deletions samply/src/shared/types.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use std::collections::HashMap;
use std::hash::BuildHasherDefault;

use fxhash::FxHasher;
use linux_perf_data::linux_perf_event_reader;
use linux_perf_event_reader::constants::{
PERF_CONTEXT_GUEST, PERF_CONTEXT_GUEST_KERNEL, PERF_CONTEXT_GUEST_USER, PERF_CONTEXT_KERNEL,
PERF_CONTEXT_USER,
};
use linux_perf_event_reader::CpuMode;

pub type FastHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FastHashMap<K, V> = rustc_hash::FxHashMap<K, V>;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StackMode {
Expand Down
3 changes: 2 additions & 1 deletion samply/src/windows/etw_reader/etw_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::ops::Deref;
use std::rc::Rc;

use once_cell::unsync::OnceCell;
use rustc_hash::FxHashMap;
use windows::core::{GUID, PCWSTR};
use windows::Win32::System::Diagnostics::Etw::{self, PropertyStruct};

Expand Down Expand Up @@ -198,7 +199,7 @@ impl TraceEventInfoRaw {
{
let is_bitmap =
map_info.Flag == super::Etw::EVENTMAP_INFO_FLAG_MANIFEST_BITMAP;
let mut map = super::FastHashMap::default();
let mut map = FxHashMap::default();
assert!(
map_info.Anonymous.MapEntryValueType
== super::Etw::EVENTMAP_ENTRY_VALUETYPE_ULONG
Expand Down
4 changes: 0 additions & 4 deletions samply/src/windows/etw_reader/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use fxhash::FxHasher;
use memoffset::offset_of;
pub use windows::core::GUID;
use windows::core::{h, HSTRING, PWSTR};
Expand All @@ -13,8 +12,6 @@ use windows::Win32::System::Diagnostics::Etw::{
};

use std::borrow::Cow;
use std::collections::HashMap;
use std::hash::BuildHasherDefault;
use std::mem;
use std::path::Path;

Expand Down Expand Up @@ -44,7 +41,6 @@ use tdh_types::{PrimitiveDesc, PropertyDesc, TdhInType};
use tdh_types::{Property, TdhOutType};
use traits::EncodeUtf16;

pub type FastHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
#[repr(C)]
#[derive(Clone)]
pub struct EventTraceLogfile(Etw::EVENT_TRACE_LOGFILEW);
Expand Down
8 changes: 5 additions & 3 deletions samply/src/windows/etw_reader/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
//!
//! The `property` module expose the basic structures that represent the Properties an Event contains
//! based on it's Schema. This Properties can then be used to parse accordingly their values.
use rustc_hash::FxHashMap;

use super::schema::Schema;
use super::tdh_types::Property;
use super::FastHashMap;

/// Event Property information
#[derive(Clone, Debug)]
Expand All @@ -28,14 +30,14 @@ impl<'a> PropertyInfo<'a> {

pub(crate) struct PropertyIter {
properties: Vec<Property>,
pub(crate) name_to_indx: FastHashMap<String, usize>,
pub(crate) name_to_indx: FxHashMap<String, usize>,
}

impl PropertyIter {
pub fn new(schema: &Schema) -> Self {
let prop_count = schema.event_schema.property_count();
let mut properties = Vec::new();
let mut name_to_indx = FastHashMap::default();
let mut name_to_indx = FxHashMap::default();
for i in 0..prop_count {
let prop = schema.event_schema.property(i);
name_to_indx.insert(prop.name.clone(), i as usize);
Expand Down
15 changes: 8 additions & 7 deletions samply/src/windows/etw_reader/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use std::collections::hash_map::Entry;
use std::rc::Rc;

use once_cell::unsync::OnceCell;
use rustc_hash::FxHashMap;
use windows::core::GUID;
use windows::Win32::System::Diagnostics::Etw::{self, EVENT_HEADER_FLAG_64_BIT_HEADER};

use super::etw_types::{DecodingSource, EventRecord, TraceEventInfoRaw};
use super::property::PropertyIter;
use super::tdh;
use super::tdh_types::Property;
use super::{tdh, FastHashMap};

/// Schema module errors
#[derive(Debug)]
Expand Down Expand Up @@ -46,15 +47,15 @@ struct SchemaKey {

// A map from tracelogging schema metdata to ids
struct TraceLoggingProviderIds {
ids: FastHashMap<Vec<u8>, u16>,
ids: FxHashMap<Vec<u8>, u16>,
next_id: u16,
}

impl TraceLoggingProviderIds {
fn new() -> Self {
// start the ids at 1 because of 0 is typically the value stored
TraceLoggingProviderIds {
ids: FastHashMap::default(),
ids: FxHashMap::default(),
next_id: 1,
}
}
Expand Down Expand Up @@ -114,8 +115,8 @@ impl SchemaKey {
/// Credits: [KrabsETW::schema_locator](https://github.com/microsoft/krabsetw/blob/master/krabs/krabs/schema_locator.hpp)
#[derive(Default)]
pub struct SchemaLocator {
schemas: FastHashMap<SchemaKey, Rc<Schema>>,
tracelogging_providers: FastHashMap<GUID, TraceLoggingProviderIds>,
schemas: FxHashMap<SchemaKey, Rc<Schema>>,
tracelogging_providers: FxHashMap<GUID, TraceLoggingProviderIds>,
}

pub trait EventSchema {
Expand Down Expand Up @@ -150,8 +151,8 @@ impl std::fmt::Debug for SchemaLocator {
impl SchemaLocator {
pub fn new() -> Self {
SchemaLocator {
schemas: FastHashMap::default(),
tracelogging_providers: FastHashMap::default(),
schemas: FxHashMap::default(),
tracelogging_providers: FxHashMap::default(),
}
}

Expand Down
3 changes: 2 additions & 1 deletion samply/src/windows/etw_reader/tdh_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ use std::rc::Rc;
use bitflags::bitflags;
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::FromPrimitive;
use rustc_hash::FxHashMap;
use windows::Win32::System::Diagnostics::Etw;

use super::etw_types::EventPropertyInfo;

#[derive(Debug, Clone, Default)]
pub struct PropertyMapInfo {
pub is_bitmap: bool,
pub map: super::FastHashMap<u32, String>,
pub map: FxHashMap<u32, String>,
}
#[derive(Debug, Clone)]
pub struct PrimitiveDesc {
Expand Down

0 comments on commit 1ca9292

Please sign in to comment.