Skip to content

Commit 6db2f7c

Browse files
captain5050acmel
authored andcommitted
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>
1 parent 8772598 commit 6db2f7c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

tools/perf/util/data-convert-json.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ struct convert_json {
4848
static void output_json_string(FILE *out, const char *s)
4949
{
5050
fputc('"', out);
51+
if (!s)
52+
goto out;
53+
5154
while (*s) {
5255
switch (*s) {
5356

@@ -71,6 +74,7 @@ static void output_json_string(FILE *out, const char *s)
7174

7275
++s;
7376
}
77+
out:
7478
fputc('"', out);
7579
}
7680

@@ -322,6 +326,16 @@ static void output_headers(struct perf_session *session, struct convert_json *c)
322326
output_json_format(out, false, 2, "]");
323327
}
324328

329+
static int process_feature_event(const struct perf_tool *tool __maybe_unused,
330+
struct perf_session *session,
331+
union perf_event *event)
332+
{
333+
if (event->feat.feat_id < HEADER_LAST_FEATURE)
334+
return perf_event__process_feature(session, event);
335+
336+
return 0;
337+
}
338+
325339
int bt_convert__perf2json(const char *input_name, const char *output_name,
326340
struct perf_data_convert_opts *opts __maybe_unused)
327341
{
@@ -360,6 +374,8 @@ int bt_convert__perf2json(const char *input_name, const char *output_name,
360374
c.tool.auxtrace_info = perf_event__process_auxtrace_info;
361375
c.tool.auxtrace = perf_event__process_auxtrace;
362376
c.tool.event_update = perf_event__process_event_update;
377+
c.tool.attr = perf_event__process_attr;
378+
c.tool.feature = process_feature_event;
363379
c.tool.ordering_requires_timestamps = true;
364380

365381
if (opts->all) {

0 commit comments

Comments
 (0)