tools/perf/util/data-convert-json.c
Source file repositories/reference/linux-study-clean/tools/perf/util/data-convert-json.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/data-convert-json.c- Extension
.c- Size
- 12533 bytes
- Lines
- 460
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
data-convert.hfcntl.hinttypes.hsys/stat.hunistd.hlinux/compiler.hlinux/err.hutil/auxtrace.hutil/debug.hutil/dso.hutil/event.hutil/evsel.hutil/evlist.hutil/header.hutil/map.hutil/session.hutil/symbol.hutil/thread.hutil/time-utils.hutil/tool.hevent-parse.h
Detected Declarations
struct convert_jsonfunction output_json_stringfunction output_json_delimitersfunction output_json_formatfunction output_json_key_stringfunction output_json_key_formatfunction output_sample_callchain_entryfunction process_sample_eventfunction output_headersfunction bt_convert__perf2json
Annotated Snippet
struct convert_json {
struct perf_tool tool;
FILE *out;
bool first;
struct perf_time_interval *ptime_range;
int range_size;
int range_num;
u64 events_count;
u64 skipped;
};
// Outputs a JSON-encoded string surrounded by quotes with characters escaped.
static void output_json_string(FILE *out, const char *s)
{
fputc('"', out);
if (!s)
goto 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;
}
out:
fputc('"', out);
}
// Outputs an optional comma, newline and indentation to delimit a new value
// from the previous one in a JSON object or array.
static void 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)
static void output_json_format(FILE *out, bool comma, int depth, const char *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.
static void output_json_key_string(FILE *out, bool comma, int depth,
const char *key, const char *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)
static void output_json_key_format(FILE *out, bool comma, int depth,
const char *key, const char *format, ...)
{
va_list args;
output_json_delimiters(out, comma, depth);
output_json_string(out, key);
Annotation
- Immediate include surface: `data-convert.h`, `fcntl.h`, `inttypes.h`, `sys/stat.h`, `unistd.h`, `linux/compiler.h`, `linux/err.h`, `util/auxtrace.h`.
- Detected declarations: `struct convert_json`, `function output_json_string`, `function output_json_delimiters`, `function output_json_format`, `function output_json_key_string`, `function output_json_key_format`, `function output_sample_callchain_entry`, `function process_sample_event`, `function output_headers`, `function bt_convert__perf2json`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.