Skip to content

Commit e15f474

Browse files
d-e-s-oanakryiko
authored andcommitted
examples/rust/profile: Add -v/--verbose option
Add the -v/--verbose option to control tracing of blazesym internals. Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent 838e986 commit e15f474

File tree

3 files changed

+169
-1
lines changed

3 files changed

+169
-1
lines changed

examples/rust/Cargo.lock

Lines changed: 142 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rust/profile/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ license = "GPL-2.0 OR BSD-3-Clause"
66
edition = "2021"
77

88
[dependencies]
9-
blazesym = { path = "../../../blazesym" }
9+
blazesym = { path = "../../../blazesym", features = ["tracing"] }
1010
clap = { version = "4.0", features = ["derive"] }
1111
libbpf-rs = "0.19"
1212
libc = "*"
1313
nix = "0.24.1"
14+
tracing = "0.1"
15+
tracing-subscriber = {version = "0.3", features = ["ansi", "env-filter", "fmt"]}
1416

1517
[build-dependencies]
1618
libbpf-cargo = "0.13"

examples/rust/profile/src/main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ use std::time::Duration;
55

66
use blazesym::symbolize;
77

8+
use clap::ArgAction;
89
use clap::Parser;
910

1011
use nix::unistd::close;
1112

13+
use tracing::subscriber::set_global_default as set_global_subscriber;
14+
use tracing_subscriber::filter::LevelFilter;
15+
use tracing_subscriber::fmt::format::FmtSpan;
16+
use tracing_subscriber::fmt::time::SystemTime;
17+
use tracing_subscriber::FmtSubscriber;
18+
1219
#[path = "bpf/.output/profile.skel.rs"]
1320
mod profile;
1421
mod syscall;
@@ -181,10 +188,27 @@ struct Args {
181188
/// Sampling frequency
182189
#[arg(short, default_value_t = 1)]
183190
freq: u64,
191+
/// Increase verbosity (can be supplied multiple times).
192+
#[arg(short = 'v', long = "verbose", global = true, action = ArgAction::Count)]
193+
verbosity: u8,
184194
}
185195

186196
fn main() -> Result<(), Error> {
187197
let args = Args::parse();
198+
let level = match args.verbosity {
199+
0 => LevelFilter::WARN,
200+
1 => LevelFilter::INFO,
201+
2 => LevelFilter::DEBUG,
202+
_ => LevelFilter::TRACE,
203+
};
204+
205+
let subscriber = FmtSubscriber::builder()
206+
.with_max_level(level)
207+
.with_span_events(FmtSpan::FULL)
208+
.with_timer(SystemTime)
209+
.finish();
210+
let () = set_global_subscriber(subscriber).expect("failed to set tracing subscriber");
211+
188212
let freq = if args.freq < 1 { 1 } else { args.freq };
189213

190214
let symbolizer = symbolize::Symbolizer::new();

0 commit comments

Comments
 (0)