Skip to content

Commit f19860e

Browse files
blakej11namhyung
authored andcommitted
perf tools: display the new PERF_RECORD_BPF_METADATA event
Here's some example "perf script -D" output for the new event type. The ": unhandled!" message is from tool.c, analogous to other behavior there. I've elided some rows with all NUL characters for brevity, and I wrapped one of the >75-column lines to fit in the commit guidelines. [email protected] [0x260]: event: 84 . . ... raw event: size 608 bytes . 0000: 54 00 00 00 00 00 60 02 62 70 66 5f 70 72 6f 67 T.....`.bpf_prog . 0010: 5f 31 65 30 61 32 65 33 36 36 65 35 36 66 31 61 _1e0a2e366e56f1a . 0020: 32 5f 70 65 72 66 5f 73 61 6d 70 6c 65 5f 66 69 2_perf_sample_fi . 0030: 6c 74 65 72 00 00 00 00 00 00 00 00 00 00 00 00 lter............ . 0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ [...] . 0110: 74 65 73 74 5f 76 61 6c 75 65 00 00 00 00 00 00 test_value...... . 0120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ [...] . 0150: 34 32 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42.............. . 0160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ [...] 0 0x50fc8 [0x260]: PERF_RECORD_BPF_METADATA \ prog bpf_prog_1e0a2e366e56f1a2_perf_sample_filter entry 0: test_value = 42 : unhandled! Signed-off-by: Blake Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent fdc3441 commit f19860e

File tree

7 files changed

+56
-3
lines changed

7 files changed

+56
-3
lines changed

tools/perf/builtin-inject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,6 +2530,7 @@ int cmd_inject(int argc, const char **argv)
25302530
inject.tool.finished_init = perf_event__repipe_op2_synth;
25312531
inject.tool.compressed = perf_event__repipe_op4_synth;
25322532
inject.tool.auxtrace = perf_event__repipe_auxtrace;
2533+
inject.tool.bpf_metadata = perf_event__repipe_op2_synth;
25332534
inject.tool.dont_split_sample_group = true;
25342535
inject.session = __perf_session__new(&data, &inject.tool,
25352536
/*trace_event_repipe=*/inject.output.is_pipe);

tools/perf/builtin-script.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "print_insn.h"
3939
#include "archinsn.h"
4040
#include <linux/bitmap.h>
41+
#include <linux/compiler.h>
4142
#include <linux/kernel.h>
4243
#include <linux/stringify.h>
4344
#include <linux/time64.h>
@@ -50,6 +51,7 @@
5051
#include <errno.h>
5152
#include <inttypes.h>
5253
#include <signal.h>
54+
#include <stdio.h>
5355
#include <sys/param.h>
5456
#include <sys/types.h>
5557
#include <sys/stat.h>
@@ -2755,6 +2757,14 @@ process_bpf_events(const struct perf_tool *tool __maybe_unused,
27552757
sample->tid);
27562758
}
27572759

2760+
static int
2761+
process_bpf_metadata_event(struct perf_session *session __maybe_unused,
2762+
union perf_event *event)
2763+
{
2764+
perf_event__fprintf(event, NULL, stdout);
2765+
return 0;
2766+
}
2767+
27582768
static int process_text_poke_events(const struct perf_tool *tool,
27592769
union perf_event *event,
27602770
struct perf_sample *sample,
@@ -2877,8 +2887,9 @@ static int __cmd_script(struct perf_script *script)
28772887
script->tool.finished_round = process_finished_round_event;
28782888
}
28792889
if (script->show_bpf_events) {
2880-
script->tool.ksymbol = process_bpf_events;
2881-
script->tool.bpf = process_bpf_events;
2890+
script->tool.ksymbol = process_bpf_events;
2891+
script->tool.bpf = process_bpf_events;
2892+
script->tool.bpf_metadata = process_bpf_metadata_event;
28822893
}
28832894
if (script->show_text_poke_events) {
28842895
script->tool.ksymbol = process_bpf_events;

tools/perf/util/event.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include <errno.h>
22
#include <fcntl.h>
33
#include <inttypes.h>
4+
#include <linux/compiler.h>
45
#include <linux/kernel.h>
56
#include <linux/types.h>
67
#include <perf/cpumap.h>
8+
#include <perf/event.h>
9+
#include <stdio.h>
710
#include <sys/types.h>
811
#include <sys/stat.h>
912
#include <unistd.h>
@@ -78,6 +81,7 @@ static const char *perf_event__names[] = {
7881
[PERF_RECORD_COMPRESSED] = "COMPRESSED",
7982
[PERF_RECORD_FINISHED_INIT] = "FINISHED_INIT",
8083
[PERF_RECORD_COMPRESSED2] = "COMPRESSED2",
84+
[PERF_RECORD_BPF_METADATA] = "BPF_METADATA",
8185
};
8286

8387
const char *perf_event__name(unsigned int id)
@@ -505,6 +509,20 @@ size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp)
505509
event->bpf.type, event->bpf.flags, event->bpf.id);
506510
}
507511

512+
size_t perf_event__fprintf_bpf_metadata(union perf_event *event, FILE *fp)
513+
{
514+
struct perf_record_bpf_metadata *metadata = &event->bpf_metadata;
515+
size_t ret;
516+
517+
ret = fprintf(fp, " prog %s\n", metadata->prog_name);
518+
for (__u32 i = 0; i < metadata->nr_entries; i++) {
519+
ret += fprintf(fp, " entry %d: %20s = %s\n", i,
520+
metadata->entries[i].key,
521+
metadata->entries[i].value);
522+
}
523+
return ret;
524+
}
525+
508526
static int text_poke_printer(enum binary_printer_ops op, unsigned int val,
509527
void *extra, FILE *fp)
510528
{
@@ -602,6 +620,9 @@ size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FIL
602620
case PERF_RECORD_AUX_OUTPUT_HW_ID:
603621
ret += perf_event__fprintf_aux_output_hw_id(event, fp);
604622
break;
623+
case PERF_RECORD_BPF_METADATA:
624+
ret += perf_event__fprintf_bpf_metadata(event, fp);
625+
break;
605626
default:
606627
ret += fprintf(fp, "\n");
607628
}

tools/perf/util/event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
370370
size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp);
371371
size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
372372
size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
373+
size_t perf_event__fprintf_bpf_metadata(union perf_event *event, FILE *fp);
373374
size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *machine,FILE *fp);
374375
size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FILE *fp);
375376

tools/perf/util/session.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <sys/types.h>
1313
#include <sys/mman.h>
1414
#include <perf/cpumap.h>
15+
#include <perf/event.h>
1516

1617
#include "map_symbol.h"
1718
#include "branch.h"
@@ -1491,6 +1492,9 @@ static s64 perf_session__process_user_event(struct perf_session *session,
14911492
case PERF_RECORD_FINISHED_INIT:
14921493
err = tool->finished_init(session, event);
14931494
break;
1495+
case PERF_RECORD_BPF_METADATA:
1496+
err = tool->bpf_metadata(session, event);
1497+
break;
14941498
default:
14951499
err = -EINVAL;
14961500
break;

tools/perf/util/tool.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include "data.h"
33
#include "debug.h"
4+
#include "event.h"
45
#include "header.h"
56
#include "session.h"
67
#include "stat.h"
78
#include "tool.h"
89
#include "tsc.h"
10+
#include <linux/compiler.h>
911
#include <sys/mman.h>
12+
#include <stddef.h>
1013
#include <unistd.h>
1114

1215
#ifdef HAVE_ZSTD_SUPPORT
@@ -237,6 +240,16 @@ static int perf_session__process_compressed_event_stub(struct perf_session *sess
237240
return 0;
238241
}
239242

243+
static int perf_event__process_bpf_metadata_stub(struct perf_session *perf_session __maybe_unused,
244+
union perf_event *event)
245+
{
246+
if (dump_trace)
247+
perf_event__fprintf_bpf_metadata(event, stdout);
248+
249+
dump_printf(": unhandled!\n");
250+
return 0;
251+
}
252+
240253
void perf_tool__init(struct perf_tool *tool, bool ordered_events)
241254
{
242255
tool->ordered_events = ordered_events;
@@ -293,6 +306,7 @@ void perf_tool__init(struct perf_tool *tool, bool ordered_events)
293306
tool->compressed = perf_session__process_compressed_event_stub;
294307
#endif
295308
tool->finished_init = process_event_op2_stub;
309+
tool->bpf_metadata = perf_event__process_bpf_metadata_stub;
296310
}
297311

298312
bool perf_tool__compressed_is_stub(const struct perf_tool *tool)

tools/perf/util/tool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ struct perf_tool {
7777
stat,
7878
stat_round,
7979
feature,
80-
finished_init;
80+
finished_init,
81+
bpf_metadata;
8182
event_op4 compressed;
8283
event_op3 auxtrace;
8384
bool ordered_events;

0 commit comments

Comments
 (0)