Skip to content

Commit

Permalink
examples/rust/profile: Add -v/--verbose option
Browse files Browse the repository at this point in the history
Add the -v/--verbose option to control tracing of blazesym internals.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o authored and anakryiko committed Aug 22, 2023
1 parent 205132f commit 26bc827
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 1 deletion.
142 changes: 142 additions & 0 deletions examples/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion examples/rust/profile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 24 additions & 0 deletions examples/rust/profile/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 26bc827

Please sign in to comment.