tools/perf/builtin-stat.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-stat.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-stat.c- Extension
.c- Size
- 85808 bytes
- Lines
- 3070
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
builtin.hutil/cgroup.hsubcmd/parse-options.hutil/parse-events.hutil/pmus.hutil/pmu.hutil/tool_pmu.hutil/event.hutil/evlist.hutil/evsel.hutil/debug.hutil/color.hutil/stat.hutil/header.hutil/cpumap.hutil/thread_map.hutil/counts.hutil/topdown.hutil/session.hutil/tool.hutil/string2.hutil/metricgroup.hutil/synthetic-events.hutil/target.hutil/time-utils.hutil/top.hutil/affinity.hutil/pfm.hutil/bpf_counter.hutil/iostat.hutil/util.hutil/intel-tpebs.h
Detected Declarations
struct rusage_statsstruct perf_statstruct opt_aggr_modeenum counter_recoveryfunction opt_aggr_mode_to_aggr_modefunction evlist__check_cpu_mapsfunction evlist__for_each_entryfunction diff_timespecfunction perf_stat__reset_statsfunction process_synthesized_eventfunction write_stat_round_eventfunction evsel__write_stat_eventfunction read_single_counterfunction evsel__tool_eventfunction read_counter_cpufunction read_counters_with_affinityfunction evlist__for_each_cpufunction read_bpf_map_countersfunction evlist__for_each_entryfunction read_tool_countersfunction evlist__for_each_entryfunction perf_cpu_map__for_each_idxfunction read_countersfunction process_countersfunction evlist__for_each_entryfunction process_intervalfunction handle_intervalfunction enable_countersfunction evlist__for_each_entryfunction disable_countersfunction workload_exec_failed_signalfunction evsel__should_store_idfunction is_target_alivefunction process_evlistfunction compute_ttsfunction dispatch_eventsfunction stat_handle_errorfunction create_perf_stat_counterfunction update_rusage_statsfunction __run_perf_statfunction evlist__for_each_entryfunction evsel__open_per_cpufunction evlist__for_each_cpufunction evlist__for_each_cpufunction run_perf_statfunction print_countersfunction skip_signalfunction sig_atexit
Annotated Snippet
struct rusage_stats {
struct stats ru_utime_usec_stat;
struct stats ru_stime_usec_stat;
};
static void print_counters(struct timespec *ts, int argc, const char **argv);
static struct evlist *evsel_list;
static struct parse_events_option_args parse_events_option_args = {
.evlistp = &evsel_list,
};
static bool all_counters_use_bpf = true;
static struct target target;
static volatile sig_atomic_t child_pid = -1;
static int detailed_run = 0;
static bool transaction_run;
static bool topdown_run = false;
static bool smi_cost = false;
static bool smi_reset = false;
static int big_num_opt = -1;
static const char *pre_cmd = NULL;
static const char *post_cmd = NULL;
static bool sync_run = false;
static bool forever = false;
static bool force_metric_only = false;
static struct timespec ref_time;
static bool append_file;
static bool interval_count;
static const char *output_name;
static int output_fd;
static char *metrics;
static struct rusage_stats ru_stats;
struct perf_stat {
bool record;
struct perf_data data;
struct perf_session *session;
u64 bytes_written;
struct perf_tool tool;
bool maps_allocated;
struct perf_cpu_map *cpus;
struct perf_thread_map *threads;
enum aggr_mode aggr_mode;
u32 aggr_level;
};
static struct perf_stat perf_stat;
#define STAT_RECORD perf_stat.record
static volatile sig_atomic_t done = 0;
/* Options set from the command line. */
struct opt_aggr_mode {
bool node, socket, die, cluster, cache, core, thread, no_aggr;
};
/* Turn command line option into most generic aggregation mode setting. */
static enum aggr_mode opt_aggr_mode_to_aggr_mode(const struct opt_aggr_mode *opt_mode)
{
enum aggr_mode mode = AGGR_GLOBAL;
if (opt_mode->node)
mode = AGGR_NODE;
if (opt_mode->socket)
mode = AGGR_SOCKET;
if (opt_mode->die)
mode = AGGR_DIE;
if (opt_mode->cluster)
mode = AGGR_CLUSTER;
if (opt_mode->cache)
mode = AGGR_CACHE;
if (opt_mode->core)
mode = AGGR_CORE;
if (opt_mode->thread)
mode = AGGR_THREAD;
if (opt_mode->no_aggr)
mode = AGGR_NONE;
return mode;
}
static void evlist__check_cpu_maps(struct evlist *evlist)
{
struct evsel *evsel, *warned_leader = NULL;
evlist__for_each_entry(evlist, evsel) {
struct evsel *leader = evsel__leader(evsel);
Annotation
- Immediate include surface: `builtin.h`, `util/cgroup.h`, `subcmd/parse-options.h`, `util/parse-events.h`, `util/pmus.h`, `util/pmu.h`, `util/tool_pmu.h`, `util/event.h`.
- Detected declarations: `struct rusage_stats`, `struct perf_stat`, `struct opt_aggr_mode`, `enum counter_recovery`, `function opt_aggr_mode_to_aggr_mode`, `function evlist__check_cpu_maps`, `function evlist__for_each_entry`, `function diff_timespec`, `function perf_stat__reset_stats`, `function process_synthesized_event`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.