Lines Matching +full:out +full:-
1 // SPDX-License-Identifier: GPL-2.0-only
8 #include "data-convert.h"
31 #include <traceevent/event-parse.h>
36 FILE *out; member
41 // Outputs a JSON-encoded string surrounded by quotes with characters escaped.
42 static void output_json_string(FILE *out, const char *s) in output_json_string() argument
44 fputc('"', out); in output_json_string()
49 case '"': fputs("\\\"", out); break; in output_json_string()
50 case '\\': fputs("\\\\", out); break; in output_json_string()
51 case '\b': fputs("\\b", out); break; in output_json_string()
52 case '\f': fputs("\\f", out); break; in output_json_string()
53 case '\n': fputs("\\n", out); break; in output_json_string()
54 case '\r': fputs("\\r", out); break; in output_json_string()
55 case '\t': fputs("\\t", out); break; in output_json_string()
60 fprintf(out, "\\u%04x", *s); in output_json_string()
62 fputc(*s, out); in output_json_string()
68 fputc('"', out); in output_json_string()
73 static void output_json_delimiters(FILE *out, bool comma, int depth) in output_json_delimiters() argument
78 fputc(',', out); in output_json_delimiters()
79 fputc('\n', out); in output_json_delimiters()
81 fputc('\t', out); in output_json_delimiters()
86 static void output_json_format(FILE *out, bool comma, int depth, const char *format, ...) in output_json_format() argument
90 output_json_delimiters(out, comma, depth); in output_json_format()
92 vfprintf(out, format, args); in output_json_format()
96 // Outputs a JSON key-value pair where the value is a string.
97 static void output_json_key_string(FILE *out, bool comma, int depth, in output_json_key_string() argument
100 output_json_delimiters(out, comma, depth); in output_json_key_string()
101 output_json_string(out, key); in output_json_key_string()
102 fputs(": ", out); in output_json_key_string()
103 output_json_string(out, value); in output_json_key_string()
106 // Outputs a JSON key-value pair where the value is a printf format string.
108 static void output_json_key_format(FILE *out, bool comma, int depth, in output_json_key_format() argument
113 output_json_delimiters(out, comma, depth); in output_json_key_format()
114 output_json_string(out, key); in output_json_key_format()
115 fputs(": ", out); in output_json_key_format()
117 vfprintf(out, format, args); in output_json_key_format()
125 FILE *out = c->out; in output_sample_callchain_entry() local
127 output_json_format(out, false, 4, "{"); in output_sample_callchain_entry()
128 output_json_key_format(out, false, 5, "ip", "\"0x%" PRIx64 "\"", ip); in output_sample_callchain_entry()
130 if (al && al->sym && al->sym->namelen) { in output_sample_callchain_entry()
131 struct dso *dso = al->map ? map__dso(al->map) : NULL; in output_sample_callchain_entry()
133 fputc(',', out); in output_sample_callchain_entry()
134 output_json_key_string(out, false, 5, "symbol", al->sym->name); in output_sample_callchain_entry()
140 fputc(',', out); in output_sample_callchain_entry()
141 output_json_key_string(out, false, 5, "dso", dso_name); in output_sample_callchain_entry()
146 output_json_format(out, false, 4, "}"); in output_sample_callchain_entry()
156 FILE *out = c->out; in process_sample_event() local
158 u64 sample_type = __evlist__combined_sample_type(evsel->evlist); in process_sample_event()
165 return -1; in process_sample_event()
168 ++c->events_count; in process_sample_event()
170 if (c->first) in process_sample_event()
171 c->first = false; in process_sample_event()
173 fputc(',', out); in process_sample_event()
174 output_json_format(out, false, 2, "{"); in process_sample_event()
176 output_json_key_format(out, false, 3, "timestamp", "%" PRIi64, sample->time); in process_sample_event()
177 output_json_key_format(out, true, 3, "pid", "%i", thread__pid(al.thread)); in process_sample_event()
178 output_json_key_format(out, true, 3, "tid", "%i", thread__tid(al.thread)); in process_sample_event()
181 output_json_key_format(out, true, 3, "cpu", "%i", sample->cpu); in process_sample_event()
183 output_json_key_format(out, true, 3, "cpu", "%i", thread__cpu(al.thread)); in process_sample_event()
185 output_json_key_string(out, true, 3, "comm", thread__comm_str(al.thread)); in process_sample_event()
187 output_json_key_format(out, true, 3, "callchain", "["); in process_sample_event()
188 if (sample->callchain) { in process_sample_event()
193 for (i = 0; i < sample->callchain->nr; ++i) { in process_sample_event()
194 u64 ip = sample->callchain->ips[i]; in process_sample_event()
219 fputc(',', out); in process_sample_event()
227 output_sample_callchain_entry(tool, sample->ip, &al); in process_sample_event()
229 output_json_format(out, false, 3, "]"); in process_sample_event()
232 if (sample->raw_data) { in process_sample_event()
236 fields = tep_event_fields(evsel->tp_format); in process_sample_event()
243 tep_print_field(&s, sample->raw_data, fields[i]); in process_sample_event()
244 output_json_key_string(out, true, 3, fields[i]->name, s.buffer); in process_sample_event()
252 output_json_format(out, false, 2, "}"); in process_sample_event()
260 struct perf_header *header = &session->header; in output_headers()
262 int fd = perf_data__fd(session->data); in output_headers()
264 FILE *out = c->out; in output_headers() local
266 output_json_key_format(out, false, 2, "header-version", "%u", header->version); in output_headers()
274 output_json_key_string(out, true, 2, "captured-on", buf); in output_headers()
276 pr_debug("Failed to get mtime of source file, not writing captured-on"); in output_headers()
279 output_json_key_format(out, true, 2, "data-offset", "%" PRIu64, header->data_offset); in output_headers()
280 output_json_key_format(out, true, 2, "data-size", "%" PRIu64, header->data_size); in output_headers()
281 output_json_key_format(out, true, 2, "feat-offset", "%" PRIu64, header->feat_offset); in output_headers()
283 output_json_key_string(out, true, 2, "hostname", header->env.hostname); in output_headers()
284 output_json_key_string(out, true, 2, "os-release", header->env.os_release); in output_headers()
285 output_json_key_string(out, true, 2, "arch", header->env.arch); in output_headers()
287 if (header->env.cpu_desc) in output_headers()
288 output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc); in output_headers()
290 output_json_key_string(out, true, 2, "cpuid", header->env.cpuid); in output_headers()
291 output_json_key_format(out, true, 2, "nrcpus-online", "%u", header->env.nr_cpus_online); in output_headers()
292 output_json_key_format(out, true, 2, "nrcpus-avail", "%u", header->env.nr_cpus_avail); in output_headers()
294 if (header->env.clock.enabled) { in output_headers()
295 output_json_key_format(out, true, 2, "clockid", in output_headers()
296 "%u", header->env.clock.clockid); in output_headers()
297 output_json_key_format(out, true, 2, "clock-time", in output_headers()
298 "%" PRIu64, header->env.clock.clockid_ns); in output_headers()
299 output_json_key_format(out, true, 2, "real-time", in output_headers()
300 "%" PRIu64, header->env.clock.tod_ns); in output_headers()
303 output_json_key_string(out, true, 2, "perf-version", header->env.version); in output_headers()
305 output_json_key_format(out, true, 2, "cmdline", "["); in output_headers()
306 for (i = 0; i < header->env.nr_cmdline; i++) { in output_headers()
307 output_json_delimiters(out, i != 0, 3); in output_headers()
308 output_json_string(c->out, header->env.cmdline_argv[i]); in output_headers()
310 output_json_format(out, false, 2, "]"); in output_headers()
318 int ret = -1; in bt_convert__perf2json()
326 .force = opts->force, in bt_convert__perf2json()
349 if (opts->all) { in bt_convert__perf2json()
350 pr_err("--all is currently unsupported for JSON output.\n"); in bt_convert__perf2json()
353 if (opts->tod) { in bt_convert__perf2json()
354 pr_err("--tod is currently unsupported for JSON output.\n"); in bt_convert__perf2json()
358 fd = open(output_name, O_CREAT | O_WRONLY | (opts->force ? O_TRUNC : O_EXCL), 0666); in bt_convert__perf2json()
359 if (fd == -1) { in bt_convert__perf2json()
361 pr_err("Output file exists. Use --force to overwrite it.\n"); in bt_convert__perf2json()
367 c.out = fdopen(fd, "w"); in bt_convert__perf2json()
368 if (!c.out) { in bt_convert__perf2json()
380 if (symbol__init(&session->header.env) < 0) { in bt_convert__perf2json()
387 fputc('{', c.out); in bt_convert__perf2json()
389 // Version number for future-proofing. Most additions should be able to be in bt_convert__perf2json()
390 // done in a backwards-compatible way so this should only need to be bumped in bt_convert__perf2json()
392 output_json_format(c.out, false, 1, "\"linux-perf-json-version\": 1"); in bt_convert__perf2json()
395 output_json_format(c.out, true, 1, "\"headers\": {"); in bt_convert__perf2json()
397 output_json_format(c.out, false, 1, "}"); in bt_convert__perf2json()
400 output_json_format(c.out, true, 1, "\"samples\": ["); in bt_convert__perf2json()
402 output_json_format(c.out, false, 1, "]"); in bt_convert__perf2json()
403 output_json_format(c.out, false, 0, "}"); in bt_convert__perf2json()
404 fputc('\n', c.out); in bt_convert__perf2json()
412 (ftell(c.out)) / 1024.0 / 1024.0, c.events_count); in bt_convert__perf2json()
418 fclose(c.out); in bt_convert__perf2json()