^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Builtin evlist command: Show the list of event selectors present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * in a perf.data file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "builtin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "perf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "util/evlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "util/evsel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "util/evsel_fprintf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "util/parse-events.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <subcmd/parse-options.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "util/session.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "util/data.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "util/debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct perf_session *session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct evsel *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct perf_data data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) .path = file_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .mode = PERF_DATA_MODE_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .force = details->force,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) bool has_tracepoint = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) session = perf_session__new(&data, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (IS_ERR(session))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return PTR_ERR(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) evlist__for_each_entry(session->evlist, pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) evsel__fprintf(pos, details, stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (pos->core.attr.type == PERF_TYPE_TRACEPOINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) has_tracepoint = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (has_tracepoint && !details->trace_fields)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) perf_session__delete(session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int cmd_evlist(int argc, const char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct perf_attr_details details = { .verbose = false, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) const struct option options[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) OPT_STRING('i', "input", &input_name, "file", "Input file name"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) OPT_BOOLEAN('v', "verbose", &details.verbose,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) "Show all event attr details"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) OPT_BOOLEAN('g', "group", &details.event_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) "Show event group information"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) OPT_END()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) const char * const evlist_usage[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) "perf evlist [<options>]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) argc = parse_options(argc, argv, options, evlist_usage, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (argc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) usage_with_options(evlist_usage, options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (details.event_group && (details.verbose || details.freq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) usage_with_options_msg(evlist_usage, options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) "--group option is not compatible with other options\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return __cmd_evlist(input_name, &details);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }