tools/perf/perf.c

Source file repositories/reference/linux-study-clean/tools/perf/perf.c

File Facts

System
Linux kernel
Corpus path
tools/perf/perf.c
Extension
.c
Size
13420 bytes
Lines
581
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 cmd_struct {
	const char *cmd;
	int (*fn)(int, const char **);
	int option;
};

static const struct cmd_struct commands[] = {
	{ "archive",	NULL,	0 },
	{ "buildid-cache", cmd_buildid_cache, 0 },
	{ "buildid-list", cmd_buildid_list, 0 },
	{ "check",	cmd_check,	0 },
	{ "config",	cmd_config,	0 },
	{ "c2c",	cmd_c2c,	0 },
	{ "diff",	cmd_diff,	0 },
	{ "evlist",	cmd_evlist,	0 },
	{ "help",	cmd_help,	0 },
	{ "iostat",	NULL,	0 },
	{ "kallsyms",	cmd_kallsyms,	0 },
	{ "list",	cmd_list,	0 },
	{ "record",	cmd_record,	0 },
	{ "report",	cmd_report,	0 },
	{ "bench",	cmd_bench,	0 },
	{ "stat",	cmd_stat,	0 },
#ifdef HAVE_LIBTRACEEVENT
	{ "timechart",	cmd_timechart,	0 },
#endif
	{ "top",	cmd_top,	0 },
	{ "annotate",	cmd_annotate,	0 },
	{ "version",	cmd_version,	0 },
	{ "script",	cmd_script,	0 },
#ifdef HAVE_LIBTRACEEVENT
	{ "sched",	cmd_sched,	0 },
#endif
#ifdef HAVE_LIBELF_SUPPORT
	{ "probe",	cmd_probe,	0 },
#endif
#ifdef HAVE_LIBTRACEEVENT
	{ "kmem",	cmd_kmem,	0 },
	{ "lock",	cmd_lock,	0 },
#endif
	{ "kvm",	cmd_kvm,	0 },
	{ "test",	cmd_test,	0 },
#if defined(HAVE_LIBTRACEEVENT)
	{ "trace",	cmd_trace,	0 },
#endif
	{ "inject",	cmd_inject,	0 },
	{ "mem",	cmd_mem,	0 },
	{ "data",	cmd_data,	0 },
	{ "ftrace",	cmd_ftrace,	0 },
	{ "daemon",	cmd_daemon,	0 },
#ifdef HAVE_LIBTRACEEVENT
	{ "kwork",	cmd_kwork,	0 },
#endif
};

struct pager_config {
	const char *cmd;
	int val;
};

static bool same_cmd_with_prefix(const char *var, struct pager_config *c,
				  const char *header)
{
	return (strstarts(var, header) && !strcmp(var + strlen(header), c->cmd));
}

static int pager_command_config(const char *var, const char *value, void *data)
{
	struct pager_config *c = data;
	if (same_cmd_with_prefix(var, c, "pager."))
		c->val = perf_config_bool(var, value);
	return 0;
}

/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
static int check_pager_config(const char *cmd)
{
	int err;
	struct pager_config c;
	c.cmd = cmd;
	c.val = -1;
	err = perf_config(pager_command_config, &c);
	return err ?: c.val;
}

static int browser_command_config(const char *var, const char *value, void *data)
{
	struct pager_config *c = data;
	if (same_cmd_with_prefix(var, c, "tui."))
		c->val = perf_config_bool(var, value);

Annotation

Implementation Notes