From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: "Liang, Kan" <kan.liang@linux.intel.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
Namhyung Kim <namhyung@kernel.org>
Subject: Re: [PATCH 1/1] perf evsel: Introduce evsel__name_is() method to check if the evsel name is equal to a given string
Date: Mon, 24 Apr 2023 14:25:27 -0300 [thread overview]
Message-ID: <ZEa7h8ZCAS+dHTBL@kernel.org> (raw)
In-Reply-To: <7de5c749-5960-2fa1-d48a-be360b08d5e1@linux.intel.com>
Em Thu, Apr 20, 2023 at 05:16:18PM -0400, Liang, Kan escreveu:
>
>
> On 2023-04-20 3:28 p.m., Arnaldo Carvalho de Melo wrote:
> > Em Thu, Apr 20, 2023 at 04:10:30PM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Em Thu, Apr 20, 2023 at 03:57:55PM -0300, Arnaldo Carvalho de Melo escreveu:
> >>> This makes the logic a bit clear by avoiding the !strcmp() pattern and
> >>> also a way to intercept the pointer if we need to do extra validation on
> >>> it or to do lazy setting of evsel->name via evsel__name(evsel).
> >>
> >> + this, looking if there are others...
> >
> > Somehow the first message didn't go thru, so below is the combined
> > patch, this is an effort to avoid accessing evsel->name directly as the
> > preferred way to get an evsel name is evsel__name(), so looking for
> > direct access and providing accessors that avoid that.
>
> One more
>
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 2260e27adf44..3a960a3f6962 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -467,7 +467,7 @@ static int evsel__strcmp(struct evsel *pos, char
> *evsel_name)
> return 0;
> if (evsel__is_dummy_event(pos))
> return 1;
> - return strcmp(pos->name, evsel_name);
> + return !evsel__name_is(pos, evsel_name);
> }
>
> static int evlist__is_enabled(struct evlist *evlist)
Added
> >
> > From e60455d6a4e35ba0c376966443294586a1adc3ec Mon Sep 17 00:00:00 2001
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > Date: Thu, 20 Apr 2023 15:54:11 -0300
> > Subject: [PATCH 1/1] perf evsel: Introduce evsel__name_is() method to check if
> > the evsel name is equal to a given string
> >
> > This makes the logic a bit clear by avoiding the !strcmp() pattern and
> > also a way to intercept the pointer if we need to do extra validation on
> > it or to do lazy setting of evsel->name via evsel__name(evsel).
> >
> > Cc: Adrian Hunter <adrian.hunter@intel.com>
> > Cc: Ian Rogers <irogers@google.com>
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: "Liang, Kan" <kan.liang@linux.intel.com>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Link: https://lore.kernel.org/lkml/ZEGLM8VehJbS0gP2@kernel.org
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> With the above one,
>
> Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Added these extra ones and actually made evsel__name_is() use
evsel__name().
Does your reviewed-by stands after these extra changes?
Thanks,
- Arnaldo
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 2260e27adf44c579..a0504316b06fbcba 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -467,7 +467,7 @@ static int evsel__strcmp(struct evsel *pos, char *evsel_name)
return 0;
if (evsel__is_dummy_event(pos))
return 1;
- return strcmp(pos->name, evsel_name);
+ return !evsel__name_is(pos, evsel_name);
}
static int evlist__is_enabled(struct evlist *evlist)
@@ -1706,7 +1706,7 @@ struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str)
evlist__for_each_entry(evlist, evsel) {
if (!evsel->name)
continue;
- if (strcmp(str, evsel->name) == 0)
+ if (evsel__name_is(evsel, str))
return evsel;
}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 81b854650160c2b0..356c07f03be6bfce 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -823,7 +823,7 @@ const char *evsel__name(struct evsel *evsel)
bool evsel__name_is(struct evsel *evsel, const char *name)
{
- return !strcmp(evsel->name, name);
+ return !strcmp(evsel__name(evsel), name);
}
const char *evsel__group_pmu_name(const struct evsel *evsel)
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 31b1cd0935e277ba..dae81d8e1769c763 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -2893,7 +2893,7 @@ static struct evsel *find_evsel(struct evlist *evlist, char *event_name)
full_name = !!strchr(event_name, ':');
evlist__for_each_entry(evlist, pos) {
/* case 2 */
- if (full_name && !strcmp(pos->name, event_name))
+ if (full_name && evsel__name_is(pos->name, event_name))
return pos;
/* case 3 */
if (!full_name && strstr(pos->name, event_name)) {
next prev parent reply other threads:[~2023-04-24 17:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <ZEGLM8VehJbS0gP2@kernel.org>
2023-04-20 19:10 ` [PATCH 1/1] perf evsel: Introduce evsel__name_is() method to check if the evsel name is equal to a given string Arnaldo Carvalho de Melo
2023-04-20 19:28 ` Arnaldo Carvalho de Melo
2023-04-20 21:16 ` Liang, Kan
2023-04-24 17:25 ` Arnaldo Carvalho de Melo [this message]
2023-04-24 17:27 ` Arnaldo Carvalho de Melo
2023-04-24 17:50 ` Liang, Kan
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=ZEa7h8ZCAS+dHTBL@kernel.org \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.