diff options
Diffstat (limited to 'tools/perf/builtin-evlist.c')
| -rw-r--r-- | tools/perf/builtin-evlist.c | 67 |
1 files changed, 54 insertions, 13 deletions
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c index 05bd9dfe875c..fb6e2c3c24c8 100644 --- a/tools/perf/builtin-evlist.c +++ b/tools/perf/builtin-evlist.c @@ -1,37 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Builtin evlist command: Show the list of event selectors present * in a perf.data file. */ #include "builtin.h" -#include "util/util.h" - #include <linux/list.h> -#include "perf.h" #include "util/evlist.h" #include "util/evsel.h" +#include "util/evsel_fprintf.h" #include "util/parse-events.h" -#include "util/parse-options.h" +#include <subcmd/parse-options.h> #include "util/session.h" +#include "util/data.h" +#include "util/debug.h" +#include <linux/err.h> +#include "util/tool.h" +#include "util/util.h" + +static int process_header_feature(const struct perf_tool *tool __maybe_unused, + struct perf_session *session __maybe_unused, + union perf_event *event __maybe_unused) +{ + session_done = 1; + return 0; +} static int __cmd_evlist(const char *file_name, struct perf_attr_details *details) { struct perf_session *session; - struct perf_evsel *pos; + struct evsel *pos; + struct perf_data data = { + .path = file_name, + .mode = PERF_DATA_MODE_READ, + .force = details->force, + }; + struct perf_tool tool; + bool has_tracepoint = false, has_group = false; - session = perf_session__new(file_name, O_RDONLY, 0, false, NULL); - if (session == NULL) - return -ENOMEM; + perf_tool__init(&tool, /*ordered_events=*/false); + /* only needed for pipe mode */ + tool.attr = perf_event__process_attr; + tool.feature = process_header_feature; + session = perf_session__new(&data, &tool); + if (IS_ERR(session)) + return PTR_ERR(session); - list_for_each_entry(pos, &session->evlist->entries, node) - perf_evsel__fprintf(pos, details, stdout); + if (data.is_pipe) + perf_session__process_events(session); + + evlist__for_each_entry(session->evlist, pos) { + evsel__fprintf(pos, details, stdout); + + if (pos->core.attr.type == PERF_TYPE_TRACEPOINT) + has_tracepoint = true; + + if (!evsel__is_group_leader(pos)) + has_group = true; + } + + if (has_tracepoint && !details->trace_fields) + printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n"); + + if (has_group && !details->event_group) + printf("# Tip: use 'perf evlist -g' to show group information\n"); perf_session__delete(session); return 0; } -int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused) +int cmd_evlist(int argc, const char **argv) { struct perf_attr_details details = { .verbose = false, }; const struct option options[] = { @@ -41,6 +80,8 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused) "Show all event attr details"), OPT_BOOLEAN('g', "group", &details.event_group, "Show event group information"), + OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"), + OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"), OPT_END() }; const char * const evlist_usage[] = { @@ -53,8 +94,8 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused) usage_with_options(evlist_usage, options); if (details.event_group && (details.verbose || details.freq)) { - pr_err("--group option is not compatible with other options\n"); - usage_with_options(evlist_usage, options); + usage_with_options_msg(evlist_usage, options, + "--group option is not compatible with other options\n"); } return __cmd_evlist(input_name, &details); |
