diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/perf-event/README.md | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/perf-event/README.md')
-rw-r--r-- | vendor/perf-event/README.md | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/perf-event/README.md b/vendor/perf-event/README.md new file mode 100644 index 000000000..9848ca226 --- /dev/null +++ b/vendor/perf-event/README.md @@ -0,0 +1,45 @@ +## perf-event: a Rust interface to Linux performance monitoring + +*This is a nascent project. Tests are lacking. The design may change.* + +This uses the Linux [`perf_event_open`][man] API to access performance monitoring +hardware and software. Use `Builder` to create a perf event counter, then use +`enable` and `disable` to start and stop counting. Call `read` to get your +count. + +For example, this counts the number of cycles used by the call to `println!`. +Try adjusting the length of the vector to see the cycle count change. + + use perf_event::Builder; + + fn main() -> std::io::Result<()> { + let mut counter = Builder::new().build()?; + + let vec = (0..=51).collect::<Vec<_>>(); + + counter.enable()?; + println!("{:?}", vec); + counter.disable()?; + + println!("{} instructions retired", counter.read()?); + + Ok(()) + } + +Since we don't specify what sort of event we want to count, `Builder` defaults +to `PERF_COUNT_HW_INSTRUCTIONS` events, whose documentation says: + +> Retired instructions. Be careful, these can be affected by various issues, +> most notably hardware interrupt counts. + +The `examples` directory includes programs that count other sorts of events. + +[man]: http://man7.org/linux/man-pages/man2/perf_event_open.2.html + +## See also + +The [`perfcnt`] crate provides more extensive coverage of the Linux +`perf_event_open` API than this crate. However, `perfcnt` does not build on +stable Rust. + +[`perfcnt`]: https://crates.io/crates/perfcnt |