Skip to content

Commit

Permalink
cargo fmt (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robo210 authored Dec 9, 2024
1 parent 515f2d6 commit 2d1e313
Show file tree
Hide file tree
Showing 19 changed files with 899 additions and 909 deletions.
4 changes: 3 additions & 1 deletion benches/etw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use tracing_subscriber::{self, prelude::*};
pub fn etw_benchmark(c: &mut Criterion) {
let builder = LayerBuilder::new("etw_bench");
let provider_id = builder.get_provider_id();
let _subscriber = tracing_subscriber::registry().with(builder.build().unwrap()).init();
let _subscriber = tracing_subscriber::registry()
.with(builder.build().unwrap())
.init();

let etw_session = SessionBuilder::new_file_mode(
"tokio-tracing-etw-bench",
Expand Down
4 changes: 3 additions & 1 deletion benches/user_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use tracing_subscriber::{self, prelude::*};
#[cfg(target_os = "linux")]
pub fn user_events_benchmark(c: &mut Criterion) {
let builder = LayerBuilder::new("user_events_bench");
let _subscriber = tracing_subscriber::registry().with(builder.build().unwrap()).init();
let _subscriber = tracing_subscriber::registry()
.with(builder.build().unwrap())
.init();

// Disabled provider
// {
Expand Down
52 changes: 28 additions & 24 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
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().unwrap()) // Collects everything
.with(LayerBuilder::new_common_schema_events("ExampleProvBasic_CS").build_with_target("geneva").unwrap())
.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");
}
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().unwrap()) // Collects everything
.with(
LayerBuilder::new_common_schema_events("ExampleProvBasic_CS")
.build_with_target("geneva")
.unwrap(),
)
.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");
}
54 changes: 29 additions & 25 deletions examples/span.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
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().unwrap())
.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);
}
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()
.unwrap(),
)
.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);
}
34 changes: 19 additions & 15 deletions examples/stress.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
use tracing::Level;
use tracing_etw::{etw_event, LayerBuilder};
use tracing_subscriber::{self, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(LayerBuilder::new("ExampleProvEtwEventStress").build().unwrap())
.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);
}
}
use tracing::Level;
use tracing_etw::{etw_event, LayerBuilder};
use tracing_subscriber::{self, prelude::*};

fn main() {
tracing_subscriber::registry()
.with(
LayerBuilder::new("ExampleProvEtwEventStress")
.build()
.unwrap(),
)
.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);
}
}
40 changes: 20 additions & 20 deletions src/_details.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Module for internal structs that need to be publicly accessible,
// but should not be directly used by consumers of the crate.
//
// Implementations for these structs are contained in other files.

// Public with public fields because the `etw_event!` macro needs to create it at invocation site.
#[doc(hidden)]
#[repr(C)]
pub struct EventMetadata {
pub kw: u64,
pub identity: tracing::callsite::Identifier,
pub event_tag: u32,
}

// An EventMetadata with a hash, because Identity doesn't implement comparisons but we need a stable ordering.
#[derive(Clone)]
pub(crate) struct ParsedEventMetadata {
pub(crate) identity_hash: u64,
pub(crate) meta: &'static EventMetadata
}
// Module for internal structs that need to be publicly accessible,
// but should not be directly used by consumers of the crate.
//
// Implementations for these structs are contained in other files.

// Public with public fields because the `etw_event!` macro needs to create it at invocation site.
#[doc(hidden)]
#[repr(C)]
pub struct EventMetadata {
pub kw: u64,
pub identity: tracing::callsite::Identifier,
pub event_tag: u32,
}

// An EventMetadata with a hash, because Identity doesn't implement comparisons but we need a stable ordering.
#[derive(Clone)]
pub(crate) struct ParsedEventMetadata {
pub(crate) identity_hash: u64,
pub(crate) meta: &'static EventMetadata,
}
11 changes: 8 additions & 3 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ fn main() {
#[cfg(not(feature = "global_filter"))]
let registry = registry.with(LayerBuilder::new("test").build().unwrap());
#[cfg(all(not(feature = "global_filter"), feature = "common_schema"))]
let registry = registry.with(LayerBuilder::new_common_schema_events("test2").build_with_target("geneva").unwrap());
let registry = registry.with(
LayerBuilder::new_common_schema_events("test2")
.build_with_target("geneva")
.unwrap(),
);
#[cfg(not(feature = "global_filter"))]
let registry = registry.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE));

let registry =
registry.with(tracing_subscriber::fmt::layer().with_span_events(FmtSpan::ACTIVE));

#[cfg(feature = "global_filter")]
let registry = registry.with(LayerBuilder::new("test").build_global_filter().unwrap());

