#perf #linux #parser

linux-perf-event-reader

从原始字节解析Linux perf_event信息

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 解析器实现

Download history 989/week @ 2024-04-26 922/week @ 2024-05-03 980/week @ 2024-05-10 996/week @ 2024-05-17 562/week @ 2024-05-24 727/week @ 2024-05-31 496/week @ 2024-06-07 609/week @ 2024-06-14 296/week @ 2024-06-21 691/week @ 2024-06-28 347/week @ 2024-07-05 668/week @ 2024-07-12 355/week @ 2024-07-19 423/week @ 2024-07-26 329/week @ 2024-08-02 269/week @ 2024-08-09

1,472 每月下载量
用于 6 个crate (通过 linux-perf-data)

MIT/Apache

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
    })
);

致谢

此仓库中的一些代码基于@koutenot-perf 项目

许可证

许可方式为以下之一

任选其一。

除非您明确声明,否则您提交的任何有意纳入作品的贡献,根据Apache-2.0许可证的定义,将按上述方式双重许可,不附加任何额外条款或条件。

依赖项

~0.6–1.2MB
~26K SLoC