-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
56af135
commit 4857a46
Showing
4 changed files
with
73 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,8 @@ Cargo.lock | |
*.txt | ||
.DS_Store | ||
|
||
# flamegraphs, probably | ||
**/*.svg | ||
flamegraph.svg | ||
|
||
# tracing-flame output | ||
**.folded |
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,38 +1,72 @@ | ||
use clap::{Parser, ValueEnum}; | ||
use liblasso::benches::bench::{benchmarks, BenchType}; | ||
use tracing_subscriber::{self, fmt::format::FmtSpan}; | ||
|
||
use clap::Parser; | ||
use std::{fs::File, io::BufWriter}; | ||
use tracing_flame::FlameLayer; | ||
use tracing_subscriber::{self, fmt, fmt::format::FmtSpan, prelude::*, registry::Registry}; | ||
|
||
/// Search for a pattern in a file and display the lines that contain it. | ||
#[derive(Parser, Debug)] | ||
struct Cli { | ||
/// Whether to present in chart format | ||
#[clap(long, short, action)] | ||
chart: bool, | ||
/// Output format | ||
#[clap(short, long, value_enum, default_value_t = Format::Default)] | ||
format: Format, | ||
|
||
/// Type of benchmark to run | ||
#[clap(long, value_enum)] | ||
name: BenchType, | ||
} | ||
|
||
#[derive(Debug, Clone, ValueEnum)] | ||
enum Format { | ||
Default, | ||
Texray, | ||
Flamegraph, | ||
} | ||
|
||
fn setup_global_subscriber() -> impl Drop { | ||
let fmt_layer = fmt::Layer::default(); | ||
|
||
let (flame_layer, _guard) = FlameLayer::with_file("./tracing.folded").unwrap(); | ||
|
||
tracing_subscriber::registry() | ||
.with(fmt_layer) | ||
.with(flame_layer) | ||
.init(); | ||
|
||
_guard | ||
} | ||
|
||
fn main() { | ||
let args = Cli::parse(); | ||
if args.chart { | ||
tracing_texray::init(); | ||
for (span, bench) in benchmarks(args.name).into_iter() { | ||
tracing_texray::examine(span.to_owned()).in_scope(bench); | ||
match args.format { | ||
Format::Default => { | ||
let collector = tracing_subscriber::fmt() | ||
.with_max_level(tracing::Level::TRACE) | ||
.with_span_events(FmtSpan::CLOSE) | ||
.finish(); | ||
tracing::subscriber::set_global_default(collector) | ||
.expect("setting tracing default failed"); | ||
for (span, bench) in benchmarks(args.name).into_iter() { | ||
span.to_owned().in_scope(|| { | ||
bench(); | ||
tracing::info!("Bench Complete"); | ||
}); | ||
} | ||
} | ||
Format::Texray => { | ||
tracing_texray::init(); | ||
for (span, bench) in benchmarks(args.name).into_iter() { | ||
tracing_texray::examine(span.to_owned()).in_scope(bench); | ||
} | ||
} | ||
} else { | ||
let collector = tracing_subscriber::fmt() | ||
.with_max_level(tracing::Level::TRACE) | ||
.with_span_events(FmtSpan::CLOSE) | ||
.finish(); | ||
tracing::subscriber::set_global_default(collector).expect("setting tracing default failed"); | ||
for (span, bench) in benchmarks(args.name).into_iter() { | ||
span.to_owned().in_scope(|| { | ||
bench(); | ||
tracing::info!("Bench Complete"); | ||
}); | ||
Format::Flamegraph => { | ||
let _guard = setup_global_subscriber(); | ||
for (span, bench) in benchmarks(args.name).into_iter() { | ||
span.to_owned().in_scope(|| { | ||
bench(); | ||
tracing::info!("Bench Complete"); | ||
}); | ||
} | ||
} | ||
} | ||
} |