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.
- 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
errno.hmath.hstdio.hevsel.hstat.hcolor.hdebug.hpmu.hrblist.hevlist.hexpr.hmetricgroup.hcgroup.hunits.hiostat.hutil/hashmap.htool_pmu.h
Detected Declarations
function tool_pmu__is_time_eventfunction prepare_metricfunction evlist__for_each_entryfunction generic_metricfunction test_generic_metricfunction perf_stat__print_metricgroup_headerfunction metricgroupfunction list_for_each_entry_fromfunction perf_stat__print_shadow_statsfunction perf_stat__skip_metric_event
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
- Immediate include surface: `errno.h`, `math.h`, `stdio.h`, `evsel.h`, `stat.h`, `color.h`, `debug.h`, `pmu.h`.
- Detected declarations: `function tool_pmu__is_time_event`, `function prepare_metric`, `function evlist__for_each_entry`, `function generic_metric`, `function test_generic_metric`, `function perf_stat__print_metricgroup_header`, `function metricgroup`, `function list_for_each_entry_from`, `function perf_stat__print_shadow_stats`, `function perf_stat__skip_metric_event`.
- 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.