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"
|
2023-05-02 22:38:37 +00:00
|
|
|
#include "util/pmus.h"
|
2013-04-20 18:02:29 +00:00
|
|
|
#include "util/pmu.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"
|
2023-06-08 23:23:59 +00:00
|
|
|
#include "util/pfm.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"
|
2022-11-18 02:46:06 +00:00
|
|
|
#include "util/strbuf.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;
|
2022-11-18 02:46:05 +00:00
|
|
|
bool saw_newline = false;
|
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
|
|
|
|
|
|
|
while (*s) {
|
2022-11-18 02:46:05 +00:00
|
|
|
int wlen = strcspn(s, " \t\n");
|
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
|
|
|
|
2022-11-18 02:46:05 +00:00
|
|
|
if ((column + wlen >= max && column > start) || saw_newline) {
|
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
|
|
|
printf("\n%*s", start, "");
|
|
|
|
column = start + corr;
|
|
|
|
}
|
|
|
|
n = printf("%s%.*s", column > start ? " " : "", wlen, s);
|
|
|
|
if (n <= 0)
|
|
|
|
break;
|
2022-11-18 02:46:05 +00:00
|
|
|
saw_newline = s[wlen] == '\n';
|
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
|
|
|
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,
|
perf pmu-events: Remove now unused event and metric variables
Previous changes separated the uses of pmu_event and pmu_metric,
however, both structures contained all the variables of event and
metric. This change removes the event variables from metric and the
metric variables from event.
Note, this change removes the setting of evsel's metric_name/expr as
these fields are no longer part of struct pmu_event. The metric
remains but is no longer implicitly requested when the event is. This
impacts a few Intel uncore events, however, as the ScaleUnit is shared
by the event and the metric this utility is questionable. Also the
MetricNames look broken (contain spaces) in some cases and when trying
to use the functionality with '-e' the metrics fail but regular
metrics with '-M' work. For example, on SkylakeX '-M' works:
```
$ perf stat -M LLC_MISSES.PCIE_WRITE -a sleep 1
Performance counter stats for 'system wide':
0 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 # 57896.0 Bytes LLC_MISSES.PCIE_WRITE (49.84%)
7,174 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 (49.85%)
0 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 (50.16%)
63 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 (50.15%)
1.004576381 seconds time elapsed
```
whilst the event '-e' version is broken even with --group/-g (fwiw, we should also remove -g [1]):
```
$ perf stat -g -e LLC_MISSES.PCIE_WRITE -g -a sleep 1
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Performance counter stats for 'system wide':
27,316 Bytes LLC_MISSES.PCIE_WRITE
1.004505469 seconds time elapsed
```
The code also carries warnings where the user is supposed to select
events for metrics [2] but given the lack of use of such a feature,
let's clean the code and just remove.
[1] https://lore.kernel.org/lkml/20220707195610.303254-1-irogers@google.com/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/stat-shadow.c?id=01b8957b738f42f96a130079bc951b3cc78c5b8a#n425
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
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: Florian Fischer <florian.fischer@muhq.space>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
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: Will Deacon <will@kernel.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linuxppc-dev@lists.ozlabs.org
Link: https://lore.kernel.org/r/20230126233645.200509-7-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-01-26 23:36:36 +00:00
|
|
|
const char *encoding_desc)
|
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 *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);
|
2023-04-12 12:50:08 +00:00
|
|
|
zfree(&print_state->last_topic);
|
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
|
|
|
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) {
|
2023-08-24 18:32:12 +00:00
|
|
|
char *desc_with_unit = NULL;
|
|
|
|
int desc_len = -1;
|
|
|
|
|
2023-08-31 07:14:19 +00:00
|
|
|
if (pmu_name && strcmp(pmu_name, "default_core")) {
|
2023-08-24 18:32:12 +00:00
|
|
|
desc_len = strlen(desc);
|
|
|
|
desc_len = asprintf(&desc_with_unit,
|
|
|
|
desc[desc_len - 1] != '.'
|
|
|
|
? "%s. Unit: %s" : "%s Unit: %s",
|
|
|
|
desc, pmu_name);
|
|
|
|
}
|
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
|
|
|
printf("%*s", 8, "[");
|
2023-08-24 18:32:12 +00:00
|
|
|
wordwrap(desc_len > 0 ? desc_with_unit : desc, 8, pager_get_columns(), 0);
|
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
|
|
|
printf("]\n");
|
2023-08-24 18:32:12 +00:00
|
|
|
free(desc_with_unit);
|
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
|
|
|
}
|
2022-11-18 02:46:05 +00:00
|
|
|
long_desc = long_desc ?: desc;
|
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
|
|
|
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) {
|
2022-11-18 02:46:05 +00:00
|
|
|
printf("%*s", 8, "");
|
|
|
|
wordwrap(encoding_desc, 8, pager_get_columns(), 0);
|
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
|
|
|
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,
|
2023-02-19 09:28:32 +00:00
|
|
|
const char *threshold,
|
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
|
|
|
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);
|
2023-05-17 17:38:03 +00:00
|
|
|
else if (print_state->metrics) {
|
|
|
|
const char *gdesc = describe_metricgroup(group);
|
|
|
|
|
|
|
|
if (gdesc)
|
|
|
|
printf("\n%s: [%s]\n", group, gdesc);
|
|
|
|
else
|
|
|
|
printf("\n%s:\n", group);
|
|
|
|
} else
|
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
|
|
|
printf("%s\n", group);
|
|
|
|
}
|
2023-04-12 12:50:08 +00:00
|
|
|
zfree(&print_state->last_metricgroups);
|
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
|
|
|
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");
|
|
|
|
}
|
2023-02-19 09:28:32 +00:00
|
|
|
if (threshold && print_state->detailed) {
|
|
|
|
printf("%*s", 8, "[");
|
|
|
|
wordwrap(threshold, 8, pager_get_columns(), 0);
|
|
|
|
printf("]\n");
|
|
|
|
}
|
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
|
|
|
}
|
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" : "");
|
|
|
|
}
|
|
|
|
|
2022-11-18 02:46:06 +00:00
|
|
|
static void fix_escape_printf(struct strbuf *buf, const char *fmt, ...)
|
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
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2022-11-18 02:46:06 +00:00
|
|
|
strbuf_setlen(buf, 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
|
|
|
for (size_t fmt_pos = 0; fmt_pos < strlen(fmt); fmt_pos++) {
|
|
|
|
switch (fmt[fmt_pos]) {
|
2022-11-18 02:46:06 +00:00
|
|
|
case '%':
|
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
|
|
|
fmt_pos++;
|
2022-11-18 02:46:06 +00:00
|
|
|
switch (fmt[fmt_pos]) {
|
|
|
|
case 's': {
|
|
|
|
const char *s = va_arg(args, const char*);
|
|
|
|
|
|
|
|
strbuf_addstr(buf, s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'S': {
|
|
|
|
const char *s = va_arg(args, const char*);
|
|
|
|
|
|
|
|
for (size_t s_pos = 0; s_pos < strlen(s); s_pos++) {
|
|
|
|
switch (s[s_pos]) {
|
|
|
|
case '\n':
|
|
|
|
strbuf_addstr(buf, "\\n");
|
|
|
|
break;
|
|
|
|
case '\\':
|
2022-11-25 15:50:16 +00:00
|
|
|
fallthrough;
|
2022-11-18 02:46:06 +00:00
|
|
|
case '\"':
|
|
|
|
strbuf_addch(buf, '\\');
|
2022-11-25 15:50:16 +00:00
|
|
|
fallthrough;
|
2022-11-18 02:46:06 +00:00
|
|
|
default:
|
|
|
|
strbuf_addch(buf, s[s_pos]);
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
}
|
2022-11-18 02:46:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
pr_err("Unexpected format character '%c'\n", fmt[fmt_pos]);
|
|
|
|
strbuf_addch(buf, '%');
|
|
|
|
strbuf_addch(buf, fmt[fmt_pos]);
|
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
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2022-11-18 02:46:06 +00:00
|
|
|
strbuf_addch(buf, fmt[fmt_pos]);
|
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
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(args);
|
2022-11-18 02:46:06 +00:00
|
|
|
fputs(buf->buf, stdout);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
perf pmu-events: Remove now unused event and metric variables
Previous changes separated the uses of pmu_event and pmu_metric,
however, both structures contained all the variables of event and
metric. This change removes the event variables from metric and the
metric variables from event.
Note, this change removes the setting of evsel's metric_name/expr as
these fields are no longer part of struct pmu_event. The metric
remains but is no longer implicitly requested when the event is. This
impacts a few Intel uncore events, however, as the ScaleUnit is shared
by the event and the metric this utility is questionable. Also the
MetricNames look broken (contain spaces) in some cases and when trying
to use the functionality with '-e' the metrics fail but regular
metrics with '-M' work. For example, on SkylakeX '-M' works:
```
$ perf stat -M LLC_MISSES.PCIE_WRITE -a sleep 1
Performance counter stats for 'system wide':
0 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 # 57896.0 Bytes LLC_MISSES.PCIE_WRITE (49.84%)
7,174 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 (49.85%)
0 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 (50.16%)
63 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 (50.15%)
1.004576381 seconds time elapsed
```
whilst the event '-e' version is broken even with --group/-g (fwiw, we should also remove -g [1]):
```
$ perf stat -g -e LLC_MISSES.PCIE_WRITE -g -a sleep 1
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
Performance counter stats for 'system wide':
27,316 Bytes LLC_MISSES.PCIE_WRITE
1.004505469 seconds time elapsed
```
The code also carries warnings where the user is supposed to select
events for metrics [2] but given the lack of use of such a feature,
let's clean the code and just remove.
[1] https://lore.kernel.org/lkml/20220707195610.303254-1-irogers@google.com/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/stat-shadow.c?id=01b8957b738f42f96a130079bc951b3cc78c5b8a#n425
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
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: Florian Fischer <florian.fischer@muhq.space>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
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: Will Deacon <will@kernel.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linuxppc-dev@lists.ozlabs.org
Link: https://lore.kernel.org/r/20230126233645.200509-7-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-01-26 23:36:36 +00:00
|
|
|
const char *encoding_desc)
|
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 *print_state = ps;
|
|
|
|
bool need_sep = false;
|
2022-11-18 02:46:06 +00:00
|
|
|
struct strbuf buf;
|
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
|
|
|
|
2022-11-18 02:46:06 +00:00
|
|
|
strbuf_init(&buf, 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
|
|
|
printf("%s{\n", print_state->need_sep ? ",\n" : "");
|
|
|
|
print_state->need_sep = true;
|
|
|
|
if (pmu_name) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "\t\"Unit\": \"%S\"", pmu_name);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (topic) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"Topic\": \"%S\"", need_sep ? ",\n" : "", topic);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (event_name) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"EventName\": \"%S\"", need_sep ? ",\n" : "",
|
|
|
|
event_name);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (event_alias && strlen(event_alias)) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"EventAlias\": \"%S\"", need_sep ? ",\n" : "",
|
|
|
|
event_alias);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (scale_unit && strlen(scale_unit)) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"ScaleUnit\": \"%S\"", need_sep ? ",\n" : "",
|
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
|
|
|
scale_unit);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (event_type_desc) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"EventType\": \"%S\"", need_sep ? ",\n" : "",
|
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
|
|
|
event_type_desc);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (deprecated) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"Deprecated\": \"%S\"", need_sep ? ",\n" : "",
|
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
|
|
|
deprecated ? "1" : "0");
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (desc) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"BriefDescription\": \"%S\"", need_sep ? ",\n" : "",
|
|
|
|
desc);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (long_desc) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"PublicDescription\": \"%S\"", need_sep ? ",\n" : "",
|
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
|
|
|
long_desc);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (encoding_desc) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"Encoding\": \"%S\"", need_sep ? ",\n" : "",
|
|
|
|
encoding_desc);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
printf("%s}", need_sep ? "\n" : "");
|
2022-11-18 02:46:06 +00:00
|
|
|
strbuf_release(&buf);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-02-19 09:28:32 +00:00
|
|
|
const char *threshold, const char *unit)
|
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 *print_state = ps;
|
|
|
|
bool need_sep = false;
|
2022-11-18 02:46:06 +00:00
|
|
|
struct strbuf buf;
|
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
|
|
|
|
2022-11-18 02:46:06 +00:00
|
|
|
strbuf_init(&buf, 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
|
|
|
printf("%s{\n", print_state->need_sep ? ",\n" : "");
|
|
|
|
print_state->need_sep = true;
|
|
|
|
if (group) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "\t\"MetricGroup\": \"%S\"", group);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (name) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"MetricName\": \"%S\"", need_sep ? ",\n" : "", name);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (expr) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"MetricExpr\": \"%S\"", need_sep ? ",\n" : "", expr);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
2023-02-19 09:28:32 +00:00
|
|
|
if (threshold) {
|
|
|
|
fix_escape_printf(&buf, "%s\t\"MetricThreshold\": \"%S\"", need_sep ? ",\n" : "",
|
|
|
|
threshold);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
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 (unit) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"ScaleUnit\": \"%S\"", need_sep ? ",\n" : "", unit);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (desc) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"BriefDescription\": \"%S\"", need_sep ? ",\n" : "",
|
|
|
|
desc);
|
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
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
if (long_desc) {
|
2022-11-18 02:46:06 +00:00
|
|
|
fix_escape_printf(&buf, "%s\t\"PublicDescription\": \"%S\"", need_sep ? ",\n" : "",
|
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
|
|
|
long_desc);
|
|
|
|
need_sep = true;
|
|
|
|
}
|
|
|
|
printf("%s}", need_sep ? "\n" : "");
|
2022-11-18 02:46:06 +00:00
|
|
|
strbuf_release(&buf);
|
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
|
|
|
}
|
|
|
|
|
2023-08-25 13:52:37 +00:00
|
|
|
static bool default_skip_duplicate_pmus(void *ps)
|
|
|
|
{
|
|
|
|
struct print_state *print_state = ps;
|
|
|
|
|
|
|
|
return !print_state->long_desc;
|
|
|
|
}
|
|
|
|
|
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,
|
2023-08-25 13:52:37 +00:00
|
|
|
.skip_duplicate_pmus = default_skip_duplicate_pmus,
|
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
|
|
|
};
|
2023-05-02 22:38:37 +00:00
|
|
|
const char *cputype = NULL;
|
2022-11-14 21:07:18 +00:00
|
|
|
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."),
|
2023-05-02 22:38:37 +00:00
|
|
|
OPT_STRING(0, "cputype", &cputype, "cpu type",
|
|
|
|
"Limit PMU or metric printing to the given PMU (e.g. cpu, core or atom)."),
|
2022-11-14 21:07:18 +00:00
|
|
|
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[] = {
|
2023-06-08 23:23:59 +00:00
|
|
|
#ifdef HAVE_LIBPFM
|
|
|
|
"perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob|pfm]",
|
|
|
|
#else
|
2020-05-22 06:45:46 +00:00
|
|
|
"perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob]",
|
2023-06-08 23:23:59 +00:00
|
|
|
#endif
|
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);
|
2023-05-02 22:38:37 +00:00
|
|
|
else if (cputype) {
|
|
|
|
const struct perf_pmu *pmu = perf_pmus__pmu_for_pmu_filter(cputype);
|
|
|
|
|
|
|
|
if (!pmu) {
|
|
|
|
pr_err("ERROR: cputype is not supported!\n");
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
2023-08-25 02:39:58 +00:00
|
|
|
default_ps.pmu_glob = strdup(pmu->name);
|
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
|
|
|
}
|
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)
|
2023-05-27 07:22:03 +00:00
|
|
|
perf_pmus__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);
|
2023-06-08 23:23:59 +00:00
|
|
|
}
|
|
|
|
#ifdef HAVE_LIBPFM
|
|
|
|
else if (strcmp(argv[i], "pfm") == 0)
|
|
|
|
print_libpfm_events(&print_cb, ps);
|
|
|
|
#endif
|
|
|
|
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);
|
2023-05-27 07:22:03 +00:00
|
|
|
perf_pmus__print_pmu_events(&print_cb, ps);
|
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);
|
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
|
|
|
}
|