9次重大发布
0.10.1 | 2024年7月3日 |
---|---|
0.10.0 | 2024年3月3日 |
0.9.0 | 2022年12月8日 |
0.8.0 | 2022年6月10日 |
#205 in 解析器实现
1,472 每月下载量
用于 6 个crate (通过 linux-perf-data)
130KB
2.5K SLoC
linux-perf-event-reader
此crate允许您解析Linux perf事件和相关结构。
示例
use linux_perf_event_reader::{Endianness, PerfEventAttr, RawData, RecordType};
use linux_perf_event_reader::records::{CommOrExecRecord, EventRecord, RawEventRecord, RecordParseInfo};
// Read the perf_event_attr data.
let attr_data = [
0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 229, 3, 0, 0, 0, 0, 0, 0, 47, 177, 0,
0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 3, 183, 215, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 15,
255, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 128, 0,
0, 0, 0, 0, 0, 0,
];
let (attr, _size) =
PerfEventAttr::parse::<_, byteorder::LittleEndian>(&attr_data[..]).unwrap();
let parse_info = RecordParseInfo::new(&attr, Endianness::LittleEndian);
let body = b"lG\x08\0lG\x08\0dump_syms\0\0\0\0\0\0\0lG\x08\0lG\x08\08\x1b\xf8\x18hX\x04\0";
let body_raw_data = RawData::from(&body[..]);
let raw_record = RawEventRecord::new(RecordType::COMM, 0x2000, body_raw_data, parse_info);
let parsed_record = raw_record.parse().unwrap();
assert_eq!(
parsed_record,
EventRecord::Comm(CommOrExecRecord {
pid: 542572,
tid: 542572,
name: RawData::Single(b"dump_syms"),
is_execve: true
})
);
致谢
此仓库中的一些代码基于@koute的 not-perf
项目。
许可证
许可方式为以下之一
- Apache许可证2.0版 (
LICENSE-APACHE
或 https://apache.ac.cn/licenses/LICENSE-2.0) - MIT许可证 (
LICENSE-MIT
或 http://opensource.org/licenses/MIT)
任选其一。
除非您明确声明,否则您提交的任何有意纳入作品的贡献,根据Apache-2.0许可证的定义,将按上述方式双重许可,不附加任何额外条款或条件。
依赖项
~0.6–1.2MB
~26K SLoC