All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] perf debug: List available options when no variable is specified
@ 2023-11-01  6:45 Yang Jihong
  2023-11-03 15:29 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Jihong @ 2023-11-01  6:45 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
	namhyung, irogers, adrian.hunter, linux-perf-users, linux-kernel
  Cc: yangjihong1

Minor help message improvement for `perf --debug`

Before:

  # perf --debug
  No variable specified for --debug.

   Usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

After:

  # perf --debug
  No variable specified for --debug, available options: verbose,ordered-events,stderr,data-convert,perf-event-open

   Usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
---

Changes since v1:
 - Provide helper to iterate debug_opts and print name instead of adding a new variable.

 tools/perf/perf.c       |  6 +++++-
 tools/perf/util/debug.c | 13 +++++++++++++
 tools/perf/util/debug.h |  1 +
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index d3fc8090413c..f29c3ef818a3 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -279,7 +279,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 			exit(0);
 		} else if (!strcmp(cmd, "--debug")) {
 			if (*argc < 2) {
-				fprintf(stderr, "No variable specified for --debug.\n");
+				fprintf(stderr,
+					"No variable specified for --debug, available options: ");
+				perf_debug_fprint_options(stderr);
+				fprintf(stderr, "\n");
+
 				usage(perf_usage_string);
 			}
 			if (perf_debug_option((*argv)[1]))
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 88378c4c5dd9..a014e6198d41 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -246,6 +246,19 @@ int perf_debug_option(const char *str)
 	return 0;
 }
 
+void perf_debug_fprint_options(FILE *file)
+{
+	struct sublevel_option *opt = debug_opts;
+
+	if (!file)
+		return;
+
+	while (opt->name) {
+		fprintf(file, "%s%s", opt == debug_opts ? "" : ",", opt->name);
+		opt++;
+	}
+}
+
 int perf_quiet_option(void)
 {
 	struct sublevel_option *opt = &debug_opts[0];
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index f99468a7f681..17294834cdb4 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -77,6 +77,7 @@ int eprintf_time(int level, int var, u64 t, const char *fmt, ...) __printf(4, 5)
 int veprintf(int level, int var, const char *fmt, va_list args);
 
 int perf_debug_option(const char *str);
+void perf_debug_fprint_options(FILE *file);
 void debug_set_file(FILE *file);
 void debug_set_display_time(bool set);
 void perf_debug_setup(void);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-03 15:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-01  6:45 [PATCH v2] perf debug: List available options when no variable is specified Yang Jihong
2023-11-03 15:29 ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.