diff --git a/Cargo.lock b/Cargo.lock index 40ad53f5..c34d4018 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,6 +34,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -135,6 +136,12 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b3d0060af21e8d11a926981cc00c6c1541aa91dd64b9f881985c3da1094425f" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "ascii" version = "0.9.3" @@ -521,6 +528,12 @@ version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +[[package]] +name = "bytemuck" +version = "1.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" + [[package]] name = "byteorder" version = "1.5.0" @@ -730,6 +743,15 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "cpp_demangle" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8227005286ec39567949b33df9896bcadfa6051bccca2488129f108ca23119" +dependencies = [ + "cfg-if", +] + [[package]] name = "cpufeatures" version = "0.2.12" @@ -903,6 +925,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +[[package]] +name = "debugid" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" +dependencies = [ + "uuid", +] + [[package]] name = "deranged" version = "0.3.11" @@ -1134,7 +1165,7 @@ checksum = "e02a15dbb4ba5223a427ec7c678c47e295ec9ecd48cd15ab015a205d15388a43" dependencies = [ "chrono", "mime", - "quick-xml", + "quick-xml 0.31.0", "regex", "serde", "serde_json", @@ -1143,6 +1174,18 @@ dependencies = [ "uuid", ] +[[package]] +name = "findshlibs" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40b9e59cd0f7e0806cca4be089683ecb6434e602038df21fe6bf6711b2f07f64" +dependencies = [ + "cc", + "lazy_static", + "libc", + "winapi", +] + [[package]] name = "flate2" version = "1.0.30" @@ -1800,6 +1843,24 @@ dependencies = [ "serde", ] +[[package]] +name = "inferno" +version = "0.11.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "321f0f839cd44a4686e9504b0a62b4d69a50b62072144c71c68f5873c167b8d9" +dependencies = [ + "ahash", + "indexmap 2.2.5", + "is-terminal", + "itoa", + "log", + "num-format", + "once_cell", + "quick-xml 0.26.0", + "rgb", + "str_stack", +] + [[package]] name = "insta" version = "1.39.0" @@ -2065,6 +2126,15 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "memmap2" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" +dependencies = [ + "libc", +] + [[package]] name = "mime" version = "0.3.17" @@ -2146,6 +2216,17 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "nix" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", +] + [[package]] name = "nom" version = "7.1.3" @@ -2239,6 +2320,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-format" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" +dependencies = [ + "arrayvec", + "itoa", +] + [[package]] name = "num-integer" version = "0.1.46" @@ -2740,6 +2831,28 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "pprof" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef5c97c51bd34c7e742402e216abdeb44d415fbe6ae41d56b114723e953711cb" +dependencies = [ + "backtrace", + "cfg-if", + "criterion", + "findshlibs", + "inferno", + "libc", + "log", + "nix", + "once_cell", + "parking_lot", + "smallvec", + "symbolic-demangle", + "tempfile", + "thiserror", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2861,6 +2974,15 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quick-xml" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd" +dependencies = [ + "memchr", +] + [[package]] name = "quick-xml" version = "0.31.0" @@ -3076,6 +3198,15 @@ dependencies = [ "winreg", ] +[[package]] +name = "rgb" +version = "0.8.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aee83dc281d5a3200d37b299acd13b81066ea126a7f16f0eae70fc9aed241d9" +dependencies = [ + "bytemuck", +] + [[package]] name = "ring" version = "0.17.8" @@ -3602,6 +3733,12 @@ dependencies = [ "syn 2.0.52", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -3614,6 +3751,12 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7beae5182595e9a8b683fa98c4317f956c9a2dec3b9716990d20023cc60c766" +[[package]] +name = "str_stack" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb" + [[package]] name = "string_cache" version = "0.8.7" @@ -3689,6 +3832,29 @@ dependencies = [ "is_ci", ] +[[package]] +name = "symbolic-common" +version = "12.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71297dc3e250f7dbdf8adb99e235da783d690f5819fdeb4cce39d9cfb0aca9f1" +dependencies = [ + "debugid", + "memmap2", + "stable_deref_trait", + "uuid", +] + +[[package]] +name = "symbolic-demangle" +version = "12.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "424fa2c9bf2c862891b9cfd354a752751a6730fd838a4691e7f6c2c7957b9daf" +dependencies = [ + "cpp_demangle", + "rustc-demangle", + "symbolic-common", +] + [[package]] name = "syn" version = "1.0.109" @@ -3858,6 +4024,7 @@ dependencies = [ "octocrab", "open", "parse_duration", + "pprof", "proptest", "ratatui", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index c3080245..3647e43e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } @@ -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" diff --git a/crates/synd_term/Cargo.toml b/crates/synd_term/Cargo.toml index 8c0e974b..535968c8 100644 --- a/crates/synd_term/Cargo.toml +++ b/crates/synd_term/Cargo.toml @@ -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 } diff --git a/crates/synd_term/benches/render.rs b/crates/synd_term/benches/render.rs index 91b7ed1d..4194e555 100644 --- a/crates/synd_term/benches/render.rs +++ b/crates/synd_term/benches/render.rs @@ -1,3 +1,6 @@ +use criterion::Criterion; +use pprof::criterion::{Output, PProfProfiler}; + mod bench { use criterion::Criterion; use synd_term::{integration, key}; @@ -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); } diff --git a/flake.nix b/flake.nix index b5c396d4..3dd97b19 100644 --- a/flake.nix +++ b/flake.nix @@ -69,6 +69,7 @@ cargo-release cargo-machete cargo-insta + cargo-flamegraph oranda gnuplot # for rendering with criterion ] ++ ci_packages diff --git a/justfile b/justfile index baaea0ba..db831315 100644 --- a/justfile +++ b/justfile @@ -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: @@ -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 \