Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1501062

Re: [PATCH 01/10] perf, tools: Factor out scale conversion code

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH 01/10] perf, tools: Factor out scale conversion code
Date 2016-10-14 17:40 +0200
Message-ID <sscKu-36Y-1@gated-at.bofh.it> (permalink)
References <srVzX-qJ-3@gated-at.bofh.it> <srVzY-qJ-35@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Em Thu, Oct 13, 2016 at 02:15:23PM -0700, Andi Kleen escreveu:
> From: Andi Kleen <ak@linux.intel.com>
> 
> Move the scale factor parsing code to an own function
> to reuse it in an upcoming patch.
> 
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
>  tools/perf/util/pmu.c | 64 +++++++++++++++++++++++++++------------------------
>  1 file changed, 34 insertions(+), 30 deletions(-)
> 
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index b1474dcadfa2..9adae7e7477c 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -94,32 +94,10 @@ static int pmu_format(const char *name, struct list_head *format)
>  	return 0;
>  }
>  
> -static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *name)
> +static double convert_scale(const char *scale, char **end)
>  {
> -	struct stat st;
> -	ssize_t sret;
> -	char scale[128];
> -	int fd, ret = -1;
> -	char path[PATH_MAX];
>  	char *lc;
> -
> -	snprintf(path, PATH_MAX, "%s/%s.scale", dir, name);
> -
> -	fd = open(path, O_RDONLY);
> -	if (fd == -1)
> -		return -1;
> -
> -	if (fstat(fd, &st) < 0)
> -		goto error;
> -
> -	sret = read(fd, scale, sizeof(scale)-1);
> -	if (sret < 0)
> -		goto error;
> -
> -	if (scale[sret - 1] == '\n')
> -		scale[sret - 1] = '\0';
> -	else
> -		scale[sret] = '\0';
> +	double sval;
>  
>  	/*
>  	 * save current locale
> @@ -132,10 +110,8 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *
>  	 * call below.
>  	 */
>  	lc = strdup(lc);
> -	if (!lc) {
> -		ret = -ENOMEM;
> -		goto error;
> -	}
> +	if (!lc)
> +		return 1.0;

So if we can't convert the scale because of an allocation failure
related to locale issues we silently trow it away and do no scale at
all?

- Arnaldo

>  
>  	/*
>  	 * force to C locale to ensure kernel
> @@ -144,13 +120,41 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *
>  	 */
>  	setlocale(LC_NUMERIC, "C");
>  
> -	alias->scale = strtod(scale, NULL);
> +	sval = strtod(scale, end);
>  
>  	/* restore locale */
>  	setlocale(LC_NUMERIC, lc);
> -
>  	free(lc);
> +	return sval;
> +}
> +
> +static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *name)
> +{
> +	struct stat st;
> +	ssize_t sret;
> +	char scale[128];
> +	int fd, ret = -1;
> +	char path[PATH_MAX];
> +
> +	snprintf(path, PATH_MAX, "%s/%s.scale", dir, name);
> +
> +	fd = open(path, O_RDONLY);
> +	if (fd == -1)
> +		return -1;
> +
> +	if (fstat(fd, &st) < 0)
> +		goto error;
> +
> +	sret = read(fd, scale, sizeof(scale)-1);
> +	if (sret < 0)
> +		goto error;
> +
> +	if (scale[sret - 1] == '\n')
> +		scale[sret - 1] = '\0';
> +	else
> +		scale[sret] = '\0';
>  
> +	alias->scale = convert_scale(scale, NULL);
>  	ret = 0;
>  error:
>  	close(fd);
> -- 
> 2.5.5

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Support Intel uncore event lists Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
  [PATCH 07/10] perf, tools: Collapse identically named events in perf stat Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
    Re: [PATCH 07/10] perf, tools: Collapse identically named events in  perf stat Jiri Olsa <jolsa@redhat.com> - 2016-10-17 13:00 +0200
    Re: [PATCH 07/10] perf, tools: Collapse identically named events in  perf stat Jiri Olsa <jolsa@redhat.com> - 2016-10-17 13:30 +0200
      Re: [PATCH 07/10] perf, tools: Collapse identically named events in  perf stat Andi Kleen <andi@firstfloor.org> - 2016-10-17 18:40 +0200
        Re: [PATCH 07/10] perf, tools: Collapse identically named events in  perf stat Jiri Olsa <jolsa@redhat.com> - 2016-10-17 19:30 +0200
          Re: [PATCH 07/10] perf, tools: Collapse identically named events in  perf stat Andi Kleen <ak@linux.intel.com> - 2016-10-17 20:20 +0200
    Re: [PATCH 07/10] perf, tools: Collapse identically named events in  perf stat Jiri Olsa <jolsa@redhat.com> - 2016-10-17 13:30 +0200
  [PATCH 08/10] perf, tools: Expand PMU events by prefix match Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
    Re: [PATCH 08/10] perf, tools: Expand PMU events by prefix match Jiri Olsa <jolsa@redhat.com> - 2016-10-17 13:40 +0200
    Re: [PATCH 08/10] perf, tools: Expand PMU events by prefix match Jiri Olsa <jolsa@redhat.com> - 2016-10-17 13:50 +0200
      Re: [PATCH 08/10] perf, tools: Expand PMU events by prefix match Andi Kleen <andi@firstfloor.org> - 2016-10-17 19:20 +0200
        Re: [PATCH 08/10] perf, tools: Expand PMU events by prefix match Jiri Olsa <jolsa@redhat.com> - 2016-10-17 19:30 +0200
  [PATCH 02/10] perf, tools: Only print Using CPUID message once Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
    Re: [PATCH 02/10] perf, tools: Only print Using CPUID message once Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-14 17:50 +0200
    [tip:perf/core] perf pmu: Only print Using CPUID message once tip-bot for Andi Kleen <tipbot@zytor.com> - 2016-10-24 21:10 +0200
  [PATCH 09/10] perf, tools: Support DividedBy header in JSON event list Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
    Re: [PATCH 09/10] perf, tools: Support DividedBy header in JSON  event list Jiri Olsa <jolsa@redhat.com> - 2016-10-17 13:50 +0200
      Re: [PATCH 09/10] perf, tools: Support DividedBy header in JSON  event list Andi Kleen <andi@firstfloor.org> - 2016-10-17 18:30 +0200
        Re: [PATCH 09/10] perf, tools: Support DividedBy header in JSON  event list Jiri Olsa <jolsa@redhat.com> - 2016-10-17 19:50 +0200
        Re: [PATCH 09/10] perf, tools: Support DividedBy header in JSON  event list Jiri Olsa <jolsa@redhat.com> - 2016-10-17 19:50 +0200
          Re: [PATCH 09/10] perf, tools: Support DividedBy header in JSON  event list Andi Kleen <andi@firstfloor.org> - 2016-10-17 20:30 +0200
  [PATCH 04/10] perf, tools: Support per pmu json aliases Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
    Re: [PATCH 04/10] perf, tools: Support per pmu json aliases Jiri Olsa <jolsa@redhat.com> - 2016-10-14 14:40 +0200
  [PATCH 05/10] perf, tools: Support event aliases for non cpu// pmus Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
    Re: [PATCH 05/10] perf, tools: Support event aliases for non cpu//  pmus Jiri Olsa <jolsa@redhat.com> - 2016-10-17 11:40 +0200
    Re: [PATCH 05/10] perf, tools: Support event aliases for non cpu//  pmus Jiri Olsa <jolsa@redhat.com> - 2016-10-17 12:30 +0200
  [PATCH 01/10] perf, tools: Factor out scale conversion code Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
    Re: [PATCH 01/10] perf, tools: Factor out scale conversion code Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-14 17:40 +0200
      Re: [PATCH 01/10] perf, tools: Factor out scale conversion code Andi Kleen <andi@firstfloor.org> - 2016-10-14 17:50 +0200
        Re: [PATCH 01/10] perf, tools: Factor out scale conversion code Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-14 18:20 +0200
          Re: [PATCH 01/10] perf, tools: Factor out scale conversion code Andi Kleen <ak@linux.intel.com> - 2016-10-14 18:20 +0200
            Re: [PATCH 01/10] perf, tools: Factor out scale conversion code Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-14 18:30 +0200
              Re: [PATCH 01/10] perf, tools: Factor out scale conversion code Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-14 18:40 +0200
              Re: [PATCH 01/10] perf, tools: Factor out scale conversion code Andi Kleen <andi@firstfloor.org> - 2016-10-14 18:40 +0200
  [PATCH 10/10] perf, tools, stat: Output generic dividedby metric Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
  [PATCH 06/10] perf, tools: Add debug support for outputing alias string Andi Kleen <andi@firstfloor.org> - 2016-10-13 23:20 +0200
  Re: Support Intel uncore event lists Jiri Olsa <jolsa@redhat.com> - 2016-10-17 13:10 +0200

csiph-web