-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
899 additions
and
909 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
Oops, something went wrong.