Lines Matching +full:convert +full:- +full:sample +full:- +full:format
1 // SPDX-License-Identifier: GPL-2.0-only
8 #include "data-convert.h"
31 #include <event-parse.h>
41 // Outputs a JSON-encoded string surrounded by quotes with characters escaped.
84 // Outputs a printf format string (with delimiter) as a JSON value.
86 static void output_json_format(FILE *out, bool comma, int depth, const char *format, ...)
91 va_start(args, format);
92 vfprintf(out, format, args);
96 // Outputs a JSON key-value pair where the value is a string.
106 // Outputs a JSON key-value pair where the value is a printf format string.
109 const char *key, const char *format, ...)
116 va_start(args, format);
117 vfprintf(out, format, args);
125 FILE *out = c->out;
130 if (al && al->sym && al->sym->namelen) {
131 struct dso *dso = al->map ? map__dso(al->map) : NULL;
134 output_json_key_string(out, false, 5, "symbol", al->sym->name);
151 struct perf_sample *sample,
156 FILE *out = c->out;
158 u64 sample_type = __evlist__combined_sample_type(evsel->evlist);
162 if (machine__resolve(machine, &al, sample) < 0) {
163 pr_err("Sample resolution failed!\n");
165 return -1;
168 ++c->events_count;
170 if (c->first)
171 c->first = false;
176 output_json_key_format(out, false, 3, "timestamp", "%" PRIi64, sample->time);
181 output_json_key_format(out, true, 3, "cpu", "%i", sample->cpu);
188 if (sample->callchain) {
193 for (i = 0; i < sample->callchain->nr; ++i) {
194 u64 ip = sample->callchain->ips[i];
227 output_sample_callchain_entry(tool, sample->ip, &al);
232 if (sample->raw_data) {
243 tep_print_field(&s, sample->raw_data, fields[i]);
244 output_json_key_string(out, true, 3, fields[i]->name, s.buffer);
260 struct perf_header *header = &session->header;
262 int fd = perf_data__fd(session->data);
264 FILE *out = c->out;
266 output_json_key_format(out, false, 2, "header-version", "%u", header->version);
274 output_json_key_string(out, true, 2, "captured-on", buf);
276 pr_debug("Failed to get mtime of source file, not writing captured-on");
279 output_json_key_format(out, true, 2, "data-offset", "%" PRIu64, header->data_offset);
280 output_json_key_format(out, true, 2, "data-size", "%" PRIu64, header->data_size);
281 output_json_key_format(out, true, 2, "feat-offset", "%" PRIu64, header->feat_offset);
283 output_json_key_string(out, true, 2, "hostname", header->env.hostname);
284 output_json_key_string(out, true, 2, "os-release", header->env.os_release);
285 output_json_key_string(out, true, 2, "arch", header->env.arch);
287 if (header->env.cpu_desc)
288 output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
290 output_json_key_string(out, true, 2, "cpuid", header->env.cpuid);
291 output_json_key_format(out, true, 2, "nrcpus-online", "%u", header->env.nr_cpus_online);
292 output_json_key_format(out, true, 2, "nrcpus-avail", "%u", header->env.nr_cpus_avail);
294 if (header->env.clock.enabled) {
296 "%u", header->env.clock.clockid);
297 output_json_key_format(out, true, 2, "clock-time",
298 "%" PRIu64, header->env.clock.clockid_ns);
299 output_json_key_format(out, true, 2, "real-time",
300 "%" PRIu64, header->env.clock.tod_ns);
303 output_json_key_string(out, true, 2, "perf-version", header->env.version);
306 for (i = 0; i < header->env.nr_cmdline; i++) {
308 output_json_string(c->out, header->env.cmdline_argv[i]);
318 int ret = -1;
326 .force = opts->force,
330 c.tool.sample = process_sample_event;
349 if (opts->all) {
350 pr_err("--all is currently unsupported for JSON output.\n");
353 if (opts->tod) {
354 pr_err("--tod is currently unsupported for JSON output.\n");
358 fd = open(output_name, O_CREAT | O_WRONLY | (opts->force ? O_TRUNC : O_EXCL), 0666);
359 if (fd == -1) {
361 pr_err("Output file exists. Use --force to overwrite it.\n");
380 if (symbol__init(&session->header.env) < 0) {
389 // Version number for future-proofing. Most additions should be able to be
390 // done in a backwards-compatible way so this should only need to be bumped
392 output_json_format(c.out, false, 1, "\"linux-perf-json-version\": 1");
407 "[ perf data convert: Converted '%s' into JSON data '%s' ]\n",
411 "[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples) ]\n",