Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy etw-reader into the samply package #482

Merged
merged 4 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions Cargo.lock

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

22 changes: 11 additions & 11 deletions etw-reader/src/etw_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Deref for EventRecord {

impl EventRecord {
pub(crate) fn user_buffer(&self) -> &[u8] {
if self.UserData == std::ptr::null_mut() {
if self.UserData.is_null() {
return &[];
}
unsafe { std::slice::from_raw_parts(self.UserData as *mut _, self.UserDataLength.into()) }
Expand Down Expand Up @@ -71,21 +71,21 @@ pub const EVENT_HEADER_FLAG_32_BIT_HEADER: u16 = Etw::EVENT_HEADER_FLAG_32_BIT_H
/// [DECODING_SOURCE]: https://microsoft.github.io/windows-docs-rs/doc/bindings/Windows/Win32/Etw/struct.DECODING_SOURCE.html
#[derive(Debug)]
pub enum DecodingSource {
DecodingSourceXMLFile,
DecodingSourceWbem,
DecodingSourceWPP,
DecodingSourceTlg,
DecodingSourceMax,
XMLFile,
Wbem,
Wpp,
Tlg,
Max,
}

impl From<Etw::DECODING_SOURCE> for DecodingSource {
fn from(val: Etw::DECODING_SOURCE) -> Self {
match val {
Etw::DecodingSourceXMLFile => DecodingSource::DecodingSourceXMLFile,
Etw::DecodingSourceWbem => DecodingSource::DecodingSourceWbem,
Etw::DecodingSourceWPP => DecodingSource::DecodingSourceWPP,
Etw::DecodingSourceTlg => DecodingSource::DecodingSourceTlg,
_ => DecodingSource::DecodingSourceMax,
Etw::DecodingSourceXMLFile => DecodingSource::XMLFile,
Etw::DecodingSourceWbem => DecodingSource::Wbem,
Etw::DecodingSourceWPP => DecodingSource::Wpp,
Etw::DecodingSourceTlg => DecodingSource::Tlg,
_ => DecodingSource::Max,
}
}
}
Expand Down
24 changes: 10 additions & 14 deletions etw-reader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
use fxhash::FxHasher;
use memoffset::offset_of;
pub use windows::core::GUID;
use windows::core::{h, HSTRING, PWSTR};
use windows::Win32::Foundation::{
GetLastError, ERROR_INSUFFICIENT_BUFFER, ERROR_MORE_DATA, MAX_PATH,
};
use windows::Win32::System::Diagnostics::Etw;
use windows::Win32::System::Diagnostics::Etw::{
EnumerateTraceGuids, EnumerateTraceGuidsEx, TraceGuidQueryInfo, TraceGuidQueryList,
CONTROLTRACE_HANDLE, EVENT_TRACE_FLAG, TRACE_GUID_INFO, TRACE_GUID_PROPERTIES,
TRACE_PROVIDER_INSTANCE_INFO,
};

use crate::parser::{Parser, ParserError, TryParse};
use crate::schema::SchemaLocator;
use crate::tdh_types::{PrimitiveDesc, PropertyDesc, TdhInType};
use crate::traits::EncodeUtf16;

#[macro_use]
extern crate memoffset;

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

use etw_types::EventRecord;
use fxhash::FxHasher;
use tdh_types::{Property, TdhOutType};
use windows::Win32::System::Diagnostics::Etw;

// typedef ULONG64 TRACEHANDLE, *PTRACEHANDLE;
pub(crate) type TraceHandle = u64;
pub const INVALID_TRACE_HANDLE: TraceHandle = u64::MAX;
Expand All @@ -46,7 +37,12 @@ pub mod utils;
//pub mod trace;
//pub mod provider;

pub use windows::core::GUID;
use etw_types::EventRecord;
use parser::{Parser, ParserError, TryParse};
use schema::SchemaLocator;
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)]
Expand Down
8 changes: 2 additions & 6 deletions etw-reader/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ impl<'a> Parser<'a> {
// as the size of AppName

// Fallback to Tdh
return Ok(
tdh::property_size(self.event.record(), &property.name).unwrap() as usize,
);
Ok(tdh::property_size(self.event.record(), &property.name).unwrap() as usize)
}
PropertyLength::Length(length) => {
// TODO: Study heuristic method used in krabsetw :)
Expand Down Expand Up @@ -222,9 +220,7 @@ impl<'a> Parser<'a> {
}
}
}
return Ok(
tdh::property_size(self.event.record(), &property.name).unwrap() as usize,
);
Ok(tdh::property_size(self.event.record(), &property.name).unwrap() as usize)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions etw-reader/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,12 @@ impl<'a> TypedEvent<'a> {
}
}

impl<'a> PartialEq for TypedEvent<'a> {
impl PartialEq for TypedEvent<'_> {
fn eq(&self, other: &Self) -> bool {
self.schema.event_schema.event_id() == other.schema.event_schema.event_id()
&& self.schema.event_schema.provider_guid() == other.schema.event_schema.provider_guid()
&& self.schema.event_schema.event_version() == other.schema.event_schema.event_version()
}
}

impl<'a> Eq for TypedEvent<'a> {}
impl Eq for TypedEvent<'_> {}
3 changes: 2 additions & 1 deletion samply/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ num-derive = "0.4"
runas = "1.2.0"
which = "7.0.0"
winver = "1"
etw-reader = { path = "../etw-reader" }

# etw-reader = { path = "../etw-reader" }
# linux-perf-data = "0.10.1"

[target.'cfg(windows)'.dependencies.windows]
Expand Down
7 changes: 4 additions & 3 deletions samply/src/windows/coreclr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use std::convert::TryInto;
use std::fmt::Display;

use bitflags::bitflags;
use etw_reader::parser::{Parser, TryParse};
use etw_reader::schema::TypedEvent;
use etw_reader::{self, event_properties_to_string};
use fxprof_processed_profile::*;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
Expand All @@ -14,6 +11,10 @@ use super::elevated_helper::ElevatedRecordingProps;
use crate::shared::recording_props::{CoreClrProfileProps, ProfileCreationProps};
use crate::windows::profile_context::{KnownCategory, ProfileContext};

use super::etw_reader::event_properties_to_string;
use super::etw_reader::parser::{Parser, TryParse};
use super::etw_reader::schema::TypedEvent;

struct SavedMarkerInfo {
start_timestamp_raw: u64,
name: String,
Expand Down
Loading