blob: 3fc73ae2e57fd91005e0ba1720da9c62fa8c9b33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
use libc::pid_t;
use perf_event::events::Hardware;
use perf_event::Builder;
use std::thread::sleep;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let pid: pid_t = std::env::args()
.nth(1)
.expect("Usage: insns-for-pid PID")
.parse()
.expect("Usage: insns-for-pid PID");
let mut insns = Builder::new()
.observe_pid(pid)
.kind(Hardware::BRANCH_INSTRUCTIONS)
.build()?;
// Count instructions in PID for five seconds.
insns.enable()?;
sleep(Duration::from_secs(5));
insns.disable()?;
println!("instructions in last five seconds: {}", insns.read()?);
Ok(())
}
|