diff --git a/examples/rust/Cargo.lock b/examples/rust/Cargo.lock index 04d32196..09fee1a7 100644 --- a/examples/rust/Cargo.lock +++ b/examples/rust/Cargo.lock @@ -81,6 +81,7 @@ dependencies = [ "libc", "lru", "rustc-demangle", + "tracing", ] [[package]] @@ -458,6 +459,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +[[package]] +name = "log" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" + [[package]] name = "lru" version = "0.10.1" @@ -467,6 +474,15 @@ dependencies = [ "hashbrown 0.13.2", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + [[package]] name = "memchr" version = "2.5.0" @@ -524,6 +540,16 @@ dependencies = [ "libc", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num_enum" version = "0.5.7" @@ -567,6 +593,18 @@ version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "pin-project-lite" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" + [[package]] name = "pkg-config" version = "0.3.25" @@ -633,6 +671,8 @@ dependencies = [ "libbpf-rs", "libc", "nix 0.24.2", + "tracing", + "tracing-subscriber", ] [[package]] @@ -664,6 +704,15 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + [[package]] name = "regex-syntax" version = "0.6.27" @@ -768,6 +817,21 @@ dependencies = [ "serde", ] +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -892,6 +956,16 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "toml" version = "0.5.9" @@ -915,6 +989,68 @@ dependencies = [ "structopt", ] +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + [[package]] name = "unicode-ident" version = "1.0.3" @@ -933,6 +1069,12 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vec_map" version = "0.8.2" diff --git a/examples/rust/profile/Cargo.toml b/examples/rust/profile/Cargo.toml index b897af4a..9899e44c 100644 --- a/examples/rust/profile/Cargo.toml +++ b/examples/rust/profile/Cargo.toml @@ -6,11 +6,13 @@ license = "GPL-2.0 OR BSD-3-Clause" edition = "2021" [dependencies] -blazesym = { path = "../../../blazesym" } +blazesym = { path = "../../../blazesym", features = ["tracing"] } clap = { version = "4.0", features = ["derive"] } libbpf-rs = "0.19" libc = "*" nix = "0.24.1" +tracing = "0.1" +tracing-subscriber = {version = "0.3", features = ["ansi", "env-filter", "fmt"]} [build-dependencies] libbpf-cargo = "0.13" diff --git a/examples/rust/profile/src/main.rs b/examples/rust/profile/src/main.rs index b34e9edc..1007de86 100644 --- a/examples/rust/profile/src/main.rs +++ b/examples/rust/profile/src/main.rs @@ -5,10 +5,17 @@ use std::time::Duration; use blazesym::symbolize; +use clap::ArgAction; use clap::Parser; use nix::unistd::close; +use tracing::subscriber::set_global_default as set_global_subscriber; +use tracing_subscriber::filter::LevelFilter; +use tracing_subscriber::fmt::format::FmtSpan; +use tracing_subscriber::fmt::time::SystemTime; +use tracing_subscriber::FmtSubscriber; + #[path = "bpf/.output/profile.skel.rs"] mod profile; mod syscall; @@ -181,10 +188,27 @@ struct Args { /// Sampling frequency #[arg(short, default_value_t = 1)] freq: u64, + /// Increase verbosity (can be supplied multiple times). + #[arg(short = 'v', long = "verbose", global = true, action = ArgAction::Count)] + verbosity: u8, } fn main() -> Result<(), Error> { let args = Args::parse(); + let level = match args.verbosity { + 0 => LevelFilter::WARN, + 1 => LevelFilter::INFO, + 2 => LevelFilter::DEBUG, + _ => LevelFilter::TRACE, + }; + + let subscriber = FmtSubscriber::builder() + .with_max_level(level) + .with_span_events(FmtSpan::FULL) + .with_timer(SystemTime) + .finish(); + let () = set_global_subscriber(subscriber).expect("failed to set tracing subscriber"); + let freq = if args.freq < 1 { 1 } else { args.freq }; let symbolizer = symbolize::Symbolizer::new();