License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-06-06 10:24:17 +00:00
|
|
|
/*
|
|
|
|
* builtin-list.c
|
|
|
|
*
|
|
|
|
* Builtin list command: list all event types
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Thomas Gleixner <tglx@linutronix.de>
|
|
|
|
* Copyright (C) 2008-2009, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
|
2011-02-17 17:38:58 +00:00
|
|
|
* Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
|
2009-06-06 10:24:17 +00:00
|
|
|
*/
|
|
|
|
#include "builtin.h"
|
|
|
|
|
2022-07-29 20:42:17 +00:00
|
|
|
#include "util/print-events.h"
|
2013-04-20 18:02:29 +00:00
|
|
|
#include "util/pmu.h"
|
2021-09-03 02:52:39 +00:00
|
|
|
#include "util/pmu-hybrid.h"
|
2017-01-28 02:03:40 +00:00
|
|
|
#include "util/debug.h"
|
2017-08-31 19:40:32 +00:00
|
|
|
#include "util/metricgroup.h"
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
#include "util/string2.h"
|
|
|
|
#include "util/strlist.h"
|
2019-08-30 15:52:25 +00:00
|
|
|
#include <subcmd/pager.h>
|
2015-12-15 15:39:39 +00:00
|
|
|
#include <subcmd/parse-options.h>
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
#include <linux/zalloc.h>
|
|
|
|
#include <stdarg.h>
|
2019-08-29 19:18:59 +00:00
|
|
|
#include <stdio.h>
|
2009-06-06 10:24:17 +00:00
|
|
|
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
/**
|
|
|
|
* struct print_state - State and configuration passed to the default_print
|
|
|
|
* functions.
|
|
|
|
*/
|
|
|
|
struct print_state {
|
|
|
|
/**
|
|
|
|
* @pmu_glob: Optionally restrict PMU and metric matching to PMU or
|
|
|
|
* debugfs subsystem name.
|
|
|
|
*/
|
|
|
|
char *pmu_glob;
|
|
|
|
/** @event_glob: Optional pattern matching glob. */
|
|
|
|
char *event_glob;
|
|
|
|
/** @name_only: Print event or metric names only. */
|
|
|
|
bool name_only;
|
|
|
|
/** @desc: Print the event or metric description. */
|
|
|
|
bool desc;
|
|
|
|
/** @long_desc: Print longer event or metric description. */
|
|
|
|
bool long_desc;
|
|
|
|
/** @deprecated: Print deprecated events or metrics. */
|
|
|
|
bool deprecated;
|
|
|
|
/**
|
|
|
|
* @detailed: Print extra information on the perf event such as names
|
|
|
|
* and expressions used internally by events.
|
|
|
|
*/
|
|
|
|
bool detailed;
|
|
|
|
/** @metrics: Controls printing of metric and metric groups. */
|
|
|
|
bool metrics;
|
|
|
|
/** @metricgroups: Controls printing of metric and metric groups. */
|
|
|
|
bool metricgroups;
|
|
|
|
/** @last_topic: The last printed event topic. */
|
|
|
|
char *last_topic;
|
|
|
|
/** @last_metricgroups: The last printed metric group. */
|
|
|
|
char *last_metricgroups;
|
|
|
|
/** @visited_metrics: Metrics that are printed to avoid duplicates. */
|
|
|
|
struct strlist *visited_metrics;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void default_print_start(void *ps)
|
|
|
|
{
|
|
|
|
struct print_state *print_state = ps;
|
|
|
|
|
|
|
|
if (!print_state->name_only && pager_in_use())
|
|
|
|
printf("\nList of pre-defined events (to be used in -e or -M):\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void default_print_end(void *print_state __maybe_unused) {}
|
|
|
|
|
|
|
|
static void wordwrap(const char *s, int start, int max, int corr)
|
|
|
|
{
|
|
|
|
int column = start;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
while (*s) {
|
|
|
|
int wlen = strcspn(s, " \t");
|
|
|
|
|
|
|
|
if (column + wlen >= max && column > start) {
|
|
|
|
printf("\n%*s", start, "");
|
|
|
|
column = start + corr;
|
|
|
|
}
|
|
|
|
n = printf("%s%.*s", column > start ? " " : "", wlen, s);
|
|
|
|
if (n <= 0)
|
|
|
|
break;
|
|
|
|
s += wlen;
|
|
|
|
column += n;
|
|
|
|
s = skip_spaces(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void default_print_event(void *ps, const char *pmu_name, const char *topic,
|
|
|
|
const char *event_name, const char *event_alias,
|
|
|
|
const char *scale_unit __maybe_unused,
|
|
|
|
bool deprecated, const char *event_type_desc,
|
|
|
|
const char *desc, const char *long_desc,
|
|
|
|
const char *encoding_desc,
|
|
|
|
const char *metric_name, const char *metric_expr)
|
|
|
|
{
|
|
|
|
struct print_state *print_state = ps;
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
if (deprecated && !print_state->deprecated)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (print_state->pmu_glob && pmu_name && !strglobmatch(pmu_name, print_state->pmu_glob))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (print_state->event_glob &&
|
|
|
|
(!event_name || !strglobmatch(event_name, print_state->event_glob)) &&
|
|
|
|
(!event_alias || !strglobmatch(event_alias, print_state->event_glob)) &&
|
|
|
|
(!topic || !strglobmatch_nocase(topic, print_state->event_glob)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (print_state->name_only) {
|
|
|
|
if (event_alias && strlen(event_alias))
|
|
|
|
printf("%s ", event_alias);
|
|
|
|
else
|
|
|
|
printf("%s ", event_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(print_state->last_topic, topic ?: "")) {
|
|
|
|
if (topic)
|
|
|
|
printf("\n%s:\n", topic);
|
|
|
|
free(print_state->last_topic);
|
|
|
|
print_state->last_topic = strdup(topic ?: "");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event_alias && strlen(event_alias))
|
|
|
|
pos = printf(" %s OR %s", event_name, event_alias);
|
|
|
|
else
|
|
|
|
pos = printf(" %s", event_name);
|
|
|
|
|
|
|
|
if (!topic && event_type_desc) {
|
|
|
|
for (; pos < 53; pos++)
|
|
|
|
putchar(' ');
|
|
|
|
printf("[%s]\n", event_type_desc);
|
|
|
|
} else
|
|
|
|
putchar('\n');
|
|
|
|
|
|
|
|
if (desc && print_state->desc) {
|
|
|
|
printf("%*s", 8, "[");
|
|
|
|
wordwrap(desc, 8, pager_get_columns(), 0);
|
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (long_desc && print_state->long_desc) {
|
|
|
|
printf("%*s", 8, "[");
|
|
|
|
wordwrap(long_desc, 8, pager_get_columns(), 0);
|
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (print_state->detailed && encoding_desc) {
|
|
|
|
printf("%*s%s", 8, "", encoding_desc);
|
|
|
|
if (metric_name)
|
|
|
|
printf(" MetricName: %s", metric_name);
|
|
|
|
if (metric_expr)
|
|
|
|
printf(" MetricExpr: %s", metric_expr);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void default_print_metric(void *ps,
|
|
|
|
const char *group,
|
|
|
|
const char *name,
|
|
|
|
const char *desc,
|
|
|
|
const char *long_desc,
|
|
|
|
const char *expr,
|
|
|
|
const char *unit __maybe_unused)
|
|
|
|
{
|
|
|
|
struct print_state *print_state = ps;
|
|
|
|
|
|
|
|
if (print_state->event_glob &&
|
|
|
|
(!print_state->metrics || !name || !strglobmatch(name, print_state->event_glob)) &&
|
|
|
|
(!print_state->metricgroups || !group || !strglobmatch(group, print_state->event_glob)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!print_state->name_only && !print_state->last_metricgroups) {
|
|
|
|
if (print_state->metricgroups) {
|
|
|
|
printf("\nMetric Groups:\n");
|
|
|
|
if (!print_state->metrics)
|
|
|
|
putchar('\n');
|
|
|
|
} else {
|
|
|
|
printf("\nMetrics:\n\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!print_state->last_metricgroups ||
|
|
|
|
strcmp(print_state->last_metricgroups, group ?: "")) {
|
|
|
|
if (group && print_state->metricgroups) {
|
|
|
|
if (print_state->name_only)
|
|
|
|
printf("%s ", group);
|
|
|
|
else if (print_state->metrics)
|
|
|
|
printf("\n%s:\n", group);
|
|
|
|
else
|
|
|
|
printf("%s\n", group);
|
|
|
|
}
|
|
|
|
free(print_state->last_metricgroups);
|
|
|
|
print_state->last_metricgroups = strdup(group ?: "");
|
|
|
|
}
|
|
|
|
if (!print_state->metrics)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (print_state->name_only) {
|
|
|
|
if (print_state->metrics &&
|
|
|
|
!strlist__has_entry(print_state->visited_metrics, name)) {
|
|
|
|
printf("%s ", name);
|
|
|
|
strlist__add(print_state->visited_metrics, name);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf(" %s\n", name);
|
|
|
|
|
|
|
|
if (desc && print_state->desc) {
|
|
|
|
printf("%*s", 8, "[");
|
|
|
|
wordwrap(desc, 8, pager_get_columns(), 0);
|
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
if (long_desc && print_state->long_desc) {
|
|
|
|
printf("%*s", 8, "[");
|
|
|
|
wordwrap(long_desc, 8, pager_get_columns(), 0);
|
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
if (expr && print_state->detailed) {
|
|
|
|
printf("%*s", 8, "[");
|
|
|
|
wordwrap(expr, 8, pager_get_columns(), 0);
|
|
|
|
printf("]\n");
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 22:24:45 +00:00
|
|
|
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
struct json_print_state {
|
|
|
|
/** Should a separator be printed prior to the next item? */
|
|
|
|
bool need_sep;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void json_print_start(void *print_state __maybe_unused)
|
|
|
|
{
|
|
|
|
printf("[\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void json_print_end(void *ps)
|
|
|
|
{
|
|
|
|
struct json_print_state *print_state = ps;
|
|
|
|
|
|
|
|
printf("%s]\n", print_state->need_sep ? "\n" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fix_escape_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buf[2048];
|
|
|
|
size_t buf_pos = 0;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
for (size_t fmt_pos = 0; fmt_pos < strlen(fmt); fmt_pos++) {
|
|
|
|
switch (fmt[fmt_pos]) {
|
|
|
|
case '%': {
|
|
|
|
const char *s = va_arg(args, const char*);
|
|
|
|
|
|
|
|
fmt_pos++;
|
|
|
|
assert(fmt[fmt_pos] == 's');
|
|
|
|
for (size_t s_pos = 0; s_pos < strlen(s); s_pos++) {
|
|
|
|
switch (s[s_pos]) {
|
|
|
|
case '\\':
|
|
|
|
__fallthrough;
|
|
|
|
case '\"':
|
|
|
|
buf[buf_pos++] = '\\';
|
|
|
|
assert(buf_pos < sizeof(buf));
|
|
|
|
__fallthrough;
|
|
|
|
default:
|
|
|
|
buf[buf_pos++] = s[s_pos];
|
|
|
|
assert(buf_pos < sizeof(buf));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
buf[buf_pos++] = fmt[fmt_pos];
|
|
|
|
assert(buf_pos < sizeof(buf));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
buf[buf_pos] = '\0';
|
|
|
|
fputs(buf, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void json_print_event(void *ps, const char *pmu_name, const char *topic,
|
|
|
|
const char *event_name, const char *event_alias,
|
|
|
|
const char *scale_unit,
|
|
|
|
bool deprecated, const char *event_type_desc,
|
|
|
|
const char *desc, const char *long_desc,
|
|
|
|
const char *encoding_desc,
|
|
|
|
const char *metric_name, const char *metric_expr)
|
|
|
|
{
|
|
|
|
struct json_print_state *print_state = ps;
|
|
|
|
bool need_sep = false;
|
|
|
|
|
|
|
|
printf("%s{\n", print_state->need_sep ? ",\n" : "");
|
|
|
|
print_state->need_sep = true;
|
|
|
|
if (pmu_name) {
|
|
|
|
fix_escape_printf("\t\"Unit\": \"%s\"", pmu_name);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (topic) {
|
|
|
|
fix_escape_printf("%s\t\"Topic\": \"%s\"", need_sep ? ",\n" : "", topic);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (event_name) {
|
|
|
|
fix_escape_printf("%s\t\"EventName\": \"%s\"", need_sep ? ",\n" : "", event_name);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (event_alias && strlen(event_alias)) {
|
|
|
|
fix_escape_printf("%s\t\"EventAlias\": \"%s\"", need_sep ? ",\n" : "", event_alias);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (scale_unit && strlen(scale_unit)) {
|
|
|
|
fix_escape_printf("%s\t\"ScaleUnit\": \"%s\"", need_sep ? ",\n" : "",
|
|
|
|
scale_unit);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (event_type_desc) {
|
|
|
|
fix_escape_printf("%s\t\"EventType\": \"%s\"", need_sep ? ",\n" : "",
|
|
|
|
event_type_desc);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (deprecated) {
|
|
|
|
fix_escape_printf("%s\t\"Deprecated\": \"%s\"", need_sep ? ",\n" : "",
|
|
|
|
deprecated ? "1" : "0");
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (desc) {
|
|
|
|
fix_escape_printf("%s\t\"BriefDescription\": \"%s\"", need_sep ? ",\n" : "", desc);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (long_desc) {
|
|
|
|
fix_escape_printf("%s\t\"PublicDescription\": \"%s\"", need_sep ? ",\n" : "",
|
|
|
|
long_desc);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (encoding_desc) {
|
|
|
|
fix_escape_printf("%s\t\"Encoding\": \"%s\"", need_sep ? ",\n" : "", encoding_desc);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (metric_name) {
|
|
|
|
fix_escape_printf("%s\t\"MetricName\": \"%s\"", need_sep ? ",\n" : "", metric_name);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (metric_expr) {
|
|
|
|
fix_escape_printf("%s\t\"MetricExpr\": \"%s\"", need_sep ? ",\n" : "", metric_expr);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
printf("%s}", need_sep ? "\n" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void json_print_metric(void *ps __maybe_unused, const char *group,
|
|
|
|
const char *name, const char *desc,
|
|
|
|
const char *long_desc, const char *expr,
|
|
|
|
const char *unit)
|
|
|
|
{
|
|
|
|
struct json_print_state *print_state = ps;
|
|
|
|
bool need_sep = false;
|
|
|
|
|
|
|
|
printf("%s{\n", print_state->need_sep ? ",\n" : "");
|
|
|
|
print_state->need_sep = true;
|
|
|
|
if (group) {
|
|
|
|
fix_escape_printf("\t\"MetricGroup\": \"%s\"", group);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (name) {
|
|
|
|
fix_escape_printf("%s\t\"MetricName\": \"%s\"", need_sep ? ",\n" : "", name);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (expr) {
|
|
|
|
fix_escape_printf("%s\t\"MetricExpr\": \"%s\"", need_sep ? ",\n" : "", expr);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (unit) {
|
|
|
|
fix_escape_printf("%s\t\"ScaleUnit\": \"%s\"", need_sep ? ",\n" : "", unit);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (desc) {
|
|
|
|
fix_escape_printf("%s\t\"BriefDescription\": \"%s\"", need_sep ? ",\n" : "", desc);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (long_desc) {
|
|
|
|
fix_escape_printf("%s\t\"PublicDescription\": \"%s\"", need_sep ? ",\n" : "",
|
|
|
|
long_desc);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
printf("%s}", need_sep ? "\n" : "");
|
|
|
|
}
|
|
|
|
|
2017-03-27 14:47:20 +00:00
|
|
|
int cmd_list(int argc, const char **argv)
|
2009-06-06 10:24:17 +00:00
|
|
|
{
|
2021-09-03 02:52:39 +00:00
|
|
|
int i, ret = 0;
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
struct print_state default_ps = {};
|
|
|
|
struct print_state json_ps = {};
|
|
|
|
void *ps = &default_ps;
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
struct print_callbacks print_cb = {
|
|
|
|
.print_start = default_print_start,
|
|
|
|
.print_end = default_print_end,
|
|
|
|
.print_event = default_print_event,
|
|
|
|
.print_metric = default_print_metric,
|
|
|
|
};
|
2022-11-14 21:07:18 +00:00
|
|
|
const char *hybrid_name = NULL;
|
|
|
|
const char *unit_name = NULL;
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
bool json = false;
|
2014-12-31 03:36:55 +00:00
|
|
|
struct option list_options[] = {
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
OPT_BOOLEAN(0, "raw-dump", &default_ps.name_only, "Dump raw events"),
|
|
|
|
OPT_BOOLEAN('j', "json", &json, "JSON encode events and metrics"),
|
|
|
|
OPT_BOOLEAN('d', "desc", &default_ps.desc,
|
2016-09-15 22:24:45 +00:00
|
|
|
"Print extra event descriptions. --no-desc to not print."),
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
OPT_BOOLEAN('v', "long-desc", &default_ps.long_desc,
|
2016-09-15 22:24:48 +00:00
|
|
|
"Print longer event descriptions."),
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
OPT_BOOLEAN(0, "details", &default_ps.detailed,
|
2017-03-20 20:17:11 +00:00
|
|
|
"Print information on the perf event names and expressions used internally by events."),
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
OPT_BOOLEAN(0, "deprecated", &default_ps.deprecated,
|
2019-10-15 02:53:57 +00:00
|
|
|
"Print deprecated events."),
|
2022-11-14 21:07:18 +00:00
|
|
|
OPT_STRING(0, "cputype", &hybrid_name, "hybrid cpu type",
|
|
|
|
"Limit PMU or metric printing to the given hybrid PMU (e.g. core or atom)."),
|
|
|
|
OPT_STRING(0, "unit", &unit_name, "PMU name",
|
|
|
|
"Limit PMU or metric printing to the specified PMU."),
|
2017-01-28 02:03:40 +00:00
|
|
|
OPT_INCR(0, "debug", &verbose,
|
|
|
|
"Enable debugging output"),
|
2013-10-30 16:28:29 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char * const list_usage[] = {
|
2020-05-22 06:45:46 +00:00
|
|
|
"perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob]",
|
2013-10-30 16:28:29 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2014-12-31 03:36:55 +00:00
|
|
|
set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
|
2022-11-14 21:07:18 +00:00
|
|
|
/* Hide hybrid flag for the more generic 'unit' flag. */
|
|
|
|
set_option_flag(list_options, 0, "cputype", PARSE_OPT_HIDDEN);
|
2014-12-31 03:36:55 +00:00
|
|
|
|
2013-10-30 16:28:29 +00:00
|
|
|
argc = parse_options(argc, argv, list_options, list_usage,
|
|
|
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
2013-10-30 16:15:06 +00:00
|
|
|
|
2009-08-12 17:44:59 +00:00
|
|
|
setup_pager();
|
2011-02-17 17:38:58 +00:00
|
|
|
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
if (!default_ps.name_only)
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
setup_pager();
|
2015-02-13 13:11:55 +00:00
|
|
|
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
if (json) {
|
|
|
|
print_cb = (struct print_callbacks){
|
|
|
|
.print_start = json_print_start,
|
|
|
|
.print_end = json_print_end,
|
|
|
|
.print_event = json_print_event,
|
|
|
|
.print_metric = json_print_metric,
|
|
|
|
};
|
|
|
|
ps = &json_ps;
|
|
|
|
} else {
|
|
|
|
default_ps.desc = !default_ps.long_desc;
|
|
|
|
default_ps.last_topic = strdup("");
|
|
|
|
assert(default_ps.last_topic);
|
|
|
|
default_ps.visited_metrics = strlist__new(NULL, NULL);
|
|
|
|
assert(default_ps.visited_metrics);
|
|
|
|
if (unit_name)
|
|
|
|
default_ps.pmu_glob = strdup(unit_name);
|
|
|
|
else if (hybrid_name) {
|
|
|
|
default_ps.pmu_glob = perf_pmu__hybrid_type_to_pmu(hybrid_name);
|
|
|
|
if (!default_ps.pmu_glob)
|
|
|
|
pr_warning("WARNING: hybrid cputype is not supported!\n");
|
|
|
|
}
|
2021-09-03 02:52:39 +00:00
|
|
|
}
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_cb.print_start(ps);
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
|
2013-10-30 16:28:29 +00:00
|
|
|
if (argc == 0) {
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
default_ps.metrics = true;
|
|
|
|
default_ps.metricgroups = true;
|
|
|
|
print_events(&print_cb, ps);
|
2021-09-03 02:52:39 +00:00
|
|
|
goto out;
|
2013-10-30 16:15:06 +00:00
|
|
|
}
|
2011-02-17 17:38:58 +00:00
|
|
|
|
2013-10-30 16:28:29 +00:00
|
|
|
for (i = 0; i < argc; ++i) {
|
2015-10-01 15:12:22 +00:00
|
|
|
char *sep, *s;
|
|
|
|
|
2015-02-27 10:21:26 +00:00
|
|
|
if (strcmp(argv[i], "tracepoint") == 0)
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_tracepoint_events(&print_cb, ps);
|
2013-10-30 16:15:06 +00:00
|
|
|
else if (strcmp(argv[i], "hw") == 0 ||
|
|
|
|
strcmp(argv[i], "hardware") == 0)
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE,
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
event_symbols_hw, PERF_COUNT_HW_MAX);
|
2013-10-30 16:15:06 +00:00
|
|
|
else if (strcmp(argv[i], "sw") == 0 ||
|
2019-03-26 22:18:23 +00:00
|
|
|
strcmp(argv[i], "software") == 0) {
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE,
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
event_symbols_sw, PERF_COUNT_SW_MAX);
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_tool_events(&print_cb, ps);
|
2019-03-26 22:18:23 +00:00
|
|
|
} else if (strcmp(argv[i], "cache") == 0 ||
|
2013-10-30 16:15:06 +00:00
|
|
|
strcmp(argv[i], "hwcache") == 0)
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_hwcache_events(&print_cb, ps);
|
2013-10-30 16:15:06 +00:00
|
|
|
else if (strcmp(argv[i], "pmu") == 0)
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_pmu_events(&print_cb, ps);
|
2016-06-24 09:06:46 +00:00
|
|
|
else if (strcmp(argv[i], "sdt") == 0)
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_sdt_events(&print_cb, ps);
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0) {
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
default_ps.metricgroups = false;
|
|
|
|
default_ps.metrics = true;
|
|
|
|
metricgroup__print(&print_cb, ps);
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
} else if (strcmp(argv[i], "metricgroup") == 0 ||
|
|
|
|
strcmp(argv[i], "metricgroups") == 0) {
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
default_ps.metricgroups = true;
|
|
|
|
default_ps.metrics = false;
|
|
|
|
metricgroup__print(&print_cb, ps);
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
} else if ((sep = strchr(argv[i], ':')) != NULL) {
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
char *old_pmu_glob = default_ps.pmu_glob;
|
2011-02-17 17:38:58 +00:00
|
|
|
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
default_ps.event_glob = strdup(argv[i]);
|
|
|
|
if (!default_ps.event_glob) {
|
2021-09-03 02:52:39 +00:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-10-30 16:15:06 +00:00
|
|
|
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_tracepoint_events(&print_cb, ps);
|
|
|
|
print_sdt_events(&print_cb, ps);
|
|
|
|
default_ps.metrics = true;
|
|
|
|
default_ps.metricgroups = true;
|
|
|
|
metricgroup__print(&print_cb, ps);
|
|
|
|
zfree(&default_ps.event_glob);
|
|
|
|
default_ps.pmu_glob = old_pmu_glob;
|
2015-10-01 15:12:22 +00:00
|
|
|
} else {
|
|
|
|
if (asprintf(&s, "*%s*", argv[i]) < 0) {
|
|
|
|
printf("Critical: Not enough memory! Trying to continue...\n");
|
|
|
|
continue;
|
|
|
|
}
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
default_ps.event_glob = s;
|
|
|
|
print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE,
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
event_symbols_hw, PERF_COUNT_HW_MAX);
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE,
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-14 21:07:22 +00:00
|
|
|
event_symbols_sw, PERF_COUNT_SW_MAX);
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_tool_events(&print_cb, ps);
|
|
|
|
print_hwcache_events(&print_cb, ps);
|
|
|
|
print_pmu_events(&print_cb, ps);
|
|
|
|
print_tracepoint_events(&print_cb, ps);
|
|
|
|
print_sdt_events(&print_cb, ps);
|
|
|
|
default_ps.metrics = true;
|
|
|
|
default_ps.metricgroups = true;
|
|
|
|
metricgroup__print(&print_cb, ps);
|
2015-10-01 15:12:22 +00:00
|
|
|
free(s);
|
2011-02-17 17:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-03 02:52:39 +00:00
|
|
|
|
|
|
|
out:
|
perf list: Add JSON output option
Output events and metrics in a JSON format by overriding the print
callbacks. Currently other command line options aren't supported and
metrics are repeated once per metric group.
Committer testing:
$ perf list cache
List of pre-defined events (to be used in -e or -M):
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-loads [Hardware cache event]
iTLB-load-misses [Hardware cache event]
iTLB-loads [Hardware cache event]
$ perf list --json cache
[
{
"Unit": "cache",
"EventName": "L1-dcache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-dcache-prefetches",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "L1-icache-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "branch-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "dTLB-loads",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-load-misses",
"EventType": "Hardware cache event"
},
{
"Unit": "cache",
"EventName": "iTLB-loads",
"EventType": "Hardware cache event"
}
]
$
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-17 16:43:37 +00:00
|
|
|
print_cb.print_end(ps);
|
|
|
|
free(default_ps.pmu_glob);
|
|
|
|
free(default_ps.last_topic);
|
|
|
|
free(default_ps.last_metricgroups);
|
|
|
|
strlist__delete(default_ps.visited_metrics);
|
2021-09-03 02:52:39 +00:00
|
|
|
return ret;
|
2009-06-06 10:24:17 +00:00
|
|
|
}
|