From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: acme@kernel.org, irogers@google.com, peterz@infradead.org,
mingo@kernel.org, linux-kernel@vger.kernel.org,
adrian.hunter@intel.com, ak@linux.intel.com, eranian@google.com
Subject: Re: [PATCH 5/9] perf evsel: Assign abbr name for the branch counter events
Date: Tue, 6 Aug 2024 10:11:12 -0400 [thread overview]
Message-ID: <01ea531d-9540-47ad-9e18-46eeddc92ff4@linux.intel.com> (raw)
In-Reply-To: <CAM9d7ciC54X5dth=6uziMS8kKHu=wfZFX8j_et3Gzvgeq3M-cw@mail.gmail.com>
On 2024-08-02 8:14 p.m., Namhyung Kim wrote:
> On Wed, Jul 3, 2024 at 1:03 PM <kan.liang@linux.intel.com> wrote:
>>
>> From: Kan Liang <kan.liang@linux.intel.com>
>>
>> There could be several branch counter events. If perf tool output the
>> result via the format "event name + a number", the line could be very
>> long and hard to read.
>>
>> An abbreviation is introduced to replace the full event name in the
>> display. The abbreviation starts from 'A' to 'Z9', which can support
>> up to 286 events. The same abbreviation will be assigned if the same
>> events are found in the evlist. The next patch will utilize the
>> abbreviation name to show the branch counter events in the output.
>>
>> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
>> ---
>> tools/perf/util/evlist.c | 53 +++++++++++++++++++++++++++++++++++++++-
>> tools/perf/util/evsel.h | 4 +++
>> 2 files changed, 56 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
>> index 6f5311d01a14..028169dcb53d 100644
>> --- a/tools/perf/util/evlist.c
>> +++ b/tools/perf/util/evlist.c
>> @@ -33,6 +33,7 @@
>> #include "util/bpf-filter.h"
>> #include "util/stat.h"
>> #include "util/util.h"
>> +#include "util/env.h"
>> #include <signal.h>
>> #include <unistd.h>
>> #include <sched.h>
>> @@ -1262,15 +1263,65 @@ u64 evlist__combined_branch_type(struct evlist *evlist)
>> return branch_type;
>> }
>>
>> +static struct evsel *
>> +evlist__find_dup_event_from_prev(struct evlist *evlist, struct evsel *event)
>> +{
>> + struct evsel *pos;
>> +
>> + evlist__for_each_entry(evlist, pos) {
>> + if (event == pos)
>> + break;
>> + if ((pos->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS) &&
>> + !strcmp(pos->name, event->name))
>> + return pos;
>> + }
>> + return NULL;
>> +}
>> +
>> +#define MAX_NR_ABBR_NAME (26 * 11)
>> +
>> +/*
>> + * The abbr name is from A to Z9. If the number of event
>> + * which requires the branch counter > MAX_NR_ABBR_NAME,
>> + * return NA.
>> + */
>> +static char *evlist__new_abbr_name(void)
>> +{
>> + static int idx;
>> + char str[3];
>> + int i = idx / 26;
>> +
>> + if (idx >= MAX_NR_ABBR_NAME)
>> + return strdup("NA");
>> +
>> + str[0] = 'A' + (idx % 26);
>> +
>> + if (!i)
>> + str[1] = '\0';
>> + else {
>> + str[1] = '0' + i - 1;
>> + str[2] = '\0';
>> + }
>> +
>> + idx++;
>> + return strdup(str);
>> +}
>> +
>> void evlist__update_br_cntr(struct evlist *evlist)
>> {
>> - struct evsel *evsel;
>> + struct evsel *evsel, *dup;
>> int i = 0;
>>
>> evlist__for_each_entry(evlist, evsel) {
>> if (evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS) {
>> evsel->br_cntr_idx = i++;
>> evsel__leader(evsel)->br_cntr_nr++;
>> +
>> + dup = evlist__find_dup_event_from_prev(evlist, evsel);
>> + if (dup)
>> + evsel->abbr_name = strdup(dup->abbr_name);
>> + else
>> + evsel->abbr_name = evlist__new_abbr_name();
>> }
>> }
>> evlist->nr_br_cntr = i;
>> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
>> index a733d3407b35..bf37442002aa 100644
>> --- a/tools/perf/util/evsel.h
>> +++ b/tools/perf/util/evsel.h
>> @@ -152,9 +152,13 @@ struct evsel {
>> * br_cntr_idx: The idx of the branch counter event in the evlist
>> * br_cntr_nr: The number of the branch counter event in the group
>> * (Only available for the leader event)
>> + * abbr_name: The abbreviation name assigned to an event which is
>> + * logged by the branch counter.
>> */
>> int br_cntr_idx;
>> int br_cntr_nr;
>> + char *abbr_name;
>
> I think it's better to have an array (of 4 characters?) instead of a
> pointer as it's supposed to be a short string.
Sure. I think 3 characters should be enough, since the abbr name is only
from A to Z9.
Thanks,
Kan
>
> Thanks,
> Namhyung
>
>> +
>> /*
>> * bpf_counter_ops serves two use cases:
>> * 1. perf-stat -b counting events used byBPF programs
>> --
>> 2.38.1
>>
>
next prev parent reply other threads:[~2024-08-06 14:11 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-03 20:03 [PATCH 0/9] Support branch counters in block annotation kan.liang
2024-07-03 20:03 ` [PATCH 1/9] perf report: Fix --total-cycles --stdio output error kan.liang
2024-08-02 20:25 ` Namhyung Kim
2024-07-03 20:03 ` [PATCH 2/9] perf report: Remove the first overflow check for branch counters kan.liang
2024-08-02 20:26 ` Namhyung Kim
2024-07-03 20:03 ` [PATCH 3/9] perf evlist: Save branch counters information kan.liang
2024-07-03 20:03 ` [PATCH 4/9] perf annotate: Save branch counters for each block kan.liang
2024-07-03 20:03 ` [PATCH 5/9] perf evsel: Assign abbr name for the branch counter events kan.liang
2024-08-03 0:14 ` Namhyung Kim
2024-08-06 14:11 ` Liang, Kan [this message]
2024-07-03 20:03 ` [PATCH 6/9] perf report: Display the branch counter histogram kan.liang
2024-08-03 0:18 ` Namhyung Kim
2024-08-06 14:39 ` Liang, Kan
2024-08-06 23:29 ` Namhyung Kim
2024-08-07 3:22 ` Andi Kleen
2024-08-07 11:57 ` Liang, Kan
2024-07-03 20:03 ` [PATCH 7/9] perf annotate: " kan.liang
2024-08-02 21:09 ` Andi Kleen
2024-08-06 14:42 ` Liang, Kan
2024-08-06 21:37 ` Liang, Kan
2024-08-06 23:02 ` Andi Kleen
2024-07-03 20:03 ` [PATCH 8/9] perf script: Add branch counters kan.liang
2024-07-03 20:03 ` [PATCH 9/9] perf test: Add new test cases for the branch counter feature kan.liang
2024-07-31 15:05 ` [PATCH 0/9] Support branch counters in block annotation Arnaldo Carvalho de Melo
2024-07-31 15:31 ` Liang, Kan
2024-07-31 17:00 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=01ea531d-9540-47ad-9e18-46eeddc92ff4@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox