linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Riccardo Mancini <rickyman7@gmail.com>,
	Kim Phillips <kim.phillips@amd.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Shunsuke Nakamura <nakamura.shun@fujitsu.com>,
	Florian Fischer <florian.fischer@muhq.space>,
	Andi Kleen <ak@linux.intel.com>,
	John Garry <john.garry@huawei.com>,
	Zhengjun Xing <zhengjun.xing@linux.intel.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@arm.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH 3/5] perf evsel: Add tool event helpers
Date: Mon, 9 May 2022 10:16:35 -0300	[thread overview]
Message-ID: <YnkUM32sISfq1fad@kernel.org> (raw)
In-Reply-To: <20220507053410.3798748-4-irogers@google.com>

Em Fri, May 06, 2022 at 10:34:08PM -0700, Ian Rogers escreveu:
> Convert to and from a string. Fix evsel__tool_name as array is off-by-1.
> Support more than just duration_time as a metric-id.

Good catch, I added this:

Fixes: 75eafc970bd9d36d ("perf list: Print all available tool events")

- Arnaldo
 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/evsel.c | 41 +++++++++++++++++++++++++++++++----------
>  tools/perf/util/evsel.h | 11 +++++++++++
>  2 files changed, 42 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index cdeace24d9be..5fd7924f8eb3 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -59,6 +59,33 @@ struct perf_missing_features perf_missing_features;
>  
>  static clockid_t clockid;
>  
> +static const char *const perf_tool_event__tool_names[PERF_TOOL_MAX] = {
> +	NULL,
> +	"duration_time",
> +	"user_time",
> +	"system_time",
> +};
> +
> +const char *perf_tool_event__to_str(enum perf_tool_event ev)
> +{
> +	if (ev > PERF_TOOL_NONE && ev < PERF_TOOL_MAX)
> +		return perf_tool_event__tool_names[ev];
> +
> +	return NULL;
> +}
> +
> +enum perf_tool_event perf_tool_event__from_str(const char *str)
> +{
> +	int i;
> +
> +	perf_tool_event__for_each_event(i) {
> +		if (!strcmp(str, perf_tool_event__tool_names[i]))
> +			return i;
> +	}
> +	return PERF_TOOL_NONE;
> +}
> +
> +
>  static int evsel__no_extra_init(struct evsel *evsel __maybe_unused)
>  {
>  	return 0;
> @@ -597,15 +624,9 @@ static int evsel__sw_name(struct evsel *evsel, char *bf, size_t size)
>  	return r + evsel__add_modifiers(evsel, bf + r, size - r);
>  }
>  
> -static const char *const evsel__tool_names[PERF_TOOL_MAX] = {
> -	"duration_time",
> -	"user_time",
> -	"system_time",
> -};
> -
>  static int evsel__tool_name(enum perf_tool_event ev, char *bf, size_t size)
>  {
> -	return scnprintf(bf, size, "%s", evsel__tool_names[ev]);
> +	return scnprintf(bf, size, "%s", perf_tool_event__to_str(ev));
>  }
>  
>  static int __evsel__bp_name(char *bf, size_t size, u64 addr, u64 type)
> @@ -758,7 +779,7 @@ const char *evsel__name(struct evsel *evsel)
>  		break;
>  
>  	case PERF_TYPE_SOFTWARE:
> -		if (evsel->tool_event)
> +		if (evsel__is_tool(evsel))
>  			evsel__tool_name(evsel->tool_event, bf, sizeof(bf));
>  		else
>  			evsel__sw_name(evsel, bf, sizeof(bf));
> @@ -791,8 +812,8 @@ const char *evsel__metric_id(const struct evsel *evsel)
>  	if (evsel->metric_id)
>  		return evsel->metric_id;
>  
> -	if (evsel->core.attr.type == PERF_TYPE_SOFTWARE && evsel->tool_event)
> -		return "duration_time";
> +	if (evsel__is_tool(evsel))
> +		return perf_tool_event__to_str(evsel->tool_event);
>  
>  	return "unknown";
>  }
> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> index a017781cdd47..d4b04537ce6d 100644
> --- a/tools/perf/util/evsel.h
> +++ b/tools/perf/util/evsel.h
> @@ -36,6 +36,12 @@ enum perf_tool_event {
>  	PERF_TOOL_MAX,
>  };
>  
> +const char *perf_tool_event__to_str(enum perf_tool_event ev);
> +enum perf_tool_event perf_tool_event__from_str(const char *str);
> +
> +#define perf_tool_event__for_each_event(ev)		\
> +	for ((ev) = PERF_TOOL_DURATION_TIME; (ev) < PERF_TOOL_MAX; ev++)
> +
>  /** struct evsel - event selector
>   *
>   * @evlist - evlist this evsel is in, if it is in one.
> @@ -269,6 +275,11 @@ int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size
>  const char *evsel__name(struct evsel *evsel);
>  const char *evsel__metric_id(const struct evsel *evsel);
>  
> +static inline bool evsel__is_tool(const struct evsel *evsel)
> +{
> +	return evsel->tool_event != PERF_TOOL_NONE;
> +}
> +
>  const char *evsel__group_name(struct evsel *evsel);
>  int evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
>  
> -- 
> 2.36.0.512.ge40c2bad7a-goog

-- 

- Arnaldo

  reply	other threads:[~2022-05-09 13:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-07  5:34 [PATCH 0/5] Revert metric hybrid events, fix tools events Ian Rogers
2022-05-07  5:34 ` [PATCH 1/5] Revert "perf stat: Support metrics with hybrid events" Ian Rogers
2022-05-09 13:12   ` Arnaldo Carvalho de Melo
2022-05-09 21:55     ` Liang, Kan
2022-05-10  9:31       ` Xing Zhengjun
2022-05-10 15:48         ` Arnaldo Carvalho de Melo
2022-05-10 16:45           ` Ian Rogers
2022-05-11  2:14             ` Xing Zhengjun
2022-05-11  5:45               ` Ian Rogers
2022-05-17 22:58         ` Namhyung Kim
2022-05-18  0:08           ` Ian Rogers
2022-05-18  2:45           ` Xing Zhengjun
2022-05-07  5:34 ` [PATCH 2/5] perf evsel: Constify a few arrays Ian Rogers
2022-05-07  5:34 ` [PATCH 3/5] perf evsel: Add tool event helpers Ian Rogers
2022-05-09 13:16   ` Arnaldo Carvalho de Melo [this message]
2022-05-07  5:34 ` [PATCH 4/5] perf metrics: Support all tool events Ian Rogers
2022-05-07  5:34 ` [PATCH 5/5] perf metrics: Don't add all tool events for sharing Ian Rogers

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=YnkUM32sISfq1fad@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=florian.fischer@muhq.space \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=john.garry@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=kim.phillips@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=nakamura.shun@fujitsu.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rickyman7@gmail.com \
    --cc=zhengjun.xing@linux.intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).