mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Wei Li <liwei391@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>, Kajol Jain <kjain@linux.ibm.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	linux-kernel@vger.kernel.org, huawei.libin@huawei.com,
	guohanjun@huawei.com
Subject: Re: [PATCH v2] perf metric: Code cleanup with map_for_each_event()
Date: Fri, 18 Sep 2020 15:57:21 +0200	[thread overview]
Message-ID: <20200918135721.GE2626435@krava> (raw)
In-Reply-To: <20200918012948.2798-1-liwei391@huawei.com>

On Fri, Sep 18, 2020 at 09:29:48AM +0800, Wei Li wrote:
> Since we have introduced map_for_each_event() to walk the 'pmu_events_map',
> clean up metricgroup__print() and metricgroup__has_metric() with it.
> 
> Signed-off-by: Wei Li <liwei391@huawei.com>
> Acked-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

> ---
> v1 -> v2:
>  - Move map_for_each_metric() after match_metric() to avoid potential
>    use-before-declare.
> ---
>  tools/perf/util/metricgroup.c | 33 +++++++++++++--------------------
>  1 file changed, 13 insertions(+), 20 deletions(-)
> 
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index 8831b964288f..50ee36437b99 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -374,6 +374,17 @@ static bool match_metric(const char *n, const char *list)
>  	return false;
>  }
>  
> +#define map_for_each_event(__pe, __idx, __map)				\
> +	for (__idx = 0, __pe = &__map->table[__idx];			\
> +	     __pe->name || __pe->metric_group || __pe->metric_name;	\
> +	     __pe = &__map->table[++__idx])
> +
> +#define map_for_each_metric(__pe, __idx, __map, __metric)		\
> +	map_for_each_event(__pe, __idx, __map)				\
> +		if (__pe->metric_expr &&				\
> +		    (match_metric(__pe->metric_group, __metric) ||	\
> +		     match_metric(__pe->metric_name, __metric)))
> +
>  struct mep {
>  	struct rb_node nd;
>  	const char *name;
> @@ -475,12 +486,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,
>  	groups.node_new = mep_new;
>  	groups.node_cmp = mep_cmp;
>  	groups.node_delete = mep_delete;
> -	for (i = 0; ; i++) {
> +	map_for_each_event(pe, i, map) {
>  		const char *g;
> -		pe = &map->table[i];
>  
> -		if (!pe->name && !pe->metric_group && !pe->metric_name)
> -			break;
>  		if (!pe->metric_expr)
>  			continue;
>  		g = pe->metric_group;
> @@ -745,17 +753,6 @@ static int __add_metric(struct list_head *metric_list,
>  	return 0;
>  }
>  
> -#define map_for_each_event(__pe, __idx, __map)				\
> -	for (__idx = 0, __pe = &__map->table[__idx];			\
> -	     __pe->name || __pe->metric_group || __pe->metric_name;	\
> -	     __pe = &__map->table[++__idx])
> -
> -#define map_for_each_metric(__pe, __idx, __map, __metric)		\
> -	map_for_each_event(__pe, __idx, __map)				\
> -		if (__pe->metric_expr &&				\
> -		    (match_metric(__pe->metric_group, __metric) ||	\
> -		     match_metric(__pe->metric_name, __metric)))
> -
>  static struct pmu_event *find_metric(const char *metric, struct pmu_events_map *map)
>  {
>  	struct pmu_event *pe;
> @@ -1092,11 +1089,7 @@ bool metricgroup__has_metric(const char *metric)
>  	if (!map)
>  		return false;
>  
> -	for (i = 0; ; i++) {
> -		pe = &map->table[i];
> -
> -		if (!pe->name && !pe->metric_group && !pe->metric_name)
> -			break;
> +	map_for_each_event(pe, i, map) {
>  		if (!pe->metric_expr)
>  			continue;
>  		if (match_metric(pe->metric_name, metric))
> -- 
> 2.17.1
> 


      reply	other threads:[~2020-09-18 13:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-18  1:29 Wei Li
2020-09-18 13:57 ` Jiri Olsa [this message]

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=20200918135721.GE2626435@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=guohanjun@huawei.com \
    --cc=huawei.libin@huawei.com \
    --cc=irogers@google.com \
    --cc=kan.liang@linux.intel.com \
    --cc=kjain@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liwei391@huawei.com \
    --cc=mark.rutland@arm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®