Re: [PATCH v4 14/25] perf stat: Add default hybrid events
From: Jiri Olsa
Date: Thu Apr 22 2021 - 06:25:38 EST
On Thu, Apr 22, 2021 at 10:12:49AM +0800, Jin, Yao wrote:
> Hi Jiri,
>
> On 4/22/2021 2:29 AM, Jiri Olsa wrote:
> > On Fri, Apr 16, 2021 at 10:05:06PM +0800, Jin Yao wrote:
> >
> > SNIP
> >
> > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> > > index 1255af4751c2..0351b99d17a7 100644
> > > --- a/tools/perf/builtin-stat.c
> > > +++ b/tools/perf/builtin-stat.c
> > > @@ -1145,6 +1145,13 @@ static int parse_stat_cgroups(const struct option *opt,
> > > return parse_cgroups(opt, str, unset);
> > > }
> > > +static int add_default_hybrid_events(struct evlist *evlist)
> > > +{
> > > + struct parse_events_error err;
> > > +
> > > + return parse_events(evlist, "cycles,instructions,branches,branch-misses", &err);
> > > +}
> > > +
> > > static struct option stat_options[] = {
> > > OPT_BOOLEAN('T', "transaction", &transaction_run,
> > > "hardware transaction statistics"),
> > > @@ -1626,6 +1633,12 @@ static int add_default_attributes(void)
> > > { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
> > > { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_MISSES },
> > > +};
> > > + struct perf_event_attr default_sw_attrs[] = {
> > > + { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK },
> > > + { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES },
> > > + { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CPU_MIGRATIONS },
> > > + { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_PAGE_FAULTS },
> >
> > hum, why not use default_attrs0, it's the same, no?
> >
>
> The default_attrs0 has one more item " {.type = PERF_TYPE_HARDWARE, .config
> = PERF_COUNT_HW_CPU_CYCLES },"
>
> So I have to only pick out the sw attrs and save them to default_sw_attrs.
>
> > > };
> > > /*
> > > @@ -1863,6 +1876,14 @@ static int add_default_attributes(void)
> > > }
> > > if (!evsel_list->core.nr_entries) {
> > > + if (perf_pmu__has_hybrid()) {
> > > + if (evlist__add_default_attrs(evsel_list,
> > > + default_sw_attrs) < 0) {
> > > + return -1;
> > > + }
> > > + return add_default_hybrid_events(evsel_list);
> >
> > please do it the same way like when topdown calls parse events,
> > we don't need to check for cycles, but please check result and
> > display the error
> >
>
> Something like this?
>
> err = parse_events(evsel_list, "cycles,instructions,branches,branch-misses", &errinfo);
> if (err) {
> fprintf(stderr,...);
> parse_events_print_error(&errinfo, ...);
> return -1;
> }
yes
jirka