Skip to content

Commit

Permalink
Add --unknown-event-markers to emit markers for unknown ETW events
Browse files Browse the repository at this point in the history
  • Loading branch information
vvuk committed May 23, 2024
1 parent ae4fd7f commit 0b51cf6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target
profile.json
profile.syms.json
.DS_Store
.direnv/

Expand Down
7 changes: 7 additions & 0 deletions samply/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ pub struct ProfileCreationArgs {
/// in the profile.json, instead of a sidecar file.)
#[arg(long)]
unstable_presymbolicate: bool,

/// Emit markers for any unknown ETW events that are encountered.
#[cfg(target_os = "windows")]
#[arg(long)]
unknown_event_markers: bool,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -413,6 +418,7 @@ impl ImportArgs {
override_arch: self.override_arch.clone(),
unstable_presymbolicate: self.profile_creation_args.unstable_presymbolicate,
coreclr: to_coreclr_profile_props(&self.coreclr),
unknown_event_markers: self.profile_creation_args.unknown_event_markers,
}
}

Expand Down Expand Up @@ -518,6 +524,7 @@ impl RecordArgs {
override_arch: None,
unstable_presymbolicate: self.profile_creation_args.unstable_presymbolicate,
coreclr: to_coreclr_profile_props(&self.coreclr),
unknown_event_markers: self.profile_creation_args.unknown_event_markers,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions samply/src/shared/recording_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub struct ProfileCreationProps {
pub unstable_presymbolicate: bool,
/// CoreCLR specific properties.
pub coreclr: CoreClrProfileProps,
/// Create markers for unknown events.
pub unknown_event_markers: bool,
}

/// Properties which are meaningful for launching and recording a fresh process.
Expand Down
6 changes: 3 additions & 3 deletions samply/src/windows/coreclr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct CoreClrContext {
props: CoreClrProfileProps,
last_marker_on_thread: HashMap<u32, MarkerHandle>,
gc_markers_on_thread: HashMap<u32, HashMap<&'static str, SavedMarkerInfo>>,
unknown_event_markers: bool,
}

impl CoreClrContext {
Expand All @@ -36,6 +37,7 @@ impl CoreClrContext {
props: profile_creation_props.coreclr,
last_marker_on_thread: HashMap::new(),
gc_markers_on_thread: HashMap::new(),
unknown_event_markers: profile_creation_props.unknown_event_markers,
}
}

Expand Down Expand Up @@ -382,8 +384,6 @@ pub fn handle_coreclr_event(
s: &TypedEvent,
parser: &mut Parser,
) {
let show_unknown_events = false;

let (gc_markers, gc_suspensions, gc_allocs, event_stacks) = (
coreclr_context.props.gc_markers,
coreclr_context.props.gc_suspensions,
Expand Down Expand Up @@ -717,7 +717,7 @@ pub fn handle_coreclr_event(
_ => {}
}

if !handled && show_unknown_events {
if !handled && coreclr_context.unknown_event_markers {
let text = event_properties_to_string(s, parser, None);
let marker_handle = context.add_thread_instant_marker(
timestamp_raw,
Expand Down
6 changes: 6 additions & 0 deletions samply/src/windows/etw_gecko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ pub fn profile_pid_from_etl_file(context: &mut ProfileContext, etl_file: &Path)
let pid: u32 = parser.parse("ProcessId");
context.handle_process_dcend(timestamp_raw, pid);
}
"MSNT_SystemTrace/Process/Terminate" => {
// nothing, but we don't want a marker for it
}
"MSNT_SystemTrace/StackWalk/Stack" => {
let tid: u32 = parser.parse("StackThread");
let pid: u32 = parser.parse("StackProcess");
Expand Down Expand Up @@ -206,6 +209,9 @@ pub fn profile_pid_from_etl_file(context: &mut ProfileContext, etl_file: &Path)
let path: String = parser.try_parse("FileName").unwrap();
context.handle_image_load(timestamp_raw, pid, image_base, image_size, path);
}
"MSNT_SystemTrace/Image/UnLoad" => {
// nothing, but we don't want a marker for it
}
"Microsoft-Windows-DxgKrnl/VSyncDPC/Info " => {
context.handle_vsync(timestamp_raw);
}
Expand Down
4 changes: 4 additions & 0 deletions samply/src/windows/profile_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,10 @@ impl ProfileContext {
task_and_op: &str,
stringified_properties: String,
) {
if !self.profile_creation_props.unknown_event_markers {
return;
}

let Some(thread) = self.threads.get_mut(&tid) else {
return;
};
Expand Down

0 comments on commit 0b51cf6

Please sign in to comment.