gpt4 book ai didi

linux - 使用 perf 根据其他事件的发生来获取事件计数

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:44:32 24 4
gpt4 key购买 nike

是否有任何可能的方法可以根据其他事件的发生获取事件计数器的值?例如:如果我想知道每次特定计数器达到特定值时性能计数器的值。

最佳答案

您可以使用 perf_event_open 执行此操作,但 AFAIK 不能直接使用当前版本的 perf record

I want to know the value of performance counters each time a specific counter reach a specific value.

使用一组事件,“特定计数器” 是组长。对于您设置的此事件:

struct perf_event_attr leader;
leader.sample_type = PERF_SAMPLE_TIME | PERF_SAMPLE_READ;
leader.sample_period = specific_value;
// set type/config accordingly
leader.read_format = PERF_FORMAT_GROUP;
group_fd = syscall(__NR_perf_event_open, &leader, tid, cpu, -1, 0);
...

struct perf_event_attr other;
other.sample_period = 0; // doesn't trigger overflows
// set type/config accordingly
syscall(__NR_perf_event_open, &other, tid, cpu, group_fd, 0);

// do the mmap dance, ioctl etc. with the fd you get for the leader
// read values from both leader and other counters in your mmap buffer.

关于linux - 使用 perf 根据其他事件的发生来获取事件计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49912451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com