* [RFC PATCH v1] perf data: Add fields when converting to json
@ 2022-11-08 19:00 Dmitrii Dolgov
2022-11-09 1:35 ` Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Dmitrii Dolgov @ 2022-11-08 19:00 UTC (permalink / raw)
To: linux-perf-users; +Cc: acme, mingo, jolsa, 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"
}
]
}
Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
---
tools/perf/util/data-convert-json.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
index 613d6ae82663..d30816eafb2f 100644
--- a/tools/perf/util/data-convert-json.c
+++ b/tools/perf/util/data-convert-json.c
@@ -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;
}
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC PATCH v1] perf data: Add fields when converting to json
2022-11-08 19:00 [RFC PATCH v1] perf data: Add fields when converting to json Dmitrii Dolgov
@ 2022-11-09 1:35 ` Ian Rogers
2022-11-09 10:37 ` Dmitry Dolgov
2022-11-10 18:37 ` Arnaldo Carvalho de Melo
0 siblings, 2 replies; 4+ messages in thread
From: Ian Rogers @ 2022-11-09 1:35 UTC (permalink / raw)
To: Dmitrii Dolgov; +Cc: linux-perf-users, acme, mingo, jolsa
On Tue, Nov 8, 2022 at 11:00 AM Dmitrii Dolgov <9erthalion6@gmail.com> wrote:
>
> 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"
> }
> ]
> }
>
> Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
Acked-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> tools/perf/util/data-convert-json.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
> index 613d6ae82663..d30816eafb2f 100644
> --- a/tools/perf/util/data-convert-json.c
> +++ b/tools/perf/util/data-convert-json.c
> @@ -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
> + 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH v1] perf data: Add fields when converting to json
2022-11-09 1:35 ` Ian Rogers
@ 2022-11-09 10:37 ` Dmitry Dolgov
2022-11-10 18:37 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 4+ messages in thread
From: Dmitry Dolgov @ 2022-11-09 10:37 UTC (permalink / raw)
To: Ian Rogers; +Cc: linux-perf-users, acme, mingo, jolsa
> On Tue, Nov 08, 2022 at 05:35:28PM -0800, Ian Rogers wrote:
> On Tue, Nov 8, 2022 at 11:00 AM Dmitrii Dolgov <9erthalion6@gmail.com> wrote:
> > ---
> > tools/perf/util/data-convert-json.c | 20 ++++++++++++++++++++
> > 1 file changed, 20 insertions(+)
> >
> > diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
> > index 613d6ae82663..d30816eafb2f 100644
> > --- a/tools/perf/util/data-convert-json.c
> > +++ b/tools/perf/util/data-convert-json.c
> > @@ -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
Thanks for looking into it, will send a new one shortly.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH v1] perf data: Add fields when converting to json
2022-11-09 1:35 ` Ian Rogers
2022-11-09 10:37 ` Dmitry Dolgov
@ 2022-11-10 18:37 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-11-10 18:37 UTC (permalink / raw)
To: Ian Rogers; +Cc: Dmitrii Dolgov, linux-perf-users, mingo, jolsa
Em Tue, Nov 08, 2022 at 05:35:28PM -0800, Ian Rogers escreveu:
> On Tue, Nov 8, 2022 at 11:00 AM Dmitrii Dolgov <9erthalion6@gmail.com> wrote:
> >
> > 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"
> > }
> > ]
> > }
> >
> > Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
>
> Acked-by: Ian Rogers <irogers@google.com>
Thanks, applied.
- Arnaldo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-10 18:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-08 19:00 [RFC PATCH v1] perf data: Add fields when converting to json Dmitrii Dolgov
2022-11-09 1:35 ` Ian Rogers
2022-11-09 10:37 ` Dmitry Dolgov
2022-11-10 18:37 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).