tools/perf/perf.c | 6 +++++- tools/perf/util/debug.c | 13 +++++++++++++ tools/perf/util/debug.h | 1 + 3 files changed, 19 insertions(+), 1 deletion(-)
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
Em Wed, Nov 01, 2023 at 06:45:43AM +0000, Yang Jihong escreveu: > 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] Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com> - Arnaldo > 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.
© 2016 - 2025 Red Hat, Inc.