tools/perf/tests/parse-metric.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/parse-metric.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/parse-metric.c- Extension
.c- Size
- 8221 bytes
- Lines
- 306
- 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
linux/compiler.herrno.hstring.hperf/cpumap.hperf/evlist.hmetricgroup.htests.hpmu-events/pmu-events.hevlist.hrblist.hdebug.hexpr.hstat.hpmus.h
Detected Declarations
struct valuefunction find_valuefunction load_runtime_statfunction compute_singlefunction evlist__for_each_entryfunction __compute_metricfunction compute_metricfunction compute_metric_groupfunction test_ipcfunction test_frontendfunction test_cache_miss_cyclesfunction test_dcache_l2function test_recursion_failfunction test_memory_bandwidthfunction test_metric_groupfunction test__parse_metric
Annotated Snippet
struct value {
const char *event;
u64 val;
};
static u64 find_value(const char *name, struct value *values)
{
struct value *v = values;
while (v->event) {
if (!strcmp(name, v->event))
return v->val;
v++;
}
return 0;
}
static void load_runtime_stat(struct evlist *evlist, struct value *vals)
{
struct evsel *evsel;
u64 count;
evlist__alloc_aggr_stats(evlist, 1);
evlist__for_each_entry(evlist, evsel) {
count = find_value(evsel->name, vals);
evsel->supported = true;
evsel->stats->aggr->counts.val = count;
evsel->stats->aggr->counts.ena = 1;
evsel->stats->aggr->counts.run = 1;
}
}
static double compute_single(struct evlist *evlist, const char *name)
{
struct metric_expr *mexp;
struct metric_event *me;
struct evsel *evsel;
evlist__for_each_entry(evlist, evsel) {
me = metricgroup__lookup(&evlist->metric_events, evsel, false);
if (me != NULL) {
list_for_each_entry (mexp, &me->head, nd) {
if (strcmp(mexp->metric_name, name))
continue;
return test_generic_metric(mexp, 0);
}
}
}
return 0.;
}
static int __compute_metric(const char *name, struct value *vals,
const char *name1, double *ratio1,
const char *name2, double *ratio2)
{
const struct pmu_metrics_table *pme_test;
struct perf_cpu_map *cpus;
struct evlist *evlist;
int err;
/*
* We need to prepare evlist for stat mode running on CPU 0
* because that's where all the stats are going to be created.
*/
evlist = evlist__new();
if (!evlist)
return -ENOMEM;
cpus = perf_cpu_map__new("0");
if (!cpus) {
evlist__delete(evlist);
return -ENOMEM;
}
perf_evlist__set_maps(&evlist->core, cpus, NULL);
/* Parse the metric into metric_events list. */
pme_test = find_core_metrics_table("testarch", "testcpu");
err = metricgroup__parse_groups_test(evlist, pme_test, name);
if (err)
goto out;
err = evlist__alloc_stats(/*config=*/NULL, evlist, /*alloc_raw=*/false);
if (err)
goto out;
/* Load the runtime stats with given numbers for events. */
load_runtime_stat(evlist, vals);
/* And execute the metric */
Annotation
- Immediate include surface: `linux/compiler.h`, `errno.h`, `string.h`, `perf/cpumap.h`, `perf/evlist.h`, `metricgroup.h`, `tests.h`, `pmu-events/pmu-events.h`.
- Detected declarations: `struct value`, `function find_value`, `function load_runtime_stat`, `function compute_single`, `function evlist__for_each_entry`, `function __compute_metric`, `function compute_metric`, `function compute_metric_group`, `function test_ipc`, `function test_frontend`.
- 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.