Commit b91a9abb authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

perf list: Skip ABI PMUs when printing pmu values



Avoid printing tracepoint, legacy and software events when listing for
the pmu option. Add the PMU type to the print_event callbacks to ease
detection.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/r/20250725185202.68671-8-irogers@google.com


Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent 55c09681
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ struct print_state {
	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. */
@@ -113,7 +115,8 @@ static void wordwrap(FILE *fp, const char *s, int start, int max, int corr)
	}
}

static void default_print_event(void *ps, const char *topic, const char *pmu_name,
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,
@@ -130,6 +133,9 @@ static void default_print_event(void *ps, const char *topic, const char *pmu_nam
	if (print_state->pmu_glob && pmu_name && !strglobmatch(pmu_name, print_state->pmu_glob))
		return;

	if (print_state->exclude_abi && pmu_type < PERF_TYPE_MAX && pmu_type != PERF_TYPE_RAW)
		return;

	if (print_state->event_glob &&
	    (!event_name || !strglobmatch(event_name, print_state->event_glob)) &&
	    (!event_alias || !strglobmatch(event_alias, print_state->event_glob)) &&
@@ -354,7 +360,8 @@ static void fix_escape_fprintf(FILE *fp, struct strbuf *buf, const char *fmt, ..
	fputs(buf->buf, fp);
}

static void json_print_event(void *ps, const char *topic, const char *pmu_name,
static void json_print_event(void *ps, const char *topic,
			     const char *pmu_name, u32 pmu_type __maybe_unused,
			     const char *event_name, const char *event_alias,
			     const char *scale_unit,
			     bool deprecated, const char *event_type_desc,
@@ -647,9 +654,11 @@ int cmd_list(int argc, const char **argv)
		} else if (strcmp(argv[i], "cache") == 0 ||
			 strcmp(argv[i], "hwcache") == 0)
			print_hwcache_events(&print_cb, ps);
		else if (strcmp(argv[i], "pmu") == 0)
		else if (strcmp(argv[i], "pmu") == 0) {
			default_ps.exclude_abi = true;
			perf_pmus__print_pmu_events(&print_cb, ps);
		else if (strcmp(argv[i], "sdt") == 0)
			default_ps.exclude_abi = false;
		} else if (strcmp(argv[i], "sdt") == 0)
			print_sdt_events(&print_cb, ps);
		else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0) {
			default_ps.metricgroups = false;
+2 −0
Original line number Diff line number Diff line
@@ -230,6 +230,7 @@ print_libpfm_event(const struct print_callbacks *print_cb, void *print_state,

	if (is_libpfm_event_supported(name, cpus, threads)) {
		print_cb->print_event(print_state, topic, pinfo->name,
				      /*pmu_type=*/PERF_TYPE_RAW,
				      name, info->equiv,
				      /*scale_unit=*/NULL,
				      /*deprecated=*/NULL, "PFM event",
@@ -265,6 +266,7 @@ print_libpfm_event(const struct print_callbacks *print_cb, void *print_state,
			print_cb->print_event(print_state,
					topic,
					pinfo->name,
					/*pmu_type=*/PERF_TYPE_RAW,
					name, /*alias=*/NULL,
					/*scale_unit=*/NULL,
					/*deprecated=*/NULL, "PFM event",
+2 −0
Original line number Diff line number Diff line
@@ -645,6 +645,7 @@ void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *p
		print_cb->print_event(print_state,
				aliases[j].topic,
				aliases[j].pmu_name,
				aliases[j].pmu->type,
				aliases[j].name,
				aliases[j].alias,
				aliases[j].scale_unit,
@@ -749,6 +750,7 @@ void perf_pmus__print_raw_pmu_events(const struct print_callbacks *print_cb, voi
		print_cb->print_event(print_state,
				/*topic=*/NULL,
				/*pmu_name=*/NULL,
				pmu->type,
				format_args.short_string.buf,
				/*event_alias=*/NULL,
				/*scale_unit=*/NULL,
+5 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
		print_cb->print_event(print_state,
				/*topic=*/NULL,
				/*pmu_name=*/NULL,
				PERF_TYPE_TRACEPOINT,
				evt_name ?: sdt_name->s,
				/*event_alias=*/NULL,
				/*deprecated=*/false,
@@ -222,6 +223,7 @@ int print_hwcache_events(const struct print_callbacks *print_cb, void *print_sta
					print_cb->print_event(print_state,
							"cache",
							pmu->name,
							pmu->type,
							name,
							alias_name,
							/*scale_unit=*/NULL,
@@ -278,6 +280,7 @@ void print_symbol_events(const struct print_callbacks *print_cb, void *print_sta
		print_cb->print_event(print_state,
				/*topic=*/NULL,
				/*pmu_name=*/NULL,
				type,
				nd->s,
				alias,
				/*scale_unit=*/NULL,
@@ -438,6 +441,7 @@ void print_events(const struct print_callbacks *print_cb, void *print_state)
	print_cb->print_event(print_state,
			/*topic=*/NULL,
			/*pmu_name=*/NULL,
			PERF_TYPE_RAW,
			"rNNN",
			/*event_alias=*/NULL,
			/*scale_unit=*/NULL,
@@ -452,6 +456,7 @@ void print_events(const struct print_callbacks *print_cb, void *print_state)
	print_cb->print_event(print_state,
			/*topic=*/NULL,
			/*pmu_name=*/NULL,
			PERF_TYPE_BREAKPOINT,
			"mem:<addr>[/len][:access]",
			/*scale_unit=*/NULL,
			/*event_alias=*/NULL,
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ struct print_callbacks {
	void (*print_start)(void *print_state);
	void (*print_end)(void *print_state);
	void (*print_event)(void *print_state, const char *topic,
			const char *pmu_name,
			const char *pmu_name, u32 pmu_type,
			const char *event_name, const char *event_alias,
			const char *scale_unit,
			bool deprecated, const char *event_type_desc,