builtin-list.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * builtin-list.c
  4. *
  5. * Builtin list command: list all event types
  6. *
  7. * Copyright (C) 2009, Thomas Gleixner <tglx@linutronix.de>
  8. * Copyright (C) 2008-2009, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
  9. * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
  10. */
  11. #include "builtin.h"
  12. #include "util/print-events.h"
  13. #include "util/pmus.h"
  14. #include "util/pmu.h"
  15. #include "util/debug.h"
  16. #include "util/metricgroup.h"
  17. #include "util/pfm.h"
  18. #include "util/string2.h"
  19. #include "util/strlist.h"
  20. #include "util/strbuf.h"
  21. #include <subcmd/pager.h>
  22. #include <subcmd/parse-options.h>
  23. #include <linux/zalloc.h>
  24. #include <ctype.h>
  25. #include <stdarg.h>
  26. #include <stdio.h>
  27. /**
  28. * struct print_state - State and configuration passed to the default_print
  29. * functions.
  30. */
  31. struct print_state {
  32. /** @fp: File to write output to. */
  33. FILE *fp;
  34. /**
  35. * @pmu_glob: Optionally restrict PMU and metric matching to PMU or
  36. * debugfs subsystem name.
  37. */
  38. char *pmu_glob;
  39. /** @event_glob: Optional pattern matching glob. */
  40. char *event_glob;
  41. /** @name_only: Print event or metric names only. */
  42. bool name_only;
  43. /** @desc: Print the event or metric description. */
  44. bool desc;
  45. /** @long_desc: Print longer event or metric description. */
  46. bool long_desc;
  47. /** @deprecated: Print deprecated events or metrics. */
  48. bool deprecated;
  49. /**
  50. * @detailed: Print extra information on the perf event such as names
  51. * and expressions used internally by events.
  52. */
  53. bool detailed;
  54. /** @metrics: Controls printing of metric and metric groups. */
  55. bool metrics;
  56. /** @metricgroups: Controls printing of metric and metric groups. */
  57. bool metricgroups;
  58. /** @last_topic: The last printed event topic. */
  59. char *last_topic;
  60. /** @last_metricgroups: The last printed metric group. */
  61. char *last_metricgroups;
  62. /** @visited_metrics: Metrics that are printed to avoid duplicates. */
  63. struct strlist *visited_metrics;
  64. };
  65. static void default_print_start(void *ps)
  66. {
  67. struct print_state *print_state = ps;
  68. if (!print_state->name_only && pager_in_use()) {
  69. fprintf(print_state->fp,
  70. "\nList of pre-defined events (to be used in -e or -M):\n\n");
  71. }
  72. }
  73. static void default_print_end(void *print_state __maybe_unused) {}
  74. static const char *skip_spaces_or_commas(const char *str)
  75. {
  76. while (isspace(*str) || *str == ',')
  77. ++str;
  78. return str;
  79. }
  80. static void wordwrap(FILE *fp, const char *s, int start, int max, int corr)
  81. {
  82. int column = start;
  83. int n;
  84. bool saw_newline = false;
  85. bool comma = false;
  86. while (*s) {
  87. int wlen = strcspn(s, " ,\t\n");
  88. const char *sep = comma ? "," : " ";
  89. if ((column + wlen >= max && column > start) || saw_newline) {
  90. fprintf(fp, comma ? ",\n%*s" : "\n%*s", start, "");
  91. column = start + corr;
  92. }
  93. if (column <= start)
  94. sep = "";
  95. n = fprintf(fp, "%s%.*s", sep, wlen, s);
  96. if (n <= 0)
  97. break;
  98. saw_newline = s[wlen] == '\n';
  99. s += wlen;
  100. comma = s[0] == ',';
  101. column += n;
  102. s = skip_spaces_or_commas(s);
  103. }
  104. }
  105. static void default_print_event(void *ps, const char *topic, const char *pmu_name,
  106. const char *event_name, const char *event_alias,
  107. const char *scale_unit __maybe_unused,
  108. bool deprecated, const char *event_type_desc,
  109. const char *desc, const char *long_desc,
  110. const char *encoding_desc)
  111. {
  112. struct print_state *print_state = ps;
  113. int pos;
  114. FILE *fp = print_state->fp;
  115. if (deprecated && !print_state->deprecated)
  116. return;
  117. if (print_state->pmu_glob && pmu_name && !strglobmatch(pmu_name, print_state->pmu_glob))
  118. return;
  119. if (print_state->event_glob &&
  120. (!event_name || !strglobmatch(event_name, print_state->event_glob)) &&
  121. (!event_alias || !strglobmatch(event_alias, print_state->event_glob)) &&
  122. (!topic || !strglobmatch_nocase(topic, print_state->event_glob)))
  123. return;
  124. if (print_state->name_only) {
  125. if (event_alias && strlen(event_alias))
  126. fprintf(fp, "%s ", event_alias);
  127. else
  128. fprintf(fp, "%s ", event_name);
  129. return;
  130. }
  131. if (strcmp(print_state->last_topic, topic ?: "")) {
  132. if (topic)
  133. fprintf(fp, "\n%s:\n", topic);
  134. zfree(&print_state->last_topic);
  135. print_state->last_topic = strdup(topic ?: "");
  136. }
  137. if (event_alias && strlen(event_alias))
  138. pos = fprintf(fp, " %s OR %s", event_name, event_alias);
  139. else
  140. pos = fprintf(fp, " %s", event_name);
  141. if (!topic && event_type_desc) {
  142. for (; pos < 53; pos++)
  143. fputc(' ', fp);
  144. fprintf(fp, "[%s]\n", event_type_desc);
  145. } else
  146. fputc('\n', fp);
  147. if (long_desc && print_state->long_desc) {
  148. fprintf(fp, "%*s", 8, "[");
  149. wordwrap(fp, long_desc, 8, pager_get_columns(), 0);
  150. fprintf(fp, "]\n");
  151. } else if (desc && print_state->desc) {
  152. char *desc_with_unit = NULL;
  153. int desc_len = -1;
  154. if (pmu_name && strcmp(pmu_name, "default_core")) {
  155. desc_len = strlen(desc);
  156. desc_len = asprintf(&desc_with_unit,
  157. desc_len > 0 && desc[desc_len - 1] != '.'
  158. ? "%s. Unit: %s" : "%s Unit: %s",
  159. desc, pmu_name);
  160. }
  161. fprintf(fp, "%*s", 8, "[");
  162. wordwrap(fp, desc_len > 0 ? desc_with_unit : desc, 8, pager_get_columns(), 0);
  163. fprintf(fp, "]\n");
  164. free(desc_with_unit);
  165. }
  166. if (print_state->detailed && encoding_desc) {
  167. fprintf(fp, "%*s", 8, "");
  168. wordwrap(fp, encoding_desc, 8, pager_get_columns(), 0);
  169. fputc('\n', fp);
  170. }
  171. }
  172. static void default_print_metric(void *ps,
  173. const char *group,
  174. const char *name,
  175. const char *desc,
  176. const char *long_desc,
  177. const char *expr,
  178. const char *threshold,
  179. const char *unit __maybe_unused)
  180. {
  181. struct print_state *print_state = ps;
  182. FILE *fp = print_state->fp;
  183. if (print_state->event_glob &&
  184. (!print_state->metrics || !name || !strglobmatch(name, print_state->event_glob)) &&
  185. (!print_state->metricgroups || !group || !strglobmatch(group, print_state->event_glob)))
  186. return;
  187. if (!print_state->name_only && !print_state->last_metricgroups) {
  188. if (print_state->metricgroups) {
  189. fprintf(fp, "\nMetric Groups:\n");
  190. if (!print_state->metrics)
  191. fputc('\n', fp);
  192. } else {
  193. fprintf(fp, "\nMetrics:\n\n");
  194. }
  195. }
  196. if (!print_state->last_metricgroups ||
  197. strcmp(print_state->last_metricgroups, group ?: "")) {
  198. if (group && print_state->metricgroups) {
  199. if (print_state->name_only) {
  200. fprintf(fp, "%s ", group);
  201. } else {
  202. const char *gdesc = print_state->desc
  203. ? describe_metricgroup(group)
  204. : NULL;
  205. const char *print_colon = "";
  206. if (print_state->metrics) {
  207. print_colon = ":";
  208. fputc('\n', fp);
  209. }
  210. if (gdesc)
  211. fprintf(fp, "%s%s [%s]\n", group, print_colon, gdesc);
  212. else
  213. fprintf(fp, "%s%s\n", group, print_colon);
  214. }
  215. }
  216. zfree(&print_state->last_metricgroups);
  217. print_state->last_metricgroups = strdup(group ?: "");
  218. }
  219. if (!print_state->metrics)
  220. return;
  221. if (print_state->name_only) {
  222. if (print_state->metrics &&
  223. !strlist__has_entry(print_state->visited_metrics, name)) {
  224. fprintf(fp, "%s ", name);
  225. strlist__add(print_state->visited_metrics, name);
  226. }
  227. return;
  228. }
  229. fprintf(fp, " %s\n", name);
  230. if (long_desc && print_state->long_desc) {
  231. fprintf(fp, "%*s", 8, "[");
  232. wordwrap(fp, long_desc, 8, pager_get_columns(), 0);
  233. fprintf(fp, "]\n");
  234. } else if (desc && print_state->desc) {
  235. fprintf(fp, "%*s", 8, "[");
  236. wordwrap(fp, desc, 8, pager_get_columns(), 0);
  237. fprintf(fp, "]\n");
  238. }
  239. if (expr && print_state->detailed) {
  240. fprintf(fp, "%*s", 8, "[");
  241. wordwrap(fp, expr, 8, pager_get_columns(), 0);
  242. fprintf(fp, "]\n");
  243. }
  244. if (threshold && print_state->detailed) {
  245. fprintf(fp, "%*s", 8, "[");
  246. wordwrap(fp, threshold, 8, pager_get_columns(), 0);
  247. fprintf(fp, "]\n");
  248. }
  249. }
  250. struct json_print_state {
  251. /** @fp: File to write output to. */
  252. FILE *fp;
  253. /** Should a separator be printed prior to the next item? */
  254. bool need_sep;
  255. };
  256. static void json_print_start(void *ps)
  257. {
  258. struct json_print_state *print_state = ps;
  259. FILE *fp = print_state->fp;
  260. fprintf(fp, "[\n");
  261. }
  262. static void json_print_end(void *ps)
  263. {
  264. struct json_print_state *print_state = ps;
  265. FILE *fp = print_state->fp;
  266. fprintf(fp, "%s]\n", print_state->need_sep ? "\n" : "");
  267. }
  268. static void fix_escape_fprintf(FILE *fp, struct strbuf *buf, const char *fmt, ...)
  269. {
  270. va_list args;
  271. va_start(args, fmt);
  272. strbuf_setlen(buf, 0);
  273. for (size_t fmt_pos = 0; fmt_pos < strlen(fmt); fmt_pos++) {
  274. switch (fmt[fmt_pos]) {
  275. case '%':
  276. fmt_pos++;
  277. switch (fmt[fmt_pos]) {
  278. case 's': {
  279. const char *s = va_arg(args, const char*);
  280. strbuf_addstr(buf, s);
  281. break;
  282. }
  283. case 'S': {
  284. const char *s = va_arg(args, const char*);
  285. for (size_t s_pos = 0; s_pos < strlen(s); s_pos++) {
  286. switch (s[s_pos]) {
  287. case '\n':
  288. strbuf_addstr(buf, "\\n");
  289. break;
  290. case '\r':
  291. strbuf_addstr(buf, "\\r");
  292. break;
  293. case '\\':
  294. fallthrough;
  295. case '\"':
  296. strbuf_addch(buf, '\\');
  297. fallthrough;
  298. default:
  299. strbuf_addch(buf, s[s_pos]);
  300. break;
  301. }
  302. }
  303. break;
  304. }
  305. default:
  306. pr_err("Unexpected format character '%c'\n", fmt[fmt_pos]);
  307. strbuf_addch(buf, '%');
  308. strbuf_addch(buf, fmt[fmt_pos]);
  309. }
  310. break;
  311. default:
  312. strbuf_addch(buf, fmt[fmt_pos]);
  313. break;
  314. }
  315. }
  316. va_end(args);
  317. fputs(buf->buf, fp);
  318. }
  319. static void json_print_event(void *ps, const char *topic, const char *pmu_name,
  320. const char *event_name, const char *event_alias,
  321. const char *scale_unit,
  322. bool deprecated, const char *event_type_desc,
  323. const char *desc, const char *long_desc,
  324. const char *encoding_desc)
  325. {
  326. struct json_print_state *print_state = ps;
  327. bool need_sep = false;
  328. FILE *fp = print_state->fp;
  329. struct strbuf buf;
  330. strbuf_init(&buf, 0);
  331. fprintf(fp, "%s{\n", print_state->need_sep ? ",\n" : "");
  332. print_state->need_sep = true;
  333. if (pmu_name) {
  334. fix_escape_fprintf(fp, &buf, "\t\"Unit\": \"%S\"", pmu_name);
  335. need_sep = true;
  336. }
  337. if (topic) {
  338. fix_escape_fprintf(fp, &buf, "%s\t\"Topic\": \"%S\"",
  339. need_sep ? ",\n" : "",
  340. topic);
  341. need_sep = true;
  342. }
  343. if (event_name) {
  344. fix_escape_fprintf(fp, &buf, "%s\t\"EventName\": \"%S\"",
  345. need_sep ? ",\n" : "",
  346. event_name);
  347. need_sep = true;
  348. }
  349. if (event_alias && strlen(event_alias)) {
  350. fix_escape_fprintf(fp, &buf, "%s\t\"EventAlias\": \"%S\"",
  351. need_sep ? ",\n" : "",
  352. event_alias);
  353. need_sep = true;
  354. }
  355. if (scale_unit && strlen(scale_unit)) {
  356. fix_escape_fprintf(fp, &buf, "%s\t\"ScaleUnit\": \"%S\"",
  357. need_sep ? ",\n" : "",
  358. scale_unit);
  359. need_sep = true;
  360. }
  361. if (event_type_desc) {
  362. fix_escape_fprintf(fp, &buf, "%s\t\"EventType\": \"%S\"",
  363. need_sep ? ",\n" : "",
  364. event_type_desc);
  365. need_sep = true;
  366. }
  367. if (deprecated) {
  368. fix_escape_fprintf(fp, &buf, "%s\t\"Deprecated\": \"%S\"",
  369. need_sep ? ",\n" : "",
  370. deprecated ? "1" : "0");
  371. need_sep = true;
  372. }
  373. if (desc) {
  374. fix_escape_fprintf(fp, &buf, "%s\t\"BriefDescription\": \"%S\"",
  375. need_sep ? ",\n" : "",
  376. desc);
  377. need_sep = true;
  378. }
  379. if (long_desc) {
  380. fix_escape_fprintf(fp, &buf, "%s\t\"PublicDescription\": \"%S\"",
  381. need_sep ? ",\n" : "",
  382. long_desc);
  383. need_sep = true;
  384. }
  385. if (encoding_desc) {
  386. fix_escape_fprintf(fp, &buf, "%s\t\"Encoding\": \"%S\"",
  387. need_sep ? ",\n" : "",
  388. encoding_desc);
  389. need_sep = true;
  390. }
  391. fprintf(fp, "%s}", need_sep ? "\n" : "");
  392. strbuf_release(&buf);
  393. }
  394. static void json_print_metric(void *ps __maybe_unused, const char *group,
  395. const char *name, const char *desc,
  396. const char *long_desc, const char *expr,
  397. const char *threshold, const char *unit)
  398. {
  399. struct json_print_state *print_state = ps;
  400. bool need_sep = false;
  401. FILE *fp = print_state->fp;
  402. struct strbuf buf;
  403. strbuf_init(&buf, 0);
  404. fprintf(fp, "%s{\n", print_state->need_sep ? ",\n" : "");
  405. print_state->need_sep = true;
  406. if (group) {
  407. fix_escape_fprintf(fp, &buf, "\t\"MetricGroup\": \"%S\"", group);
  408. need_sep = true;
  409. }
  410. if (name) {
  411. fix_escape_fprintf(fp, &buf, "%s\t\"MetricName\": \"%S\"",
  412. need_sep ? ",\n" : "",
  413. name);
  414. need_sep = true;
  415. }
  416. if (expr) {
  417. fix_escape_fprintf(fp, &buf, "%s\t\"MetricExpr\": \"%S\"",
  418. need_sep ? ",\n" : "",
  419. expr);
  420. need_sep = true;
  421. }
  422. if (threshold) {
  423. fix_escape_fprintf(fp, &buf, "%s\t\"MetricThreshold\": \"%S\"",
  424. need_sep ? ",\n" : "",
  425. threshold);
  426. need_sep = true;
  427. }
  428. if (unit) {
  429. fix_escape_fprintf(fp, &buf, "%s\t\"ScaleUnit\": \"%S\"",
  430. need_sep ? ",\n" : "",
  431. unit);
  432. need_sep = true;
  433. }
  434. if (desc) {
  435. fix_escape_fprintf(fp, &buf, "%s\t\"BriefDescription\": \"%S\"",
  436. need_sep ? ",\n" : "",
  437. desc);
  438. need_sep = true;
  439. }
  440. if (long_desc) {
  441. fix_escape_fprintf(fp, &buf, "%s\t\"PublicDescription\": \"%S\"",
  442. need_sep ? ",\n" : "",
  443. long_desc);
  444. need_sep = true;
  445. }
  446. fprintf(fp, "%s}", need_sep ? "\n" : "");
  447. strbuf_release(&buf);
  448. }
  449. static bool json_skip_duplicate_pmus(void *ps __maybe_unused)
  450. {
  451. return false;
  452. }
  453. static bool default_skip_duplicate_pmus(void *ps)
  454. {
  455. struct print_state *print_state = ps;
  456. return !print_state->long_desc;
  457. }
  458. int cmd_list(int argc, const char **argv)
  459. {
  460. int i, ret = 0;
  461. struct print_state default_ps = {
  462. .fp = stdout,
  463. .desc = true,
  464. };
  465. struct print_state json_ps = {
  466. .fp = stdout,
  467. };
  468. void *ps = &default_ps;
  469. struct print_callbacks print_cb = {
  470. .print_start = default_print_start,
  471. .print_end = default_print_end,
  472. .print_event = default_print_event,
  473. .print_metric = default_print_metric,
  474. .skip_duplicate_pmus = default_skip_duplicate_pmus,
  475. };
  476. const char *cputype = NULL;
  477. const char *unit_name = NULL;
  478. const char *output_path = NULL;
  479. bool json = false;
  480. struct option list_options[] = {
  481. OPT_BOOLEAN(0, "raw-dump", &default_ps.name_only, "Dump raw events"),
  482. OPT_BOOLEAN('j', "json", &json, "JSON encode events and metrics"),
  483. OPT_BOOLEAN('d', "desc", &default_ps.desc,
  484. "Print extra event descriptions. --no-desc to not print."),
  485. OPT_BOOLEAN('v', "long-desc", &default_ps.long_desc,
  486. "Print longer event descriptions."),
  487. OPT_BOOLEAN(0, "details", &default_ps.detailed,
  488. "Print information on the perf event names and expressions used internally by events."),
  489. OPT_STRING('o', "output", &output_path, "file", "output file name"),
  490. OPT_BOOLEAN(0, "deprecated", &default_ps.deprecated,
  491. "Print deprecated events."),
  492. OPT_STRING(0, "cputype", &cputype, "cpu type",
  493. "Limit PMU or metric printing to the given PMU (e.g. cpu, core or atom)."),
  494. OPT_STRING(0, "unit", &unit_name, "PMU name",
  495. "Limit PMU or metric printing to the specified PMU."),
  496. OPT_INCR(0, "debug", &verbose,
  497. "Enable debugging output"),
  498. OPT_END()
  499. };
  500. const char * const list_usage[] = {
  501. #ifdef HAVE_LIBPFM
  502. "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob|pfm]",
  503. #else
  504. "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob]",
  505. #endif
  506. NULL
  507. };
  508. set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
  509. /* Hide hybrid flag for the more generic 'unit' flag. */
  510. set_option_flag(list_options, 0, "cputype", PARSE_OPT_HIDDEN);
  511. argc = parse_options(argc, argv, list_options, list_usage,
  512. PARSE_OPT_STOP_AT_NON_OPTION);
  513. if (output_path) {
  514. default_ps.fp = fopen(output_path, "w");
  515. json_ps.fp = default_ps.fp;
  516. }
  517. setup_pager();
  518. if (!default_ps.name_only)
  519. setup_pager();
  520. if (json) {
  521. print_cb = (struct print_callbacks){
  522. .print_start = json_print_start,
  523. .print_end = json_print_end,
  524. .print_event = json_print_event,
  525. .print_metric = json_print_metric,
  526. .skip_duplicate_pmus = json_skip_duplicate_pmus,
  527. };
  528. ps = &json_ps;
  529. } else {
  530. default_ps.last_topic = strdup("");
  531. assert(default_ps.last_topic);
  532. default_ps.visited_metrics = strlist__new(NULL, NULL);
  533. assert(default_ps.visited_metrics);
  534. if (unit_name)
  535. default_ps.pmu_glob = strdup(unit_name);
  536. else if (cputype) {
  537. const struct perf_pmu *pmu = perf_pmus__pmu_for_pmu_filter(cputype);
  538. if (!pmu) {
  539. pr_err("ERROR: cputype is not supported!\n");
  540. ret = -1;
  541. goto out;
  542. }
  543. default_ps.pmu_glob = strdup(pmu->name);
  544. }
  545. }
  546. print_cb.print_start(ps);
  547. if (argc == 0) {
  548. default_ps.metrics = true;
  549. default_ps.metricgroups = true;
  550. print_events(&print_cb, ps);
  551. goto out;
  552. }
  553. for (i = 0; i < argc; ++i) {
  554. char *sep, *s;
  555. if (strcmp(argv[i], "tracepoint") == 0)
  556. print_tracepoint_events(&print_cb, ps);
  557. else if (strcmp(argv[i], "hw") == 0 ||
  558. strcmp(argv[i], "hardware") == 0)
  559. print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE,
  560. event_symbols_hw, PERF_COUNT_HW_MAX);
  561. else if (strcmp(argv[i], "sw") == 0 ||
  562. strcmp(argv[i], "software") == 0) {
  563. print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE,
  564. event_symbols_sw, PERF_COUNT_SW_MAX);
  565. print_tool_events(&print_cb, ps);
  566. } else if (strcmp(argv[i], "cache") == 0 ||
  567. strcmp(argv[i], "hwcache") == 0)
  568. print_hwcache_events(&print_cb, ps);
  569. else if (strcmp(argv[i], "pmu") == 0)
  570. perf_pmus__print_pmu_events(&print_cb, ps);
  571. else if (strcmp(argv[i], "sdt") == 0)
  572. print_sdt_events(&print_cb, ps);
  573. else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0) {
  574. default_ps.metricgroups = false;
  575. default_ps.metrics = true;
  576. metricgroup__print(&print_cb, ps);
  577. } else if (strcmp(argv[i], "metricgroup") == 0 ||
  578. strcmp(argv[i], "metricgroups") == 0) {
  579. default_ps.metricgroups = true;
  580. default_ps.metrics = false;
  581. metricgroup__print(&print_cb, ps);
  582. }
  583. #ifdef HAVE_LIBPFM
  584. else if (strcmp(argv[i], "pfm") == 0)
  585. print_libpfm_events(&print_cb, ps);
  586. #endif
  587. else if ((sep = strchr(argv[i], ':')) != NULL) {
  588. char *old_pmu_glob = default_ps.pmu_glob;
  589. default_ps.event_glob = strdup(argv[i]);
  590. if (!default_ps.event_glob) {
  591. ret = -1;
  592. goto out;
  593. }
  594. print_tracepoint_events(&print_cb, ps);
  595. print_sdt_events(&print_cb, ps);
  596. default_ps.metrics = true;
  597. default_ps.metricgroups = true;
  598. metricgroup__print(&print_cb, ps);
  599. zfree(&default_ps.event_glob);
  600. default_ps.pmu_glob = old_pmu_glob;
  601. } else {
  602. if (asprintf(&s, "*%s*", argv[i]) < 0) {
  603. printf("Critical: Not enough memory! Trying to continue...\n");
  604. continue;
  605. }
  606. default_ps.event_glob = s;
  607. print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE,
  608. event_symbols_hw, PERF_COUNT_HW_MAX);
  609. print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE,
  610. event_symbols_sw, PERF_COUNT_SW_MAX);
  611. print_tool_events(&print_cb, ps);
  612. print_hwcache_events(&print_cb, ps);
  613. perf_pmus__print_pmu_events(&print_cb, ps);
  614. print_tracepoint_events(&print_cb, ps);
  615. print_sdt_events(&print_cb, ps);
  616. default_ps.metrics = true;
  617. default_ps.metricgroups = true;
  618. metricgroup__print(&print_cb, ps);
  619. free(s);
  620. }
  621. }
  622. out:
  623. print_cb.print_end(ps);
  624. free(default_ps.pmu_glob);
  625. free(default_ps.last_topic);
  626. free(default_ps.last_metricgroups);
  627. strlist__delete(default_ps.visited_metrics);
  628. if (output_path)
  629. fclose(default_ps.fp);
  630. return ret;
  631. }