有没有人知道如何设置perf_event_attr
可以触发PMU监控多个(类型)事件的结构perf_event_open()
?
比如perf record -e cycles,faults ls
,它有两种不同的事件类型(PERF_TYPE_HARDWARE和PERF_TYPE_SOFTWARE),但在perf_event_open的联机帮助页上的示例中,perf_event_attr.type
只能分配单个值.
任何建议将不胜感激,谢谢!
20170208更新 感谢@gudok指点我的方向,但结果似乎有些异常.演示程序如下(用于测量整个系统的CPU周期和缓存未命中):
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/perf_event.h>
#include <linux/hw_breakpoint.h>
#include <asm/unistd.h>
#include <errno.h>
#include <stdint.h>
#include <inttypes.h>
#include <time.h>
struct read_format {
uint64_t nr;
struct {
uint64_t value;
uint64_t id;
} values[];
};
int main(int argc, char* argv[]) {
struct perf_event_attr pea;
int fd1, fd2;
uint64_t id1, id2;
uint64_t val1, …
Run Code Online (Sandbox Code Playgroud)