perf header: Allow tracing of attr events
authorIan Rogers <irogers@google.com>
Sat, 7 Jun 2025 06:12:36 +0000 (23:12 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Wed, 25 Jun 2025 19:37:29 +0000 (12:37 -0700)
commit57cbd56e2efe26483be2d4e7f62a7d9d816b54f1
treed0a730188c178bbed419bd55e4c959c778864cbf
parent61051f9a8452d7f0878eaeb30299363310f07fd7
perf header: Allow tracing of attr events

In pipe mode attr events capture the perf_event_attr. Allow their
dumping as they normally start the file.

Before:
```
$ perf record -o - -a sleep 1 | perf script -D -i -
. ... raw event: size 272 bytes
.  0000:  40 00 00 00 00 00 10 01 00 00 00 00 88 00 00 00  @...............
.  0010:  00 00 00 00 00 00 00 00 a0 0f 00 00 00 00 00 00  ................
.  0020:  87 01 01 00 00 00 00 00 14 00 00 00 00 00 00 00  ................
.  0030:  01 84 05 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0040:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0050:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0060:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0070:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0080:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0090:  91 08 00 00 00 00 00 00 92 08 00 00 00 00 00 00  ................
.  00a0:  93 08 00 00 00 00 00 00 94 08 00 00 00 00 00 00  ................
.  00b0:  95 08 00 00 00 00 00 00 96 08 00 00 00 00 00 00  ................
.  00c0:  97 08 00 00 00 00 00 00 98 08 00 00 00 00 00 00  ................
.  00d0:  99 08 00 00 00 00 00 00 9a 08 00 00 00 00 00 00  ................
.  00e0:  9b 08 00 00 00 00 00 00 9c 08 00 00 00 00 00 00  ................
.  00f0:  9d 08 00 00 00 00 00 00 9e 08 00 00 00 00 00 00  ................
.  0100:  9f 08 00 00 00 00 00 00 a0 08 00 00 00 00 00 00  ................

-1 -1 0 [0x110]: PERF_RECORD_ATTR
0x110@pipe [0x110]: event: 64
...
```

After:
```
$ perf record -o - -a sleep 1 | perf script -D -i -
0@pipe [0x110]: event: 64
.
. ... raw event: size 272 bytes
.  0000:  40 00 00 00 00 00 10 01 00 00 00 00 88 00 00 00  @...............
.  0010:  00 00 00 00 00 00 00 00 a0 0f 00 00 00 00 00 00  ................
.  0020:  87 01 01 00 00 00 00 00 14 00 00 00 00 00 00 00  ................
.  0030:  01 84 05 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0040:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0050:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0060:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0070:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0080:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
.  0090:  5c 08 00 00 00 00 00 00 5d 08 00 00 00 00 00 00  \.......].......
.  00a0:  5e 08 00 00 00 00 00 00 5f 08 00 00 00 00 00 00  ^......._.......
.  00b0:  60 08 00 00 00 00 00 00 61 08 00 00 00 00 00 00  `.......a.......
.  00c0:  62 08 00 00 00 00 00 00 63 08 00 00 00 00 00 00  b.......c.......
.  00d0:  64 08 00 00 00 00 00 00 65 08 00 00 00 00 00 00  d.......e.......
.  00e0:  66 08 00 00 00 00 00 00 67 08 00 00 00 00 00 00  f.......g.......
.  00f0:  68 08 00 00 00 00 00 00 69 08 00 00 00 00 00 00  h.......i.......
.  0100:  6a 08 00 00 00 00 00 00 6b 08 00 00 00 00 00 00  j.......k.......

-1 -1 0 [0x110]: PERF_RECORD_ATTR, type = 0 (PERF_TYPE_HARDWARE), size = 136, config = 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq } = 4000, sample_type = IP|TID|TIME|CPU|PERIOD|IDENTIFIER, read_format = ID|LOST, disabled = 1, freq = 1, precise_ip = 3, sample_id_all = 1
0x110@pipe [0x110]: event: 64
...
```

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250617223356.2752099-4-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/header.c
tools/perf/util/header.h