Skip to content

Commit

Permalink
chore(term): support flamegraph
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Jul 12, 2024
1 parent 0a1d4d3 commit e09f315
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 7 deletions.
169 changes: 168 additions & 1 deletion Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ moka = { version = "0.12.8", features = ["future"] }
octocrab = { version = "0.38.0", features = ["rustls-webpki-tokio"] }
once_cell = { version = "1.19.0" }
parse_duration = { version = "2.1.1" }
pprof = { version = "0.13", features = ["flamegraph", "criterion"] }
proptest = { version = "1.5.0" }
rand = { version = "0.8.5" }
reqwest = { version = "0.11.27", default-features = false, features = ["rustls-tls", "json"] }
Expand All @@ -53,6 +54,9 @@ tracing = { version = "0.1.40" }
tracing-subscriber = { version = "0.3.18", features = ["smallvec", "fmt", "ansi", "std", "env-filter", "time"], default-features = false }
url = { version = "2.5.2" }

[profile.bench]
# To enable framegraph
debug = true

[workspace.lints.rust]
unsafe_code = "forbid"
Expand Down
1 change: 1 addition & 0 deletions crates/synd_term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ criterion = { workspace = true }
fake = { workspace = true }
insta = { workspace = true }
kvsd = { workspace = true }
pprof = { workspace = true }
proptest = { workspace = true }
serial_test = { version = "3.1.1", default-features = false, features = ["async", "file_locks"] }
tempfile = { workspace = true }
Expand Down
11 changes: 6 additions & 5 deletions crates/synd_term/benches/render.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use criterion::Criterion;
use pprof::criterion::{Output, PProfProfiler};

mod bench {
use criterion::Criterion;
use synd_term::{integration, key};
Expand Down Expand Up @@ -31,12 +34,10 @@ mod bench {
}
}

// Explicitly using the expanded code of the following lines.
// criterion::criterion_group!(benches, bench::render);
// criterion::criterion_main!(benches);
pub fn benches() {
let mut criterion: criterion::Criterion<_> =
criterion::Criterion::default().configure_from_args();
let mut criterion: Criterion<_> = Criterion::default()
.with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)))
.configure_from_args();
bench::render(&mut criterion);
}

Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
cargo-release
cargo-machete
cargo-insta
cargo-flamegraph
oranda
gnuplot # for rendering with criterion
] ++ ci_packages
Expand Down
10 changes: 9 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fmt: fmt-toml

# Run linter
lint:
cargo clippy --all-features --tests
cargo clippy --all-features --tests --benches

# Format toml files
fmt-toml:
Expand Down Expand Up @@ -96,6 +96,14 @@ bench:
cargo bench --package synd-term --bench render --features integration -- --verbose
@start ./target/criterion/report/index.html

# Generate flamegraph
flamegraph:
cargo flamegraph \
--root --output target/flamegraph.svg \
--package synd-term --bench render --features integration \
-- --bench
@start target/flamegraph.svg

# Update synd_api graphql schema
update-gql-schema:
@graphql-client introspect-schema https://localhost:5959/graphql --no-ssl \
Expand Down

0 comments on commit e09f315

Please sign in to comment.