From: Namhyung Kim Date: Fri, 25 Aug 2023 15:25:50 +0000 (-0700) Subject: libperf: Add perf_record_header_attr_id() X-Git-Tag: v6.6-rc1~4^2~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=baec60800dd4a379546f3ba311574d907a01a77d;p=thirdparty%2Fkernel%2Flinux.git libperf: Add perf_record_header_attr_id() The HEADER_ATTR record has an event attr followed by the id array. But perf data from a different version could have different size of attr. So it cannot just use event->attr.id to access the array. Let's add the perf_record_header_attr_id() macro to calculate the start of the array. Signed-off-by: Namhyung Kim Cc: Adrian Hunter Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20230825152552.112913-2-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h index ba2dcf64f4e63..e563dd8c3628f 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -151,6 +151,10 @@ struct perf_record_header_attr { __u64 id[]; }; +/* Returns the pointer to id array based on the actual attr size. */ +#define perf_record_header_attr_id(evt) \ + ((void *)&(evt)->attr.attr + (evt)->attr.attr.size) + enum { PERF_CPU_MAP__CPUS = 0, PERF_CPU_MAP__MASK = 1,