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.

Dependency Surface

Detected Declarations

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

Implementation Notes