tools/perf/util/stat.c
Source file repositories/reference/linux-study-clean/tools/perf/util/stat.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/stat.c- Extension
.c- Size
- 16884 bytes
- Lines
- 722
- 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.hlinux/err.hinttypes.hmath.hstring.hcounts.hcpumap.hdebug.hheader.hstat.hsession.htarget.hevlist.hevsel.hthread_map.hutil/hashmap.hlinux/zalloc.h
Detected Declarations
function update_statsfunction avg_statsfunction sqrtfunction rel_stddev_statsfunction evsel__reset_aggr_statsfunction evsel__reset_stat_privfunction evsel__alloc_aggr_statsfunction evlist__alloc_aggr_statsfunction evlist__for_each_entryfunction evsel__alloc_stat_privfunction evsel__free_stat_privfunction evsel__alloc_prev_raw_countsfunction evsel__free_prev_raw_countsfunction evsel__reset_prev_raw_countsfunction evsel__alloc_statsfunction evlist__alloc_statsfunction evlist__for_each_entryfunction evlist__free_statsfunction evlist__for_each_entryfunction evlist__reset_statsfunction evlist__for_each_entryfunction evlist__reset_aggr_statsfunction evlist__reset_prev_raw_countsfunction evsel__copy_prev_raw_countsfunction perf_cpu_map__for_each_idxfunction evlist__copy_prev_raw_countsfunction evsel__copy_res_statsfunction evlist__copy_res_statsfunction pkg_id_hashfunction pkg_id_equalfunction check_per_pkgfunction evsel__count_has_errorfunction process_counter_valuesfunction process_counter_mapsfunction perf_stat_process_counterfunction evsel__merge_aggr_countersfunction evsel__merge_aliasesfunction evsel__should_merge_hybridfunction evsel__merge_statsfunction perf_stat_merge_countersfunction evsel__update_percore_statsfunction evsel__process_percorefunction perf_cpu_map__for_each_cpufunction perf_stat_process_percorefunction perf_event__process_stat_eventfunction perf_event__fprintf_statfunction perf_event__fprintf_stat_roundfunction perf_event__fprintf_stat_config
Annotated Snippet
perf_cpu_map__for_each_idx(idx, evsel__cpus(evsel)) {
*perf_counts(evsel->counts, idx, thread) =
*perf_counts(evsel->prev_raw_counts, idx, thread);
}
}
}
void evlist__copy_prev_raw_counts(struct evlist *evlist)
{
struct evsel *evsel;
evlist__for_each_entry(evlist, evsel)
evsel__copy_prev_raw_counts(evsel);
}
static void evsel__copy_res_stats(struct evsel *evsel)
{
struct perf_stat_evsel *ps = evsel->stats;
/*
* For GLOBAL aggregation mode, it updates the counts for each run
* in the evsel->stats.res_stats. See perf_stat_process_counter().
*/
*ps->aggr[0].counts.values = avg_stats(&ps->res_stats);
}
void evlist__copy_res_stats(struct perf_stat_config *config, struct evlist *evlist)
{
struct evsel *evsel;
if (config->aggr_mode != AGGR_GLOBAL)
return;
evlist__for_each_entry(evlist, evsel)
evsel__copy_res_stats(evsel);
}
static size_t pkg_id_hash(long __key, void *ctx __maybe_unused)
{
uint64_t *key = (uint64_t *) __key;
return *key & 0xffffffff;
}
static bool pkg_id_equal(long __key1, long __key2, void *ctx __maybe_unused)
{
uint64_t *key1 = (uint64_t *) __key1;
uint64_t *key2 = (uint64_t *) __key2;
return *key1 == *key2;
}
static int check_per_pkg(struct evsel *counter, struct perf_counts_values *vals,
int cpu_map_idx, bool *skip)
{
struct hashmap *mask = counter->per_pkg_mask;
struct perf_cpu_map *cpus = evsel__cpus(counter);
struct perf_cpu cpu = perf_cpu_map__cpu(cpus, cpu_map_idx);
int s, d, ret = 0;
uint64_t *key;
*skip = false;
if (!counter->per_pkg)
return 0;
if (perf_cpu_map__is_any_cpu_or_is_empty(cpus))
return 0;
if (!mask) {
mask = hashmap__new(pkg_id_hash, pkg_id_equal, NULL);
if (IS_ERR(mask))
return -ENOMEM;
counter->per_pkg_mask = mask;
}
/*
* we do not consider an event that has not run as a good
* instance to mark a package as used (skip=1). Otherwise
* we may run into a situation where the first CPU in a package
* is not running anything, yet the second is, and this function
* would mark the package as used after the first CPU and would
* not read the values from the second CPU.
*/
if (!(vals->run && vals->ena))
return 0;
s = cpu__get_socket_id(cpu);
if (s < 0)
Annotation
- Immediate include surface: `errno.h`, `linux/err.h`, `inttypes.h`, `math.h`, `string.h`, `counts.h`, `cpumap.h`, `debug.h`.
- Detected declarations: `function update_stats`, `function avg_stats`, `function sqrt`, `function rel_stddev_stats`, `function evsel__reset_aggr_stats`, `function evsel__reset_stat_priv`, `function evsel__alloc_aggr_stats`, `function evlist__alloc_aggr_stats`, `function evlist__for_each_entry`, `function evsel__alloc_stat_priv`.
- 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.