tools/perf/util/stat-shadow.c

Source file repositories/reference/linux-study-clean/tools/perf/util/stat-shadow.c

File Facts

System
Linux kernel
Corpus path
tools/perf/util/stat-shadow.c
Extension
.c
Size
9690 bytes
Lines
352
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

cpu_aggr_map__for_each_idx(aggr_idx, config->aggr_map) {
			if (config->aggr_map->map[aggr_idx].cpu.cpu == 0) {
				*tool_aggr_idx = aggr_idx;
				return true;
			}
		}
		pr_debug("Unexpected CPU0 missing in aggregation for tool event.\n");
	}
	*tool_aggr_idx = 0; /* Assume the first aggregation index works. */
	return true;
}

static int prepare_metric(struct perf_stat_config *config,
			  const struct metric_expr *mexp,
			  const struct evsel *evsel,
			  struct expr_parse_ctx *pctx,
			  int aggr_idx)
{
	struct evsel * const *metric_events = mexp->metric_events;
	struct metric_ref *metric_refs = mexp->metric_refs;
	int i;

	for (i = 0; metric_events[i]; i++) {
		int source_count = 0, tool_aggr_idx;
		bool is_tool_time =
			tool_pmu__is_time_event(config, metric_events[i], &tool_aggr_idx);
		struct perf_stat_evsel *ps = metric_events[i]->stats;
		char *n;
		double val;

		/*
		 * If there are multiple uncore PMUs and we're not reading the
		 * leader's stats, determine the stats for the appropriate
		 * uncore PMU.
		 */
		if (evsel && evsel->metric_leader &&
		    evsel->pmu != evsel->metric_leader->pmu &&
		    mexp->metric_events[i]->pmu == evsel->metric_leader->pmu) {
			struct evsel *pos;

			evlist__for_each_entry(evsel->evlist, pos) {
				if (pos->pmu != evsel->pmu)
					continue;
				if (pos->metric_leader != mexp->metric_events[i])
					continue;
				ps = pos->stats;
				source_count = 1;
				break;
			}
		}
		/* Time events are always on CPU0, the first aggregation index. */
		if (!ps || !metric_events[i]->supported) {
			/*
			 * Not supported events will have a count of 0, which
			 * can be confusing in a metric. Explicitly set the
			 * value to NAN. Not counted events (enable time of 0)
			 * are read as 0.
			 */
			val = NAN;
			source_count = 0;
		} else {
			struct perf_stat_aggr *aggr =
				&ps->aggr[is_tool_time ? tool_aggr_idx : aggr_idx];

			if (aggr->counts.run == 0) {
				val = NAN;
				source_count = 0;
			} else {
				val = aggr->counts.val;
				if (is_tool_time) {
					/* Convert time event nanoseconds to seconds. */
					val *= 1e-9;
				}
				if (!source_count)
					source_count = evsel__source_count(metric_events[i]);
			}
		}
		n = strdup(evsel__metric_id(metric_events[i]));
		if (!n)
			return -ENOMEM;

		expr__add_id_val_source_count(pctx, n, val, source_count);
	}

	for (int j = 0; metric_refs && metric_refs[j].metric_name; j++) {
		int ret = expr__add_ref(pctx, &metric_refs[j]);

		if (ret)
			return ret;
	}

Annotation

Implementation Notes