Lines Matching +full:data +full:- +full:out

1 // SPDX-License-Identifier: GPL-2.0-only
8 #include "data-convert.h"
32 FILE *out; member
37 // Outputs a JSON-encoded string surrounded by quotes with characters escaped.
38 static void output_json_string(FILE *out, const char *s) in output_json_string() argument
40 fputc('"', out); in output_json_string()
45 case '"': fputs("\\\"", out); break; in output_json_string()
46 case '\\': fputs("\\\\", out); break; in output_json_string()
47 case '\b': fputs("\\b", out); break; in output_json_string()
48 case '\f': fputs("\\f", out); break; in output_json_string()
49 case '\n': fputs("\\n", out); break; in output_json_string()
50 case '\r': fputs("\\r", out); break; in output_json_string()
51 case '\t': fputs("\\t", out); break; in output_json_string()
56 fprintf(out, "\\u%04x", *s); in output_json_string()
58 fputc(*s, out); in output_json_string()
64 fputc('"', out); in output_json_string()
69 static void output_json_delimiters(FILE *out, bool comma, int depth) in output_json_delimiters() argument
74 fputc(',', out); in output_json_delimiters()
75 fputc('\n', out); in output_json_delimiters()
77 fputc('\t', out); in output_json_delimiters()
82 static void output_json_format(FILE *out, bool comma, int depth, const char *format, ...) in output_json_format() argument
86 output_json_delimiters(out, comma, depth); in output_json_format()
88 vfprintf(out, format, args); in output_json_format()
92 // Outputs a JSON key-value pair where the value is a string.
93 static void output_json_key_string(FILE *out, bool comma, int depth, in output_json_key_string() argument
96 output_json_delimiters(out, comma, depth); in output_json_key_string()
97 output_json_string(out, key); in output_json_key_string()
98 fputs(": ", out); in output_json_key_string()
99 output_json_string(out, value); in output_json_key_string()
102 // Outputs a JSON key-value pair where the value is a printf format string.
104 static void output_json_key_format(FILE *out, bool comma, int depth, in output_json_key_format() argument
109 output_json_delimiters(out, comma, depth); in output_json_key_format()
110 output_json_string(out, key); in output_json_key_format()
111 fputs(": ", out); in output_json_key_format()
113 vfprintf(out, format, args); in output_json_key_format()
121 FILE *out = c->out; in output_sample_callchain_entry() local
123 output_json_format(out, false, 4, "{"); in output_sample_callchain_entry()
124 output_json_key_format(out, false, 5, "ip", "\"0x%" PRIx64 "\"", ip); in output_sample_callchain_entry()
126 if (al && al->sym && al->sym->namelen) { in output_sample_callchain_entry()
127 fputc(',', out); in output_sample_callchain_entry()
128 output_json_key_string(out, false, 5, "symbol", al->sym->name); in output_sample_callchain_entry()
130 if (al->map && al->map->dso) { in output_sample_callchain_entry()
131 const char *dso = al->map->dso->short_name; in output_sample_callchain_entry()
134 fputc(',', out); in output_sample_callchain_entry()
135 output_json_key_string(out, false, 5, "dso", dso); in output_sample_callchain_entry()
140 output_json_format(out, false, 4, "}"); in output_sample_callchain_entry()
150 FILE *out = c->out; in process_sample_event() local
152 u64 sample_type = __evlist__combined_sample_type(evsel->evlist); in process_sample_event()
157 return -1; in process_sample_event()
160 ++c->events_count; in process_sample_event()
162 if (c->first) in process_sample_event()
163 c->first = false; in process_sample_event()
165 fputc(',', out); in process_sample_event()
166 output_json_format(out, false, 2, "{"); in process_sample_event()
168 output_json_key_format(out, false, 3, "timestamp", "%" PRIi64, sample->time); in process_sample_event()
169 output_json_key_format(out, true, 3, "pid", "%i", al.thread->pid_); in process_sample_event()
170 output_json_key_format(out, true, 3, "tid", "%i", al.thread->tid); in process_sample_event()
173 output_json_key_format(out, true, 3, "cpu", "%i", sample->cpu); in process_sample_event()
174 else if (al.thread->cpu >= 0) in process_sample_event()
175 output_json_key_format(out, true, 3, "cpu", "%i", al.thread->cpu); in process_sample_event()
177 output_json_key_string(out, true, 3, "comm", thread__comm_str(al.thread)); in process_sample_event()
179 output_json_key_format(out, true, 3, "callchain", "["); in process_sample_event()
180 if (sample->callchain) { in process_sample_event()
185 for (i = 0; i < sample->callchain->nr; ++i) { in process_sample_event()
186 u64 ip = sample->callchain->ips[i]; in process_sample_event()
210 fputc(',', out); in process_sample_event()
216 output_sample_callchain_entry(tool, sample->ip, &al); in process_sample_event()
218 output_json_format(out, false, 3, "]"); in process_sample_event()
220 output_json_format(out, false, 2, "}"); in process_sample_event()
227 struct perf_header *header = &session->header; in output_headers()
229 int fd = perf_data__fd(session->data); in output_headers()
231 FILE *out = c->out; in output_headers() local
233 output_json_key_format(out, false, 2, "header-version", "%u", header->version); in output_headers()
241 output_json_key_string(out, true, 2, "captured-on", buf); in output_headers()
243 pr_debug("Failed to get mtime of source file, not writing captured-on"); in output_headers()
246 output_json_key_format(out, true, 2, "data-offset", "%" PRIu64, header->data_offset); in output_headers()
247 output_json_key_format(out, true, 2, "data-size", "%" PRIu64, header->data_size); in output_headers()
248 output_json_key_format(out, true, 2, "feat-offset", "%" PRIu64, header->feat_offset); in output_headers()
250 output_json_key_string(out, true, 2, "hostname", header->env.hostname); in output_headers()
251 output_json_key_string(out, true, 2, "os-release", header->env.os_release); in output_headers()
252 output_json_key_string(out, true, 2, "arch", header->env.arch); in output_headers()
254 output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc); in output_headers()
255 output_json_key_string(out, true, 2, "cpuid", header->env.cpuid); in output_headers()
256 output_json_key_format(out, true, 2, "nrcpus-online", "%u", header->env.nr_cpus_online); in output_headers()
257 output_json_key_format(out, true, 2, "nrcpus-avail", "%u", header->env.nr_cpus_avail); in output_headers()
259 if (header->env.clock.enabled) { in output_headers()
260 output_json_key_format(out, true, 2, "clockid", in output_headers()
261 "%u", header->env.clock.clockid); in output_headers()
262 output_json_key_format(out, true, 2, "clock-time", in output_headers()
263 "%" PRIu64, header->env.clock.clockid_ns); in output_headers()
264 output_json_key_format(out, true, 2, "real-time", in output_headers()
265 "%" PRIu64, header->env.clock.tod_ns); in output_headers()
268 output_json_key_string(out, true, 2, "perf-version", header->env.version); in output_headers()
270 output_json_key_format(out, true, 2, "cmdline", "["); in output_headers()
271 for (i = 0; i < header->env.nr_cmdline; i++) { in output_headers()
272 output_json_delimiters(out, i != 0, 3); in output_headers()
273 output_json_string(c->out, header->env.cmdline_argv[i]); in output_headers()
275 output_json_format(out, false, 2, "]"); in output_headers()
283 int ret = -1; in bt_convert__perf2json()
309 struct perf_data data = { in bt_convert__perf2json() local
312 .force = opts->force, in bt_convert__perf2json()
315 if (opts->all) { in bt_convert__perf2json()
316 pr_err("--all is currently unsupported for JSON output.\n"); in bt_convert__perf2json()
319 if (opts->tod) { in bt_convert__perf2json()
320 pr_err("--tod is currently unsupported for JSON output.\n"); in bt_convert__perf2json()
324 fd = open(output_name, O_CREAT | O_WRONLY | (opts->force ? O_TRUNC : O_EXCL), 0666); in bt_convert__perf2json()
325 if (fd == -1) { in bt_convert__perf2json()
327 pr_err("Output file exists. Use --force to overwrite it.\n"); in bt_convert__perf2json()
333 c.out = fdopen(fd, "w"); in bt_convert__perf2json()
334 if (!c.out) { in bt_convert__perf2json()
340 session = perf_session__new(&data, &c.tool); in bt_convert__perf2json()
346 if (symbol__init(&session->header.env) < 0) { in bt_convert__perf2json()
353 fputc('{', c.out); in bt_convert__perf2json()
355 // Version number for future-proofing. Most additions should be able to be in bt_convert__perf2json()
356 // done in a backwards-compatible way so this should only need to be bumped in bt_convert__perf2json()
358 output_json_format(c.out, false, 1, "\"linux-perf-json-version\": 1"); in bt_convert__perf2json()
361 output_json_format(c.out, true, 1, "\"headers\": {"); in bt_convert__perf2json()
363 output_json_format(c.out, false, 1, "}"); in bt_convert__perf2json()
366 output_json_format(c.out, true, 1, "\"samples\": ["); in bt_convert__perf2json()
368 output_json_format(c.out, false, 1, "]"); in bt_convert__perf2json()
369 output_json_format(c.out, false, 0, "}"); in bt_convert__perf2json()
370 fputc('\n', c.out); in bt_convert__perf2json()
373 "[ perf data convert: Converted '%s' into JSON data '%s' ]\n", in bt_convert__perf2json()
374 data.path, output_name); in bt_convert__perf2json()
377 "[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples) ]\n", in bt_convert__perf2json()
378 (ftell(c.out)) / 1024.0 / 1024.0, c.events_count); in bt_convert__perf2json()
384 fclose(c.out); in bt_convert__perf2json()