tools/perf/util/pfm.c
Source file repositories/reference/linux-study-clean/tools/perf/util/pfm.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/pfm.c- Extension
.c- Size
- 7463 bytes
- Lines
- 322
- 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
util/cpumap.hutil/debug.hutil/event.hutil/evlist.hutil/evsel.hutil/parse-events.hutil/pmus.hutil/pfm.hutil/strbuf.hutil/thread_map.herrno.hstring.hlinux/kernel.hperfmon/pfmlib_perf_event.h
Detected Declarations
function libpfm_initializefunction parse_libpfm_events_optionfunction is_libpfm_event_supportedfunction print_attr_flagsfunction print_libpfm_eventfunction pfm_for_each_event_attrfunction pfm_for_each_event_attrfunction print_libpfm_eventsfunction pfm_for_all_pmus
Annotated Snippet
if (*sep == '{') {
if (grp_evt > -1) {
ui__error(
"nested event groups not supported\n");
goto error;
}
grp_evt++;
}
/* no event */
if (*q == '\0') {
if (*sep == '}') {
if (grp_evt < 0) {
ui__error("cannot close a non-existing event group\n");
goto error;
}
grp_evt--;
}
continue;
}
memset(&attr, 0, sizeof(attr));
event_attr_init(&attr);
ret = pfm_get_perf_event_encoding(q, PFM_PLM0|PFM_PLM3,
&attr, NULL, NULL);
if (ret != PFM_SUCCESS) {
ui__error("failed to parse event %s : %s\n", str,
pfm_strerror(ret));
goto error;
}
pmu = perf_pmus__find_by_type((unsigned int)attr.type);
evsel = parse_events__add_event(evlist->core.nr_entries,
&attr, q, /*metric_id=*/NULL,
pmu);
if (evsel == NULL)
goto error;
evsel->is_libpfm_event = true;
evlist__add(evlist, evsel);
if (grp_evt == 0)
grp_leader = evsel;
if (grp_evt > -1) {
evsel__set_leader(evsel, grp_leader);
grp_leader->core.nr_members++;
grp_evt++;
}
if (*sep == '}') {
if (grp_evt < 0) {
ui__error(
"cannot close a non-existing event group\n");
goto error;
}
grp_leader = NULL;
grp_evt = -1;
}
}
free(p_orig);
return 0;
error:
free(p_orig);
return -1;
}
static bool is_libpfm_event_supported(const char *name, struct perf_cpu_map *cpus,
struct perf_thread_map *threads)
{
struct perf_pmu *pmu;
struct evsel *evsel;
struct perf_event_attr attr = {};
bool result = true;
int ret;
ret = pfm_get_perf_event_encoding(name, PFM_PLM0|PFM_PLM3,
&attr, NULL, NULL);
if (ret != PFM_SUCCESS)
return false;
pmu = perf_pmus__find_by_type((unsigned int)attr.type);
evsel = parse_events__add_event(0, &attr, name, /*metric_id=*/NULL, pmu);
if (evsel == NULL)
return false;
evsel->is_libpfm_event = true;
Annotation
- Immediate include surface: `util/cpumap.h`, `util/debug.h`, `util/event.h`, `util/evlist.h`, `util/evsel.h`, `util/parse-events.h`, `util/pmus.h`, `util/pfm.h`.
- Detected declarations: `function libpfm_initialize`, `function parse_libpfm_events_option`, `function is_libpfm_event_supported`, `function print_attr_flags`, `function print_libpfm_event`, `function pfm_for_each_event_attr`, `function pfm_for_each_event_attr`, `function print_libpfm_events`, `function pfm_for_all_pmus`.
- 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.