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.

Dependency Surface

Detected Declarations

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

Implementation Notes