perf data: Add fields when converting to json
RFC PATCH 1/1 perf data: Add fields when converting to json
When converting recorded data into json format, perf data omits probe variables. Add them to the output in the format "field name": "field value" using tep_print_field:
$ perf data convert --to-json output.json
// output.json
{
"linux-perf-json-version": 1,
"headers": { ... },
"samples": [
{
"timestamp": 29182079082999,
"pid": 309194,
[...]
"__probe_ip": "0x93ee35",
"query_string_string": "select 2;",
"nxids": "0"
}
]
}--- tools/perf/util/data-convert-json.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
tools/perf/util/data-convert-json.c +20 -0
@@ -217,6 +217,26 @@ static int process_sample_event(struct perf_tool *tool, }output_json_format (out, false,3 ,"]" ); +if (sample->raw_data) { +int i; +struct tep_format_field **fields; + + fields =tep_event_fields (evsel->tp_format); +if (fields !=NULL ) { + i =0 ; +while (fields[i]) { +struct trace_seq s; + +trace_seq_init (&s); +tep_print_field (&s, sample->raw_data, fields[i]); +output_json_key_string (out, true,3 , fields[i]->name, s.buffer); + + i++; + } +free (fields); + } + } +output_json_format (out, false,2 ,"}" );return 0 ; }
Signature · 1 line
2.27.0
Quoted 23 lines · Dmitrii Dolgov
When converting recorded data into json format, perf data omits probe variables. Add them to the output in the format "field name": "field value" using
tep_print_field:$ perf data convert --to-json output.json// output.json { "linux-perf-json-version": 1, "headers": { ... }, "samples": [ { "timestamp": 29182079082999, "pid": 309194, [...] "__probe_ip": "0x93ee35", "query_string_string": "select 2;", "nxids": "0" } ] }
Quoted 1 line
Signed-off-by Dmitrii Dolgov <[email protected]>
Thanks,
Ian
Quoted 9 lines
--- tools/perf/util/data-convert-json.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)tools/perf/util/data-convert-json.c +0
-0
tools/perf/util/data-convert-json.c static int process_sample_event(struct perf_tool *tool, · line 225
Quoted 9 lines
tools/perf/util/data-convert-json.c +6
-0@@ -217,6 +217,26 @@ static int process_sample_event(struct perf_tool *tool, }output_json_format (out, false,3 ,"]" ); +if (sample->raw_data) { +int i; +struct tep_format_field **fields; + + fields =tep_event_fields (evsel->tp_format); +if (fields !=NULL ) {
nit: just "if(fields) {" as you did above with sample->raw_data
Quoted 20 lines
tools/perf/util/data-convert-json.c +14
-1+ i =0 ; +while (fields[i]) { +struct trace_seq s; + +trace_seq_init (&s); +tep_print_field (&s, sample->raw_data, fields[i]); +output_json_key_string (out, true,3 , fields[i]->name, s.buffer); + + i++; + } +free (fields); + } + } +output_json_format (out, false,2 ,"}" );return 0 ; } --2.27.0
Quoted 14 lines · Ian Rogers
Quoted 12 lines · Dmitrii Dolgov
--- tools/perf/util/data-convert-json.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)tools/perf/util/data-convert-json.c +0
-0@@ -217,6 +217,26 @@ static int process_sample_event(struct perf_tool *tool, }output_json_format (out, false,3 ,"]" );
Quoted 8 lines
tools/perf/util/data-convert-json.c static int process_sample_event(struct perf_tool *tool, · line 225
Quoted 6 lines
tools/perf/util/data-convert-json.c +6
-0+if (sample->raw_data) { +int i; +struct tep_format_field **fields; + + fields =tep_event_fields (evsel->tp_format); +if (fields !=NULL ) {nit: just "if(fields) {" as you did above with
sample->raw_data
Thanks for looking into it, will send a new one shortly.
Em Tue, Nov 08, 2022 at 05:35:28PM -0800, Ian Rogers escreveu:
Quoted 24 lines · Dmitrii Dolgov
Quoted 23 lines
When converting recorded data into json format, perf data omits probe variables. Add them to the output in the format "field name": "field value" using
tep_print_field:$ perf data convert --to-json output.json// output.json { "linux-perf-json-version": 1, "headers": { ... }, "samples": [ { "timestamp": 29182079082999, "pid": 309194, [...] "__probe_ip": "0x93ee35", "query_string_string": "select 2;", "nxids": "0" } ] }
Quoted 3 lines
Quoted 1 line
Signed-off-by Dmitrii Dolgov <[email protected]>Acked-by Ian Rogers <[email protected]>
Thanks, applied.
- Arnaldo