如何将PERF_AMPLE_READ与mmap一起使用

How to use PERF_SAMPLE_READ with mmap

本文关键字:mmap 一起 AMPLE PERF READ      更新时间:2023-10-16

这个问题与perf_event_open系统调用有关,但没有标签。

我目前希望使用枚举perf_event_sample_formatPERF_SAMPLE_READ成员从内存映射中检索一些数据,但由于未知原因,系统调用本身返回"无效参数"(错误号22(。


我有以下配置:

this->eventConfiguration.sample_freq = 11;
this->eventConfiguration.freq = true;
this->eventConfiguration.inherit = true;
this->eventConfiguration.sample_type = PERF_SAMPLE_CPU | PERF_SAMPLE_TIME | PERF_SAMPLE_PERIOD /*| PERF_SAMPLE_READ*/;

我正在跟踪的事件是PERF_COUNT_HW_CPU_CYCLES

这是我的系统调用。我监视我电脑的每个核心:

int fileDescriptor = syscall(__NR_perf_event_open, this->configuration.getEventConfiguration() , -1, i, -1, 0);

错误的处理如下所示,但我认为它没有用处。。。

if(fileDescriptor < 0) {
switch(errno) {
// here is some cases
};
}

提前感谢!:-(

我发现了错误!

问题是,当设置了perf_event_attr结构的inherit成员时,内核不支持使用PERF_AMPLE_READ。

以下代码来自内核源代码:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/events/core.c#n10788

/*
* We currently do not support PERF_SAMPLE_READ on inherited events.
* See perf_output_read().
*/
if (attr->inherit && (attr->sample_type & PERF_SAMPLE_READ))
goto err_ns;