tools/perf/util/mem-events.c
Source file repositories/reference/linux-study-clean/tools/perf/util/mem-events.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/mem-events.c- Extension
.c- Size
- 22435 bytes
- Lines
- 983
- 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
stddef.hstdlib.hstring.herrno.hsys/types.hsys/stat.hunistd.hapi/fs/fs.hlinux/kernel.hcpumap.hmap_symbol.hmem-events.hmem-info.hdebug.hevsel.hsymbol.hpmu.hpmus.h
Detected Declarations
function perf_pmu__mem_events_num_mem_pmusfunction is_mem_loads_aux_eventfunction perf_pmu__mem_events_parsefunction perf_pmu__mem_events_supportedfunction __perf_pmu__mem_events_initfunction perf_pmu__mem_events_initfunction perf_pmu__mem_events_listfunction perf_mem_events__record_argsfunction perf_mem__tlb_scnprintffunction perf_mem__op_scnprintffunction perf_mem__lvl_scnprintffunction perf_mem__snp_scnprintffunction perf_mem__lck_scnprintffunction perf_mem__blk_scnprintffunction perf_script__meminfo_scnprintffunction c2c_decode_statsfunction c2c_add_statsfunction mem_stat_index
Annotated Snippet
if (e->ldlat) {
if (!e->aux_event) {
/* ARM and Most of Intel */
scnprintf(buf, buf_size,
e->name, pmu->name,
perf_mem_events__loads_ldlat);
} else {
/* Intel with mem-loads-aux event */
scnprintf(buf, buf_size,
e->name, pmu->name, pmu->name,
perf_mem_events__loads_ldlat);
}
} else {
if (!e->aux_event) {
/* AMD and POWER */
scnprintf(buf, buf_size,
e->name, pmu->name);
} else {
return NULL;
}
}
return buf;
}
if (i == PERF_MEM_EVENTS__STORE) {
scnprintf(buf, buf_size,
e->name, pmu->name);
return buf;
}
return NULL;
}
bool is_mem_loads_aux_event(struct evsel *leader)
{
struct perf_pmu *pmu = leader->pmu;
struct perf_mem_event *e;
if (!pmu || !pmu->mem_events)
return false;
e = &pmu->mem_events[PERF_MEM_EVENTS__LOAD];
if (!e->aux_event)
return false;
return leader->core.attr.config == e->aux_event;
}
int perf_pmu__mem_events_parse(struct perf_pmu *pmu, const char *str)
{
char *tok, *saveptr = NULL;
bool found = false;
char *buf;
int j;
/* We need buffer that we know we can write to. */
buf = malloc(strlen(str) + 1);
if (!buf)
return -ENOMEM;
strcpy(buf, str);
tok = strtok_r((char *)buf, ",", &saveptr);
while (tok) {
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
struct perf_mem_event *e = perf_pmu__mem_events_ptr(pmu, j);
if (!e->tag)
continue;
if (strstr(e->tag, tok))
perf_mem_record[j] = found = true;
}
tok = strtok_r(NULL, ",", &saveptr);
}
free(buf);
if (found)
return 0;
pr_err("failed: event '%s' not found, use '-e list' to get list of available events\n", str);
return -1;
}
static bool perf_pmu__mem_events_supported(const char *mnt, struct perf_pmu *pmu,
struct perf_mem_event *e)
{
Annotation
- Immediate include surface: `stddef.h`, `stdlib.h`, `string.h`, `errno.h`, `sys/types.h`, `sys/stat.h`, `unistd.h`, `api/fs/fs.h`.
- Detected declarations: `function perf_pmu__mem_events_num_mem_pmus`, `function is_mem_loads_aux_event`, `function perf_pmu__mem_events_parse`, `function perf_pmu__mem_events_supported`, `function __perf_pmu__mem_events_init`, `function perf_pmu__mem_events_init`, `function perf_pmu__mem_events_list`, `function perf_mem_events__record_args`, `function perf_mem__tlb_scnprintf`, `function perf_mem__op_scnprintf`.
- 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.