Expand Down
26 changes: 13 additions & 13 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum EtwError {
#[error("Provider group GUID must not be zeros")]
EmptyProviderGroupGuid,
#[error("Provider group names must be lower case ASCII or numeric digits: {0:?}")]
InvalidProviderGroupCharacters(String),
#[error("Linux provider names must be ASCII alphanumeric: {0:?}")]
InvalidProviderNameCharacters(String),
#[error("Linux provider name and provider group must less than 234 characters combined. Current length: {0:?}")]
TooManyCharacters(usize)
}
use thiserror::Error;

#[derive(Error, Debug)]
pub enum EtwError {
#[error("Provider group GUID must not be zeros")]
EmptyProviderGroupGuid,
#[error("Provider group names must be lower case ASCII or numeric digits: {0:?}")]
InvalidProviderGroupCharacters(String),
#[error("Linux provider names must be ASCII alphanumeric: {0:?}")]
InvalidProviderNameCharacters(String),
#[error("Linux provider name and provider group must less than 234 characters combined. Current length: {0:?}")]
TooManyCharacters(usize),
}
111 changes: 58 additions & 53 deletions src/layer/filter.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,58 @@
use tracing::Subscriber;
use tracing_subscriber::{layer::Filter, registry::LookupSpan};

use crate::{native::{EventWriter, ProviderTypes}, statics::get_event_metadata};

use super::*;

impl<S, Mode> Filter<S> for EtwFilter<S, Mode>
where
S: Subscriber + for<'a> LookupSpan<'a>,
Mode: ProviderTypes + 'static,
Mode::Provider: EventWriter<Mode> + 'static,
{
fn callsite_enabled(
&self,
metadata: &'static tracing::Metadata<'static>,
) -> tracing::subscriber::Interest {
let etw_meta = get_event_metadata(&metadata.callsite());
let keyword = if let Some(meta) = etw_meta {
meta.kw
} else {
self.layer.default_keyword
};

if Mode::supports_enable_callback() {
if self.layer.provider.enabled(metadata.level(), keyword) {
tracing::subscriber::Interest::always()
} else {
tracing::subscriber::Interest::never()
}
} else {
// Returning "sometimes" means the enabled function will be called every time an event or span is created from the callsite.
// This will let us perform a global "is enabled" check each time.
tracing::subscriber::Interest::sometimes()
}
}

fn enabled(
&self,
metadata: &tracing::Metadata<'_>,
_cx: &tracing_subscriber::layer::Context<'_, S>,
) -> bool {
self.layer.is_enabled(&metadata.callsite(), metadata.level())
}

fn event_enabled(
&self,
event: &tracing::Event<'_>,
_cx: &tracing_subscriber::layer::Context<'_, S>,
) -> bool {
self.layer.is_enabled(&event.metadata().callsite(), event.metadata().level())
}
}
use tracing::Subscriber;
use tracing_subscriber::{layer::Filter, registry::LookupSpan};

use crate::{
native::{EventWriter, ProviderTypes},
statics::get_event_metadata,
};

use super::*;

impl<S, Mode> Filter<S> for EtwFilter<S, Mode>
where
S: Subscriber + for<'a> LookupSpan<'a>,
Mode: ProviderTypes + 'static,
Mode::Provider: EventWriter<Mode> + 'static,
{
fn callsite_enabled(
&self,
metadata: &'static tracing::Metadata<'static>,
) -> tracing::subscriber::Interest {
let etw_meta = get_event_metadata(&metadata.callsite());
let keyword = if let Some(meta) = etw_meta {
meta.kw
} else {
self.layer.default_keyword
};

if Mode::supports_enable_callback() {
if self.layer.provider.enabled(metadata.level(), keyword) {
tracing::subscriber::Interest::always()
} else {
tracing::subscriber::Interest::never()
}
} else {
// Returning "sometimes" means the enabled function will be called every time an event or span is created from the callsite.
// This will let us perform a global "is enabled" check each time.
tracing::subscriber::Interest::sometimes()
}
}

fn enabled(
&self,
metadata: &tracing::Metadata<'_>,
_cx: &tracing_subscriber::layer::Context<'_, S>,
) -> bool {
self.layer
.is_enabled(&metadata.callsite(), metadata.level())
}

fn event_enabled(
&self,
event: &tracing::Event<'_>,
_cx: &tracing_subscriber::layer::Context<'_, S>,
) -> bool {
self.layer
.is_enabled(&event.metadata().callsite(), event.metadata().level())
}
}
Loading

0 comments on commit 2d1e313

Please sign in to comment.