gpt4 book ai didi

c++ - “id”系统调用通过选项 “stream_id”返回的结构中的 “PERF_RECORD_SAMPLE”和 “perf_event_open”有什么区别?

转载 作者:行者123 更新时间:2023-12-02 10:35:56 26 4
gpt4 key购买 nike

我正在尝试使用perf_event_open syscall编写一段代码。但是我不了解在内存映射中返回的结构中idstream_id字段之间的真正区别。

这种结构是这样的(来自perf_event_open的手册页):

struct {
struct perf_event_header header;
u64 sample_id; /* if PERF_SAMPLE_IDENTIFIER */
u64 ip; /* if PERF_SAMPLE_IP */
u32 pid, tid; /* if PERF_SAMPLE_TID */
u64 time; /* if PERF_SAMPLE_TIME */
u64 addr; /* if PERF_SAMPLE_ADDR */
u64 id; /* if PERF_SAMPLE_ID */
u64 stream_id; /* if PERF_SAMPLE_STREAM_ID */
u32 cpu, res; /* if PERF_SAMPLE_CPU */
u64 period; /* if PERF_SAMPLE_PERIOD */
struct read_format v;
/* if PERF_SAMPLE_READ */
u64 nr; /* if PERF_SAMPLE_CALLCHAIN */
u64 ips[nr]; /* if PERF_SAMPLE_CALLCHAIN */
u32 size; /* if PERF_SAMPLE_RAW */
char data[size]; /* if PERF_SAMPLE_RAW */
u64 bnr; /* if PERF_SAMPLE_BRANCH_STACK */
struct perf_branch_entry lbr[bnr];
/* if PERF_SAMPLE_BRANCH_STACK */
u64 abi; /* if PERF_SAMPLE_REGS_USER */
u64 regs[weight(mask)];
/* if PERF_SAMPLE_REGS_USER */
u64 size; /* if PERF_SAMPLE_STACK_USER */
char data[size]; /* if PERF_SAMPLE_STACK_USER */
u64 dyn_size; /* if PERF_SAMPLE_STACK_USER &&
size != 0 */
u64 weight; /* if PERF_SAMPLE_WEIGHT */
u64 data_src; /* if PERF_SAMPLE_DATA_SRC */
u64 transaction; /* if PERF_SAMPLE_TRANSACTION */
u64 abi; /* if PERF_SAMPLE_REGS_INTR */
u64 regs[weight(mask)];
/* if PERF_SAMPLE_REGS_INTR */
};

手册页给了我这个解释:
id               If PERF_SAMPLE_ID is enabled, a 64-bit unique ID is included.  If the event is a member of an event group, the group leader ID is returned.  This ID is the same as the one returned by PERF_FORMAT_ID.
stream_id If PERF_SAMPLE_STREAM_ID is enabled, a 64-bit unique ID is included. Unlike PERF_SAMPLE_ID the actual ID is returned, not the group leader. This ID is the same as the one returned by PERF_FORMAT_ID.

但是问题出在这里:文档似乎不连贯。

我错过了什么吗?

感谢您的关注。

最佳答案

出现PERF_SAMPLE_STREAM_ID的主要原因是维护继承计数器的事件ID。而PERF_SAMPLE_ID将包含父计数器的事件ID。 (如果有任何父子关系)。

继承的计数器是分配给子任务的那些计数器,这些计数器源自正在配置的父任务(除非将标志--no-inherit传递给perf命令)。

此详细信息在此旧commit中进行了描述。

查看最新的源代码here

if (sample_type & (PERF_SAMPLE_ID | PERF_SAMPLE_IDENTIFIER))
data->id = primary_event_id(event);

if (sample_type & PERF_SAMPLE_STREAM_ID)
data->stream_id = event->id;

....

/*
* If we inherit events we want to return the parent event id
* to userspace.
*/
static u64 primary_event_id(struct perf_event *event)
{
u64 id = event->id;

if (event->parent)
id = event->parent->id;

return id;
}

上面的代码片段清楚地区分了结构的两个成员。这与事件是否为组长无关。

另外,必须注意,组中的所有事件也将计算/使用此 primary_event_id函数。可以看到 here。因此,组中的所有事件将包含组长的ID。

关于c++ - “id”系统调用通过选项 “stream_id”返回的结构中的 “PERF_RECORD_SAMPLE”和 “perf_event_open”有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60316869/

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