Skip to content

Commit aea4a4e

Browse files
committed
Add compression utility to benchlib and document runtime benchmark input file handling
1 parent f8cc0b2 commit aea4a4e

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/benchlib/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ log = "0.4.17"
1414
env_logger = "0.10.0"
1515
clap = { version = "4.1", features = ["derive", "string"] }
1616
libc = "0.2"
17+
flate2 = { version = "1", optional = true }
1718

1819
[target.'cfg(target_os = "linux")'.dependencies]
1920
perf-event = "0.4.7"
21+
22+
[features]
23+
compression = ["dep:flate2"]

collector/benchlib/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ mod cli;
1818
pub mod comm;
1919
pub mod measure;
2020
pub mod process;
21+
mod utils;
22+
23+
#[cfg(feature = "compression")]
24+
pub use utils::decompress_file;

collector/benchlib/src/utils.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// Decompresses the contents of a gzipped (.gz) file.
2+
#[cfg(feature = "compression")]
3+
pub fn decompress_file(contents: &[u8]) -> Vec<u8> {
4+
use std::io::Read;
5+
6+
let mut tar = flate2::bufread::GzDecoder::new(contents);
7+
let mut result = Vec::new();
8+
tar.read_to_end(&mut result)
9+
.expect("Cannot decompress file");
10+
11+
result
12+
}

collector/runtime-benchmarks/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@ not print anything to `stdout`!
2222
Note that each benchmark group binary will be thus invoked twice per benchmarking collection. Keep this
2323
in mind so that the `main` function of the group doesn't perform too much work, which will be thrown
2424
away when it is invoked with the `list` argument.
25+
26+
## Benchmark input files
27+
Some benchmarks will need input files. Ideally, these should be stored directly inside this repository,
28+
e.g. in a `data` directory under the benchmark group workspace root. If some files are shared between
29+
multiple groups, you can put them in the `runtime-benchmarks/data` directory. To keep benchmarks
30+
self-contained, consider including the input files directly into the binary using the `include_bytes!`
31+
or `include_str!` macros.
32+
33+
Try to keep the sizes of input files reasonable. If you want to increase their size for the benchmark,
34+
you can repeat their contents at the beginning of the benchmark run (in `main`). If the file has a
35+
format that is not easily repeatable it is large (e.g. larger than 1 MiB), consider compressing it
36+
using `gzip <file>` and them decompressing it in `main` using `benchlib::decompress_file`.

0 commit comments

Comments
 (0)