简体   繁体   English

如何在 mmap 中使用 PERF_SAMPLE_READ

[英]How to use PERF_SAMPLE_READ with mmap

This question is related to the perf_event_open syscall, but there is no tag for it.这个问题与perf_event_open系统调用有关,但没有标签。

I'm currently looking to use the PERF_SAMPLE_READ member of the enum perf_event_sample_format to retreive some data from a memory map, but for an unknown reason, the syscall itself return "invalid argument" (errno 22).我目前正在寻找使用枚举perf_event_sample_formatPERF_SAMPLE_READ成员从内存映射中检索一些数据,但由于未知原因,系统调用本身返回“无效参数”(错误号 22)。


I have the following configuration :我有以下配置:

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*/;

The event I'm tracking is PERF_COUNT_HW_CPU_CYCLES .我正在跟踪的事件是PERF_COUNT_HW_CPU_CYCLES

There is my syscall.有我的系统调用。 I spy each core of my computer :我监视计算机的每个核心:

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

The handling of the error is shown below, but I don't think it's useful...错误的处理如下所示,但我认为它没有用......

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

Thanks in advance !提前致谢 ! :-) :-)

I've found the bug !我找到了错误!

The problem is that the kernel don't support the use of PERF_SAMPLE_READ when the inherit member of the perf_event_attr structure is set.问题是当设置了perf_event_attr结构的inherit成员时,内核不支持使用 PERF_SAMPLE_READ。

The following code is from the kernel sources : https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/events/core.c#n10788以下代码来自内核源代码: 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM