// Outputs a JSON-encoded string surrounded by quotes with characters escaped. staticvoid output_json_string(FILE *out, constchar *s)
{
fputc('"', out); while (*s) { switch (*s) {
// required escapes with special forms as per RFC 8259 case'"': fputs("\\\"", out); break; case'\\': fputs("\\\\", out); break; case'\b': fputs("\\b", out); break; case'\f': fputs("\\f", out); break; case'\n': fputs("\\n", out); break; case'\r': fputs("\\r", out); break; case'\t': fputs("\\t", out); break;
default: // all other control characters must be escaped by hex code if (*s <= 0x1f)
fprintf(out, "\\u%04x", *s); else
fputc(*s, out); break;
}
++s;
}
fputc('"', out);
}
// Outputs an optional comma, newline and indentation to delimit a new value // from the previous one in a JSON object or array. staticvoid output_json_delimiters(FILE *out, bool comma, int depth)
{ int i;
if (comma)
fputc(',', out);
fputc('\n', out); for (i = 0; i < depth; ++i)
fputc('\t', out);
}
// Outputs a printf format string (with delimiter) as a JSON value.
__printf(4, 5) staticvoid output_json_format(FILE *out, bool comma, int depth, constchar *format, ...)
{
va_list args;
output_json_delimiters(out, comma, depth);
va_start(args, format);
vfprintf(out, format, args);
va_end(args);
}
// Outputs a JSON key-value pair where the value is a string. staticvoid output_json_key_string(FILE *out, bool comma, int depth, constchar *key, constchar *value)
{
output_json_delimiters(out, comma, depth);
output_json_string(out, key);
fputs(": ", out);
output_json_string(out, value);
}
// Outputs a JSON key-value pair where the value is a printf format string.
__printf(5, 6) staticvoid output_json_key_format(FILE *out, bool comma, int depth, constchar *key, constchar *format, ...)
{
va_list args;
if (opts->all) {
pr_err("--all is currently unsupported for JSON output.\n"); goto err;
} if (opts->tod) {
pr_err("--tod is currently unsupported for JSON output.\n"); goto err;
}
fd = open(output_name, O_CREAT | O_WRONLY | (opts->force ? O_TRUNC : O_EXCL), 0666); if (fd == -1) { if (errno == EEXIST)
pr_err("Output file exists. Use --force to overwrite it.\n"); else
pr_err("Error opening output file!\n"); goto err;
}
// The opening brace is printed manually because it isn't delimited from a // previous value (i.e. we don't want a leading newline)
fputc('{', c.out);
// Version number for future-proofing. Most additions should be able to be // done in a backwards-compatible way so this should only need to be bumped // if some major breaking change must be made.
output_json_format(c.out, false, 1, "\"linux-perf-json-version\": 1");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.