[PATCH] perf: add event name to json output

From: Oleg Latin
Date: Mon Nov 15 2021 - 07:37:35 EST


After converting perf.data to json it missing event name entry.

In perf script output it is clear that events have different types:

$ perf script -F -ip
...
dd 130321 [001] 10282.698083: 117995 cycles:
dd 130321 [001] 10282.698091: 225856 instructions:
...

But json output lack of this information and it hard to distinguish
different event types:

...
{
"timestamp": 10282698083472,
"pid": 130321,
"tid": 130321,
"comm": "dd",
"callchain": [
{
"ip": "0xffffffff901f4cd5",
"symbol": "syscall_exit_to_user_mode",
"dso": "[kernel.kallsyms]"
}
]
},
{
"timestamp": 10282698091328,
"pid": 130321,
"tid": 130321,
"comm": "dd",
"callchain": [
{
"ip": "0x7fb7f0c271e7",
"symbol": "__GI___libc_write",
"dso": "libc-2.31.so"
}
]
},
...

This patch adds event name entry to resulting json.

Signed-off-by: Oleg Latin <oleglatin@xxxxxxxxxxxxxx>
---
tools/perf/util/data-convert-json.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
index b0e3d69c6835..72aaf6babc22 100644
--- a/tools/perf/util/data-convert-json.c
+++ b/tools/perf/util/data-convert-json.c
@@ -168,6 +168,9 @@ static int process_sample_event(struct perf_tool *tool,
output_json_key_format(out, true, 3, "pid", "%i", al.thread->pid_);
output_json_key_format(out, true, 3, "tid", "%i", al.thread->tid);

+ if (evsel->name)
+ output_json_key_string(out, true, 3, "event", evsel->name);
+
if (al.cpu >= 0)
output_json_key_format(out, true, 3, "cpu", "%i", al.cpu);

--
2.25.1