#cpu #linux #perf-event #ffi-bind

cpu-instructions-reader

perf_event_read 包,专门用于读取 CPU 硬件指令

2 个不稳定版本

0.2.0 2024 年 8 月 8 日
0.1.0 2024 年 8 月 8 日

#5#perf-event

Download history 173/week @ 2024-08-03 30/week @ 2024-08-10

每月下载 203

WTFPL 许可证

14KB
285

此库仅用于读取 CPU 指令,不是完整的 perf_event_open

权限要求 ⚠ : 确保程序具有 ROOT 权限


lib.rs:

此库仅用于读取 CpuInstructionNumber 特化,不是完整的 perf_event_read

示例

use std::{fs, time::{Duration, Instant}, thread};
use cpu_instructions_reader::{InstructionNumber, InstructionNumberReader, InstructionNumberInstant};

let reader = InstructionNumberReader::new().unwrap();
let record_1 = reader.instant(0).unwrap();

thread::sleep(Duration::from_secs(1));

let record_2 = reader.instant(0).unwrap();
let instructions = record_2 - record_1;

println!("{instructions}");

依赖项

~0.4–1.1MB
~25K SLoC