From 8a40e2e9e3f732f6e720969f6a26b74fcaefc34b Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Wed, 8 Jun 2022 19:32:43 -0400 Subject: [PATCH] Add more bench-cargo-miri programs These example programs are derived from long-running (>15 minutes) tests in the test suites of highly-downloaded crates. They should serve as realistic but also somewhat pathological workloads for the interpreter. The unicode program stresses the code which looks for adjacent and equal stacks to merge them. The backtrace program has an uncommonly large working set of borrow tags per borrow stack. This also updates the .gitignore to ignore files commonly emitted in the course of using these benchmark programs. --- .gitignore | 4 ++ bench-cargo-miri/backtraces/Cargo.lock | 94 +++++++++++++++++++++++++ bench-cargo-miri/backtraces/Cargo.toml | 9 +++ bench-cargo-miri/backtraces/src/main.rs | 29 ++++++++ bench-cargo-miri/mse/Cargo.lock | 7 ++ bench-cargo-miri/serde1/Cargo.lock | 89 +++++++++++++++++++++++ bench-cargo-miri/unicode/Cargo.lock | 16 +++++ bench-cargo-miri/unicode/Cargo.toml | 9 +++ bench-cargo-miri/unicode/src/main.rs | 20 ++++++ 9 files changed, 277 insertions(+) create mode 100644 bench-cargo-miri/backtraces/Cargo.lock create mode 100644 bench-cargo-miri/backtraces/Cargo.toml create mode 100644 bench-cargo-miri/backtraces/src/main.rs create mode 100644 bench-cargo-miri/mse/Cargo.lock create mode 100644 bench-cargo-miri/serde1/Cargo.lock create mode 100644 bench-cargo-miri/unicode/Cargo.lock create mode 100644 bench-cargo-miri/unicode/Cargo.toml create mode 100644 bench-cargo-miri/unicode/src/main.rs diff --git a/.gitignore b/.gitignore index b84a1cfe9f5..dcefbc62c70 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ tex/*/out *.dot *.rs.bk .vscode +*.mm_profdata +perf.data +perf.data.old +flamegraph.svg diff --git a/bench-cargo-miri/backtraces/Cargo.lock b/bench-cargo-miri/backtraces/Cargo.lock new file mode 100644 index 00000000000..375b129a7e5 --- /dev/null +++ b/bench-cargo-miri/backtraces/Cargo.lock @@ -0,0 +1,94 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "backtrace" +version = "0.3.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "backtraces" +version = "0.1.0" +dependencies = [ + "backtrace", +] + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "gimli" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "miniz_oxide" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" +dependencies = [ + "adler", +] + +[[package]] +name = "object" +version = "0.28.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +dependencies = [ + "memchr", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" diff --git a/bench-cargo-miri/backtraces/Cargo.toml b/bench-cargo-miri/backtraces/Cargo.toml new file mode 100644 index 00000000000..1ba96b19395 --- /dev/null +++ b/bench-cargo-miri/backtraces/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "backtraces" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +backtrace = "0.3.65" diff --git a/bench-cargo-miri/backtraces/src/main.rs b/bench-cargo-miri/backtraces/src/main.rs new file mode 100644 index 00000000000..eba51c60dbc --- /dev/null +++ b/bench-cargo-miri/backtraces/src/main.rs @@ -0,0 +1,29 @@ +//! Extracted from the backtrace crate's test test_frame_conversion + +use backtrace::{Backtrace, BacktraceFrame}; +use std::fmt::Write; + +fn main() { + let mut frames = vec![]; + backtrace::trace(|frame| { + let converted = BacktraceFrame::from(frame.clone()); + frames.push(converted); + true + }); + + let mut manual = Backtrace::from(frames); + manual.resolve(); + let frames = manual.frames(); + + let mut output = String::new(); + for frame in frames { + // Originally these were println! but we'd prefer our benchmarks to not emit a lot of + // output to stdout/stderr. Unfortunately writeln! to a String is faster, but we still + // manage to exercise interesting code paths in Miri. + writeln!(output, "{:?}", frame.ip()).unwrap(); + writeln!(output, "{:?}", frame.symbol_address()).unwrap(); + writeln!(output, "{:?}", frame.module_base_address()).unwrap(); + writeln!(output, "{:?}", frame.symbols()).unwrap(); + } + drop(output); +} diff --git a/bench-cargo-miri/mse/Cargo.lock b/bench-cargo-miri/mse/Cargo.lock new file mode 100644 index 00000000000..d2b1aa341bb --- /dev/null +++ b/bench-cargo-miri/mse/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "mse" +version = "0.1.0" diff --git a/bench-cargo-miri/serde1/Cargo.lock b/bench-cargo-miri/serde1/Cargo.lock new file mode 100644 index 00000000000..48750576135 --- /dev/null +++ b/bench-cargo-miri/serde1/Cargo.lock @@ -0,0 +1,89 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cargo-miri-test" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "itoa" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" + +[[package]] +name = "proc-macro2" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" + +[[package]] +name = "serde" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" diff --git a/bench-cargo-miri/unicode/Cargo.lock b/bench-cargo-miri/unicode/Cargo.lock new file mode 100644 index 00000000000..80d013b7d6d --- /dev/null +++ b/bench-cargo-miri/unicode/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "unicode" +version = "0.1.0" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" diff --git a/bench-cargo-miri/unicode/Cargo.toml b/bench-cargo-miri/unicode/Cargo.toml new file mode 100644 index 00000000000..7e8708b03f1 --- /dev/null +++ b/bench-cargo-miri/unicode/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "unicode" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +unicode-xid = "0.2.3" diff --git a/bench-cargo-miri/unicode/src/main.rs b/bench-cargo-miri/unicode/src/main.rs new file mode 100644 index 00000000000..3f0ee5ecf6a --- /dev/null +++ b/bench-cargo-miri/unicode/src/main.rs @@ -0,0 +1,20 @@ +//! Extracted from the unicode-xid exhaustive test all_valid_chars_do_not_panic_for_is_xid_continue + +use unicode_xid::UnicodeXID; + +/// A `char` in Rust is a Unicode Scalar Value +/// +/// See: http://www.unicode.org/glossary/#unicode_scalar_value +fn all_valid_chars() -> impl Iterator { + (0u32..=0xD7FF).chain(0xE000u32..=0x10FFFF).map(|u| { + core::convert::TryFrom::try_from(u) + .expect("The selected range should be infallible if the docs match impl") + }) +} + +fn main() { + // Take only the first few chars because we don't want to wait all day + for c in all_valid_chars().take(2_000) { + let _ = UnicodeXID::is_xid_continue(c); + } +}