perf stat: Support --cputype option for hybrid events
PATCH 1/1 perf stat: Support --cputype option for hybrid events
In previous patch, we have supported the syntax which enables the event on a specified pmu, such as:
cpu_core/<event>/
cpu_atom/<event>/
While this syntax is not very easy for applying on a set of events or applying on a group. In following example, we have to explicitly assign the pmu prefix.
# ./perf stat -e '{cpu_core/cycles/,cpu_core/instructions/}' -- sleep 1Performance counter stats for 'sleep 1':
1,158,545 cpu_core/cycles/
1,003,113 cpu_core/instructions/
1.002428712 seconds time elapsedA much easier way is:
# ./perf stat --cputype core -e '{cycles,instructions}' -- sleep 1Performance counter stats for 'sleep 1':
1,101,071 cpu_core/cycles/
939,892 cpu_core/instructions/
1.002363142 seconds time elapsedFor this example, the '--cputype' enables the events from specified pmu (cpu_core).
If '--cputype' conflicts with pmu prefix, '--cputype' is ignored.
# ./perf stat --cputype core -e cycles,cpu_atom/instructions/ -a -- sleep 1
Performance counter stats for 'system wide':
21,003,407 cpu_core/cycles/
367,886 cpu_atom/instructions/
1.002203520 seconds time elapsed--- tools/perf/Documentation/perf-stat.txt | 4 ++++ tools/perf/builtin-stat.c | 24 ++++++++++++++++++++++++ tools/perf/util/evlist.h | 1 + tools/perf/util/parse-events-hybrid.c | 9 ++++++--- 4 files changed, 35 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-stat.txt +4 -0
@@ -493,6 +493,10 @@ This option can be enabled in perf config by setting the variable $ perf config stat.no-csv-summary=true +--cputype:: +Only enable events on applying cpu with this type for hybrid platform +(e.g. core or atom)" + EXAMPLES --------
tools/perf/builtin-stat.c +24 -0
@@ -1168,6 +1168,26 @@ static int parse_stat_cgroups(const struct option *opt,return parse_cgroups (opt, str, unset); } +static int parse_hybrid_type (const struct option *opt, +const char *str, +int unset__maybe_unused ) +{ +struct evlist *evlist = *(struct evlist **)opt->value; + +if (!list_empty (&evlist->core.entries)) { +fprintf (stderr,"Must define cputype before events/metrics\n" ); +return -1 ; + } + + evlist->hybrid_pmu_name =perf_pmu__hybrid_type_to_pmu (str); +if (!evlist->hybrid_pmu_name) { +fprintf (stderr,"--cputype %s is not supported!\n" , str); +return -1 ; + } + +return 0 ; +} +static struct option stat_options[] = {OPT_BOOLEAN ('T' ,"transaction" , &transaction_run,"hardware transaction statistics" ),
@@ -1282,6 +1302,10 @@ static struct option stat_options[] = { "don't print 'summary' for CSV summary output"),OPT_BOOLEAN (0 ,"quiet" , &stat_config.quiet,"don't print output (useful with record)" ), +OPT_CALLBACK (0 ,"cputype" , &evsel_list,"hybrid cpu type" , +"Only enable events on applying cpu with this type " +"for hybrid platform (e.g. core or atom)" , + parse_hybrid_type), #ifdef HAVE_LIBPFM OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", "libpfm4 event selector. use 'perf list' to list available events",
tools/perf/util/evlist.h +1 -0
@@ -64,6 +64,7 @@ struct evlist {struct evsel *selected;struct events_stats stats;struct perf_env *env; +const char *hybrid_pmu_name;void (*trace_event_sample_raw)(struct evlist *evlist,union perf_event *event,struct perf_sample *sample);
tools/perf/util/parse-events-hybrid.c +6 -3
@@ -62,10 +62,13 @@ static int create_event_hybrid(__u32 config_type, int *idx,static int pmu_cmp (struct parse_events_state *parse_state,struct perf_pmu *pmu) { -if (!parse_state->hybrid_pmu_name) -return 0 ; +if (parse_state->evlist && parse_state->evlist->hybrid_pmu_name) +return strcmp (parse_state->evlist->hybrid_pmu_name, pmu->name); + +if (parse_state->hybrid_pmu_name) +return strcmp (parse_state->hybrid_pmu_name, pmu->name); -return strcmp (parse_state->hybrid_pmu_name, pmu->name); +return 0 ; } static int add_hw_hybrid(struct parse_events_state *parse_state,
Signature · 1 line
2.17.1
Em Thu, Sep 09, 2021 at 02:22:15PM +0800, Jin Yao escreveu:
Quoted 2 lines
In previous patch, we have supported the syntax which enables the event on a specified pmu, such as:
Fell thru the cracks :-\
Thanks, applied.
- Arnaldo
Quoted 141 lines
cpu_core/<event>/
cpu_atom/<event>/While this syntax is not very easy for applying on a set of events or applying on a group. In following example, we have to explicitly assign the pmu prefix.
# ./perf stat -e '{cpu_core/cycles/,cpu_core/instructions/}' -- sleep 1Performance counter stats for 'sleep 1': 1,158,545 cpu_core/cycles/ 1,003,113 cpu_core/instructions/ 1.002428712 seconds time elapsedA much easier way is:
# ./perf stat --cputype core -e '{cycles,instructions}' -- sleep 1Performance counter stats for 'sleep 1': 1,101,071 cpu_core/cycles/ 939,892 cpu_core/instructions/ 1.002363142 seconds time elapsedFor this example, the '--cputype' enables the events from specified pmu (
cpu_core).If '--cputype' conflicts with pmu prefix, '--cputype' is ignored.
# ./perf stat --cputype core -e cycles,cpu_atom/instructions/ -a -- sleep 1Performance counter stats for 'system wide': 21,003,407 cpu_core/cycles/ 367,886 cpu_atom/instructions/ 1.002203520 seconds time elapsedSigned-off-by Jin Yao <[email protected]>--- tools/perf/Documentation/perf-stat.txt | 4 ++++ tools/perf/builtin-stat.c | 24 ++++++++++++++++++++++++ tools/perf/util/evlist.h | 1 + tools/perf/util/parse-events-hybrid.c | 9 ++++++--- 4 files changed, 35 insertions(+), 3 deletions(-)tools/perf/Documentation/perf-stat.txt +4
-0@@ -493,6 +493,10 @@ This option can be enabled in perf config by setting the variable $ perf config stat.no-csv-summary=true +--cputype:: +Only enable events on applying cpu with this type for hybrid platform +(e.g. core or atom)" + EXAMPLES --------tools/perf/builtin-stat.c +24
-0@@ -1168,6 +1168,26 @@ static int parse_stat_cgroups(const struct option *opt,return parse_cgroups (opt, str, unset); } +static int parse_hybrid_type (const struct option *opt, +const char *str, +int unset__maybe_unused ) +{ +struct evlist *evlist = *(struct evlist **)opt->value; + +if (!list_empty (&evlist->core.entries)) { +fprintf (stderr,"Must define cputype before events/metrics\n" ); +return -1 ; + } + + evlist->hybrid_pmu_name =perf_pmu__hybrid_type_to_pmu (str); +if (!evlist->hybrid_pmu_name) { +fprintf (stderr,"--cputype %s is not supported!\n" , str); +return -1 ; + } + +return 0 ; +} +static struct option stat_options[] = {OPT_BOOLEAN ('T' ,"transaction" , &transaction_run,"hardware transaction statistics" ),@@ -1282,6 +1302,10 @@ static struct option stat_options[] = { "don't print 'summary' for CSV summary output"),OPT_BOOLEAN (0 ,"quiet" , &stat_config.quiet,"don't print output (useful with record)" ), +OPT_CALLBACK (0 ,"cputype" , &evsel_list,"hybrid cpu type" , +"Only enable events on applying cpu with this type " +"for hybrid platform (e.g. core or atom)" , + parse_hybrid_type), #ifdef HAVE_LIBPFM OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", "libpfm4 event selector. use 'perf list' to list available events",tools/perf/util/evlist.h +1
-0@@ -64,6 +64,7 @@ struct evlist {struct evsel *selected;struct events_stats stats;struct perf_env *env; +const char *hybrid_pmu_name;void (*trace_event_sample_raw)(struct evlist *evlist,union perf_event *event,struct perf_sample *sample);tools/perf/util/parse-events-hybrid.c +6
-3@@ -62,10 +62,13 @@ static int create_event_hybrid(__u32 config_type, int *idx,static int pmu_cmp (struct parse_events_state *parse_state,struct perf_pmu *pmu) { -if (!parse_state->hybrid_pmu_name) -return 0 ; +if (parse_state->evlist && parse_state->evlist->hybrid_pmu_name) +return strcmp (parse_state->evlist->hybrid_pmu_name, pmu->name); + +if (parse_state->hybrid_pmu_name) +return strcmp (parse_state->hybrid_pmu_name, pmu->name); -return strcmp (parse_state->hybrid_pmu_name, pmu->name); +return 0 ; } static int add_hw_hybrid(struct parse_events_state *parse_state,Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo