tools/perf/builtin-mem.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-mem.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-mem.c- Extension
.c- Size
- 13522 bytes
- Lines
- 555
- 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.hinttypes.hsys/types.hsys/stat.hunistd.hbuiltin.hperf.hsubcmd/parse-options.hutil/auxtrace.hutil/trace-event.hutil/tool.hutil/session.hutil/data.hutil/map_symbol.hutil/mem-events.hutil/debug.hutil/dso.hutil/map.hutil/symbol.hutil/pmus.hutil/sample.hutil/sort.hutil/string2.hutil/util.hlinux/err.h
Detected Declarations
struct perf_memstruct mem_modefunction parse_record_eventsfunction __cmd_recordfunction dump_raw_samplesfunction process_sample_eventfunction report_raw_eventsfunction weightfunction __cmd_reportfunction parse_mem_opsfunction cmd_mem
Annotated Snippet
struct perf_mem {
struct perf_tool tool;
const char *input_name;
const char *sort_key;
bool hide_unresolved;
bool dump_raw;
bool force;
bool phys_addr;
bool data_page_size;
bool all_kernel;
bool all_user;
bool data_type;
int operation;
const char *cpu_list;
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
};
static int parse_record_events(const struct option *opt,
const char *str, int unset __maybe_unused)
{
struct perf_mem *mem = (struct perf_mem *)opt->value;
struct perf_pmu *pmu;
pmu = perf_mem_events_find_pmu();
if (!pmu) {
pr_err("failed: there is no PMU that supports perf mem\n");
exit(-1);
}
if (!strcmp(str, "list")) {
perf_pmu__mem_events_list(pmu);
exit(0);
}
if (perf_pmu__mem_events_parse(pmu, str))
exit(-1);
mem->operation = 0;
return 0;
}
static int __cmd_record(int argc, const char **argv, struct perf_mem *mem,
const struct option *options)
{
int rec_argc, i = 0, j;
int start, end;
const char **rec_argv;
char *event_name_storage = NULL;
int ret;
struct perf_mem_event *e;
struct perf_pmu *pmu;
const char * const record_usage[] = {
"perf mem record [<options>] [<command>]",
"perf mem record [<options>] -- <command> [<options>]",
NULL
};
pmu = perf_mem_events_find_pmu();
if (!pmu) {
pr_err("failed: no PMU supports the memory events\n");
return -1;
}
if (perf_pmu__mem_events_init()) {
pr_err("failed: memory events not supported\n");
return -1;
}
argc = parse_options(argc, argv, options, record_usage,
PARSE_OPT_KEEP_UNKNOWN);
/* Max number of arguments multiplied by number of PMUs that can support them. */
rec_argc = argc + 9 * (perf_pmu__mem_events_num_mem_pmus(pmu) + 1);
if (mem->cpu_list)
rec_argc += 2;
rec_argv = calloc(rec_argc + 1, sizeof(char *));
if (!rec_argv)
return -1;
rec_argv[i++] = "record";
e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__LOAD_STORE);
/*
* The load and store operations are required, use the event
* PERF_MEM_EVENTS__LOAD_STORE if it is supported.
*/
if (e->tag &&
(mem->operation & MEM_OPERATION_LOAD) &&
Annotation
- Immediate include surface: `errno.h`, `inttypes.h`, `sys/types.h`, `sys/stat.h`, `unistd.h`, `builtin.h`, `perf.h`, `subcmd/parse-options.h`.
- Detected declarations: `struct perf_mem`, `struct mem_mode`, `function parse_record_events`, `function __cmd_record`, `function dump_raw_samples`, `function process_sample_event`, `function report_raw_events`, `function weight`, `function __cmd_report`, `function parse_mem_ops`.
- 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.