tools/perf/util/stat-display.c
Source file repositories/reference/linux-study-clean/tools/perf/util/stat-display.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/stat-display.c- Extension
.c- Size
- 41992 bytes
- Lines
- 1604
- 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
stdlib.hstdio.hinttypes.hlinux/string.hlinux/time64.hmath.hperf/cpumap.hcolor.hcounts.hdebug.hevlist.hevsel.hstat.htop.hthread_map.hcpumap.hstring2.hlinux/ctype.hcgroup.hapi/fs/fs.hutil.hiostat.hpmu.hpmus.htool_pmu.h
Detected Declarations
struct outstatefunction print_running_stdfunction print_running_csvfunction print_running_jsonfunction print_runningfunction print_noise_pct_stdfunction print_noise_pct_csvfunction print_noise_pct_jsonfunction print_noise_pctfunction print_noisefunction print_cgroup_stdfunction print_cgroup_csvfunction print_cgroup_jsonfunction print_cgroupfunction print_aggr_id_stdfunction print_aggr_id_csvfunction print_aggr_id_jsonfunction aggr_printoutfunction new_line_stdfunction __new_line_std_csvfunction __new_line_stdfunction do_new_line_stdfunction print_metric_stdfunction new_line_csvfunction print_metric_csvfunction print_metric_jsonfunction new_line_jsonfunction print_metricgroup_header_jsonfunction print_metricgroup_header_csvfunction print_metricgroup_header_stdfunction print_metric_onlyfunction print_metric_only_csvfunction print_metric_only_jsonfunction print_metric_headerfunction print_counter_value_stdfunction print_counter_value_csvfunction print_counter_value_jsonfunction print_counter_valuefunction abs_printoutfunction evlist__has_hybrid_pmusfunction evlist__for_each_entryfunction printoutfunction should_skip_zero_countfunction perf_cpu_map__for_each_cpufunction print_counter_aggrdatafunction print_metric_beginfunction print_metric_endfunction print_aggr
Annotated Snippet
struct outstate {
/* Std mode: insert a newline before the next metric */
bool newline;
/* JSON mode: track need for comma for a previous field or not */
bool first;
/* Num CSV separators remaining to pad out when not all fields are printed */
int csv_col_pad;
/*
* The following don't track state across fields, but are here as a shortcut to
* pass data to the print functions. The alternative would be to update the
* function signatures of the entire print stack to pass them through.
*/
/* Place to output to */
FILE * const fh;
/* Lines are timestamped in --interval-print mode */
char timestamp[64];
/* Num items aggregated in current line. See struct perf_stat_aggr.nr */
int aggr_nr;
/* Core/socket/die etc ID for the current line */
struct aggr_cpu_id id;
/* Event for current line */
struct evsel *evsel;
/* Cgroup for current line */
struct cgroup *cgrp;
};
static const char *json_sep(struct outstate *os)
{
const char *sep = os->first ? "" : ", ";
os->first = false;
return sep;
}
#define json_out(os, format, ...) fprintf((os)->fh, "%s" format, json_sep(os), ##__VA_ARGS__)
static void print_running_json(struct outstate *os, u64 run, u64 ena)
{
double enabled_percent = 100;
if (run != ena)
enabled_percent = 100 * run / ena;
json_out(os, "\"event-runtime\" : %" PRIu64 ", \"pcnt-running\" : %.2f",
run, enabled_percent);
}
static void print_running(struct perf_stat_config *config, struct outstate *os,
u64 run, u64 ena, bool before_metric)
{
if (config->json_output) {
if (before_metric)
print_running_json(os, run, ena);
} else if (config->csv_output) {
if (before_metric)
print_running_csv(config, run, ena);
} else {
if (!before_metric)
print_running_std(config, run, ena);
}
}
static void print_noise_pct_std(struct perf_stat_config *config,
double pct)
{
if (pct)
fprintf(config->output, " ( +-%6.2f%% )", pct);
}
static void print_noise_pct_csv(struct perf_stat_config *config,
double pct)
{
fprintf(config->output, "%s%.2f%%", config->csv_sep, pct);
}
static void print_noise_pct_json(struct outstate *os,
double pct)
{
json_out(os, "\"variance\" : %.2f", pct);
}
static void print_noise_pct(struct perf_stat_config *config, struct outstate *os,
double total, double avg, bool before_metric)
{
double pct = rel_stddev_stats(total, avg);
if (config->json_output) {
if (before_metric)
print_noise_pct_json(os, pct);
} else if (config->csv_output) {
Annotation
- Immediate include surface: `stdlib.h`, `stdio.h`, `inttypes.h`, `linux/string.h`, `linux/time64.h`, `math.h`, `perf/cpumap.h`, `color.h`.
- Detected declarations: `struct outstate`, `function print_running_std`, `function print_running_csv`, `function print_running_json`, `function print_running`, `function print_noise_pct_std`, `function print_noise_pct_csv`, `function print_noise_pct_json`, `function print_noise_pct`, `function print_noise`.
- 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.