tools/perf/builtin-list.c

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

File Facts

System
Linux kernel
Corpus path
tools/perf/builtin-list.c
Extension
.c
Size
21013 bytes
Lines
774
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 print_state {
	/** @fp: File to write output to. */
	FILE *fp;
	/**
	 * @pmu_glob: Optionally restrict PMU and metric matching to PMU or
	 * debugfs subsystem name.
	 */
	char *pmu_glob;
	/** @event_glob: Optional pattern matching glob. */
	char *event_glob;
	/** @name_only: Print event or metric names only. */
	bool name_only;
	/** @desc: Print the event or metric description. */
	bool desc;
	/** @long_desc: Print longer event or metric description. */
	bool long_desc;
	/** @deprecated: Print deprecated events or metrics. */
	bool deprecated;
	/**
	 * @detailed: Print extra information on the perf event such as names
	 * and expressions used internally by events.
	 */
	bool detailed;
	/** @metrics: Controls printing of metric and metric groups. */
	bool metrics;
	/** @metricgroups: Controls printing of metric and metric groups. */
	bool metricgroups;
	/** @exclude_abi: Exclude PMUs with types less than PERF_TYPE_MAX except PERF_TYPE_RAW. */
	bool exclude_abi;
	/** @last_topic: The last printed event topic. */
	char *last_topic;
	/** @last_metricgroups: The last printed metric group. */
	char *last_metricgroups;
	/** @visited_metrics: Metrics that are printed to avoid duplicates. */
	struct strlist *visited_metrics;
};

static void default_print_start(void *ps)
{
	struct print_state *print_state = ps;

	if (!print_state->name_only && pager_in_use()) {
		fprintf(print_state->fp,
			"\nList of pre-defined events (to be used in -e or -M):\n\n");
	}
}

static void default_print_end(void *print_state __maybe_unused) {}

static const char *skip_spaces_or_commas(const char *str)
{
	while (isspace(*str) || *str == ',')
		++str;
	return str;
}

static void wordwrap(FILE *fp, const char *s, int start, int max, int corr)
{
	int column = start;
	int n;
	bool saw_newline = false;
	bool comma = false;

	while (*s) {
		int wlen = strcspn(s, " ,\t\n");
		const char *sep = comma ? "," : " ";

		if ((column + wlen >= max && column > start) || saw_newline) {
			fprintf(fp, comma ? ",\n%*s" : "\n%*s", start, "");
			column = start + corr;
		}
		if (column <= start)
			sep = "";
		n = fprintf(fp, "%s%.*s", sep, wlen, s);
		if (n <= 0)
			break;
		saw_newline = s[wlen] == '\n';
		s += wlen;
		comma = s[0] == ',';
		column += n;
		s = skip_spaces_or_commas(s);
	}
}

static void default_print_event(void *ps, const char *topic,
				const char *pmu_name, u32 pmu_type,
				const char *event_name, const char *event_alias,
				const char *scale_unit __maybe_unused,
				bool deprecated, const char *event_type_desc,
				const char *desc, const char *long_desc,

Annotation

Implementation Notes