Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Initial import #2

Closed
wants to merge 15 commits into from
16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@ default = ["common_schema"]

[dependencies]
tracing = {version = "0.1", default-features = false, features = ["std"]}
tracing-core = {version = "0.1", default-features = false}
tracing-subscriber = {version="0.3", default-features = false, features=["std", "fmt", "registry"]}
tracelogging = ">= 1.1.0"
tracelogging_dynamic = ">= 1.1.0"
eventheader = "0.3.1"
eventheader_dynamic = "0.3.1"
tracelogging = ">= 1.2.0"
tracelogging_dynamic = ">= 1.2.0"
eventheader = ">= 0.4"
eventheader_dynamic = ">= 0.4"
chrono = {version="0.4", default-features = false, features=["std"]}
once_cell = "1.18"
const_format = {version="0.2", features=["rust_1_64"]}
atoi = "2"
dashmap = "5.5"
paste = "1"

[dev-dependencies]
criterion = {version="0.5", features=["html_reports"]}
tracing = {version = "0.1", default-features = false, features = ["std", "attributes"]}

[target.'cfg(windows)'.dev-dependencies]
windows = {version="0.48", features=["Win32_System_Diagnostics_Etw", "Win32_Foundation", "Win32_System_Time"]}
windows = {version="0.56", features=["Win32_System_Diagnostics_Etw", "Win32_Foundation", "Win32_System_Time"]}
etw_helpers = {version="0.1", path="../etw_helpers"}

[[bench]]
Expand Down
26 changes: 26 additions & 0 deletions benches/etw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@ pub fn etw_benchmark(c: &mut Criterion) {
})
});
}

// etw_events
{
let mut event_group = c.benchmark_group("etw_events");
event_group.warm_up_time(std::time::Duration::from_millis(500));

event_group.bench_function("empty", |b| {
b.iter(|| {
etw_event!(name: "evtname", Level::INFO, 1, "Enabled event!");
})
});

event_group.bench_function("3 fields", |b| {
b.iter(|| {
etw_event!(
name: "evtname",
Level::INFO,
1,
field1 = 1,
field2 = "asdf",
field3 = 1.1,
"Enabled event!"
);
})
});
}
}

#[cfg(not(target_os = "windows"))]
Expand Down
26 changes: 26 additions & 0 deletions benches/user_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ pub fn user_events_benchmark(c: &mut Criterion) {
})
});
}

// etw_events
{
let mut event_group = c.benchmark_group("etw_events");
event_group.warm_up_time(std::time::Duration::from_millis(500));

event_group.bench_function("empty", |b| {
b.iter(|| {
etw_event!(name: "evtname", Level::INFO, 1, "Enabled event!");
})
});

event_group.bench_function("3 fields", |b| {
b.iter(|| {
etw_event!(
name: "evtname",
Level::INFO,
1,
field1 = 1,
field2 = "asdf",
field3 = 1.1,
"Enabled event!"
);
})
});
}
}

#[cfg(not(target_os = "linux"))]
Expand Down
24 changes: 24 additions & 0 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use tracing::{event, Level};
use tracing_etw::LayerBuilder;
use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new("ExampleProvBasic").build()) // Collects everything
.with(LayerBuilder::new_common_schema_events("ExampleProvBasic_CS").build_with_target("geneva"))
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();

#[allow(non_snake_case)]
let fieldB = "asdf";
event!(
Level::INFO,
fieldC = b'x',
fieldB,
fieldA = 7,
"inside {}!",
"main"
);

event!(target: "geneva", Level::ERROR, "error event");
}
12 changes: 12 additions & 0 deletions examples/etw_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use tracing::Level;
use tracing_etw::{etw_event, LayerBuilder};
use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new_common_schema_events("ExampleProvEtwEvent_CS").build())
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();

etw_event!(name: "EtwEventName", Level::ERROR, 5, "An event with a name and keyword!");
}
17 changes: 17 additions & 0 deletions examples/instrument.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use tracing::instrument;
use tracing_etw::LayerBuilder;
use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};

#[instrument]
fn test_function(x: u32, y: f64) -> f64 {
x as f64 + y
}

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new("ExampleProvInstrument").build()) // Collects everything
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();

test_function(1, 2.0);
}
25 changes: 25 additions & 0 deletions examples/span.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use tracing::{event, span, Level};
use tracing_etw::LayerBuilder;
use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new_common_schema_events("ExampleProvSpan_CS").build())
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();

let span = span!(
Level::INFO,
"span name",
fieldC = b'x',
fieldB = "asdf",
fieldA = 7,
"inside {}!",
"main"
);
let _ = span.enter();

event!(Level::ERROR, "error event");

span.record("fieldB", 12345);
}
15 changes: 15 additions & 0 deletions examples/stress.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use tracing::Level;
use tracing_etw::{etw_event, LayerBuilder};
use tracing_subscriber::{self, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new("ExampleProvEtwEventStress").build())
.init();

for i in 0..500000 {
etw_event!(name: "EtwEventName", Level::ERROR, 5, "An event with a name and keyword!");

etw_event!(name: "Event2", Level::ERROR, 5, idx=i,a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10,k=11,l=12,m=13,n=14,o=15,p=16,q=17,r=18,s=19,t=20,u=21,v=22,w=23,x=24,y=25,z=26);
}
}
14 changes: 5 additions & 9 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use tracing::{event, span, Level};
use tracing_etw::LayerBuilder;
use tracing_etw::{etw_event, LayerBuilder};
use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};

// #[tracing::instrument]
Expand All @@ -8,15 +8,11 @@ use tracing_subscriber::{self, fmt::format::FmtSpan, prelude::*};
// }

fn main() {
// let subscriber = tracing_subscriber::fmt::fmt()
// .with_span_events(FmtSpan::FULL)
// .without_time();

let subscriber = tracing_subscriber::registry()
tracing_subscriber::registry()
.with(LayerBuilder::new("test").build()) // Collects everything
.with(LayerBuilder::new_common_schema_events("test2").build_with_target("geneva"))
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE));
let _sub = subscriber.try_init();
.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE))
.init();

#[allow(non_snake_case)]
let fieldB = "asdf";
Expand Down Expand Up @@ -47,5 +43,5 @@ fn main() {
drop(_enter);
drop(span);

event!(target: "geneva", Level::INFO, "Only for geneva!");
etw_event!(target: "geneva", name: "EtwEventName", Level::ERROR, 5, "Only for geneva!");
}
Loading
Loading