我正在尝试使用系统调用perf_vent_open
从系统中获取一些性能数据。
我目前正在使用带有环形缓冲区的共享内存来进行定期数据检索。
但是我无法在环形缓冲区的每个部分中找到返回什么结构。手册页列举了所有可能性,仅此而已。我不知道要填充perf_event_attr
结构的哪个成员来控制将哪种类型的结构返回到环形缓冲区。
如果您有关于此的一些信息,我将很高兴阅读它!
https://github.com/torvalds/linux/blob/master/tools/perf/design.txt文档中有mmaped振铃的说明,当perf script
/ perf script -D
保存为perf.data文件时,可以解码振铃数据。该文档的某些部分已过时,但对于perf_event_open
系统调用说明仍然有用。
第一个mmap页面是元数据页面,其余2 ^ n个页面填充了事件,其中每个事件的标题struct perf_event_header
为8字节。
就像所陈述的那样,异步事件,例如计数器溢出或PROT_EXECmmap跟踪记录到环形缓冲区中。该环形缓冲区是通过mmap()创建和访问。
mmap大小应为1 + 2 ^ n页,其中第一页是包含各种内容的元数据页面(结构perf_event_mmap_page)位信息,例如环形缓冲区头的位置。
/* * Structure of the page that can be mapped via mmap */ struct perf_event_mmap_page { __u32 version; /* version number of this structure */ __u32 compat_version; /* lowest version this is compat with */ ... }
以下2 ^ n页是包含以下形式事件的环形缓冲区:
#define PERF_RECORD_MISC_KERNEL (1 << 0) #define PERF_RECORD_MISC_USER (1 << 1) #define PERF_RECORD_MISC_OVERFLOW (1 << 2) struct perf_event_header { __u32 type; __u16 misc; __u16 size; }; enum perf_event_type
[design.txt
]文档的枚举perf_event_type的值不正确,请检查实际的perf_events内核子系统源代码-https://github.com/torvalds/linux/blob/master/include/uapi/linux/perf_event.h#L707。该uapi / linux / perf_event.h文件在注释中也有一些结构提示,例如
* # * # The RAW record below is opaque data wrt the ABI * # * # That is, the ABI doesn't make any promises wrt to * # the stability of its content, it may vary depending * # on event, hardware, kernel version and phase of * # the moon. * # * # In other words, PERF_SAMPLE_RAW contents are not an ABI. * # * * { u32 size; * char data[size];}&& PERF_SAMPLE_RAW *... * { u64 size; * char data[size]; * u64 dyn_size; } && PERF_SAMPLE_STACK_USER *... PERF_RECORD_SAMPLE = 9,