summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-02-10 17:52:39 -0800
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-02-12 17:45:22 -0300
commit6db2f7c67b2804bc13fa385ff4e462fc3b366f8f (patch)
tree82936cfa37eb8f8200fb9f9c16e926153ce116e7 /tools
parent8772598b7801a2bb235bd35a858017e0fb939c38 (diff)
perf json: Pipe mode --to-json support
In pipe mode the environment may not be fully initialized so be robust to fields being NULL. Add default handling of feature and attr events. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Derek Foreman <derek.foreman@collabora.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/data-convert-json.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
index eefa3a94c813..6a626322476a 100644
--- a/tools/perf/util/data-convert-json.c
+++ b/tools/perf/util/data-convert-json.c
@@ -48,6 +48,9 @@ struct convert_json {
static void output_json_string(FILE *out, const char *s)
{
fputc('"', out);
+ if (!s)
+ goto out;
+
while (*s) {
switch (*s) {
@@ -71,6 +74,7 @@ static void output_json_string(FILE *out, const char *s)
++s;
}
+out:
fputc('"', out);
}
@@ -322,6 +326,16 @@ static void output_headers(struct perf_session *session, struct convert_json *c)
output_json_format(out, false, 2, "]");
}
+static int process_feature_event(const struct perf_tool *tool __maybe_unused,
+ struct perf_session *session,
+ union perf_event *event)
+{
+ if (event->feat.feat_id < HEADER_LAST_FEATURE)
+ return perf_event__process_feature(session, event);
+
+ return 0;
+}
+
int bt_convert__perf2json(const char *input_name, const char *output_name,
struct perf_data_convert_opts *opts __maybe_unused)
{
@@ -360,6 +374,8 @@ int bt_convert__perf2json(const char *input_name, const char *output_name,
c.tool.auxtrace_info = perf_event__process_auxtrace_info;
c.tool.auxtrace = perf_event__process_auxtrace;
c.tool.event_update = perf_event__process_event_update;
+ c.tool.attr = perf_event__process_attr;
+ c.tool.feature = process_feature_event;
c.tool.ordering_requires_timestamps = true;
if (opts->all) {