public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/tool: remove newline char when reading event scale and unit
@ 2015-05-31  6:06 Madhavan Srinivasan
  2015-06-01 13:28 ` Arnaldo Carvalho de Melo
  2015-06-04 14:10 ` [tip:perf/core] perf tools: Remove " tip-bot for Madhavan Srinivasan
  0 siblings, 2 replies; 3+ messages in thread
From: Madhavan Srinivasan @ 2015-05-31  6:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Madhavan Srinivasan, Arnaldo Carvalho de Melo, Peter Zijlstra,
	Ingo Molnar, Jiri Olsa, Sukadev Bhattiprolu, Michael Ellerman

commit <fd979c013207> intruduced perf_event_sysfs_show function to display
event_str value of an attr in kernel/event/core.c. But the function returns
the value with a newline char. So, if a event also carries a event.unit file,
when printing the counter data perf tool formatting goes for a spin.
That is, because of the event unit, event name is printed in the newline
because of perf_event_sysfs_show returns with a newline char.

Now fixing perf core will break API, hencing proposing a fix in the perf tool.

Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
---
 tools/perf/util/pmu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 4841167..cf2cb34 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -112,7 +112,11 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *
 	if (sret < 0)
 		goto error;
 
-	scale[sret] = '\0';
+	if (scale[sret-1] == '\n')
+		scale[sret-1] = '\0';
+	else
+		scale[sret] = '\0';
+
 	/*
 	 * save current locale
 	 */
@@ -154,7 +158,10 @@ static int perf_pmu__parse_unit(struct perf_pmu_alias *alias, char *dir, char *n
 
 	close(fd);
 
-	alias->unit[sret] = '\0';
+	if (alias->unit[sret-1] == '\n')
+		alias->unit[sret-1] = '\0';
+	else
+		alias->unit[sret] = '\0';
 
 	return 0;
 error:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf/tool: remove newline char when reading event scale and unit
  2015-05-31  6:06 [PATCH] perf/tool: remove newline char when reading event scale and unit Madhavan Srinivasan
@ 2015-06-01 13:28 ` Arnaldo Carvalho de Melo
  2015-06-04 14:10 ` [tip:perf/core] perf tools: Remove " tip-bot for Madhavan Srinivasan
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-06-01 13:28 UTC (permalink / raw)
  To: Madhavan Srinivasan
  Cc: linux-kernel, Peter Zijlstra, Ingo Molnar, Jiri Olsa,
	Sukadev Bhattiprolu, Michael Ellerman

Em Sun, May 31, 2015 at 11:36:23AM +0530, Madhavan Srinivasan escreveu:
> commit <fd979c013207> intruduced perf_event_sysfs_show function to display
> event_str value of an attr in kernel/event/core.c. But the function returns
> the value with a newline char. So, if a event also carries a event.unit file,
> when printing the counter data perf tool formatting goes for a spin.
> That is, because of the event unit, event name is printed in the newline
> because of perf_event_sysfs_show returns with a newline char.
> 
> Now fixing perf core will break API, hencing proposing a fix in the perf tool.

Looks sensible, but please next time add spaces around operators, doing
it this time.

I.e., it should be:

		scale[sret - 1] = '\0';

Thanks,

- Arnaldo
  
> +	if (scale[sret-1] == '\n')
> +		scale[sret-1] = '\0';
> +	else
> +		scale[sret] = '\0';
> +
>  	/*
>  	 * save current locale
>  	 */
> @@ -154,7 +158,10 @@ static int perf_pmu__parse_unit(struct perf_pmu_alias *alias, char *dir, char *n
>  
>  	close(fd);
>  
> -	alias->unit[sret] = '\0';
> +	if (alias->unit[sret-1] == '\n')
> +		alias->unit[sret-1] = '\0';
> +	else
> +		alias->unit[sret] = '\0';
>  
>  	return 0;
>  error:
> -- 
> 1.9.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:perf/core] perf tools: Remove newline char when reading event scale and unit
  2015-05-31  6:06 [PATCH] perf/tool: remove newline char when reading event scale and unit Madhavan Srinivasan
  2015-06-01 13:28 ` Arnaldo Carvalho de Melo
@ 2015-06-04 14:10 ` tip-bot for Madhavan Srinivasan
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Madhavan Srinivasan @ 2015-06-04 14:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, tglx, acme, sukadev, mingo, peterz, linux-kernel, maddy,
	hpa, mpe

Commit-ID:  9ecae065f3295d7ea5e1c5492170a848ca255a46
Gitweb:     http://git.kernel.org/tip/9ecae065f3295d7ea5e1c5492170a848ca255a46
Author:     Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
AuthorDate: Sun, 31 May 2015 11:36:23 +0530
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 1 Jun 2015 10:26:19 -0300

perf tools: Remove newline char when reading event scale and unit

The <fd979c013207> commit intruduced the perf_event_sysfs_show function
to display the event_str value of an attr in kernel/event/core.c. But
the function returns the value with a newline char.

So, if a event also carries a event.unit file, when printing the counter
data perf tool formatting goes for a spin.

That is, because of the event unit, event name is printed in the newline
because of perf_event_sysfs_show returns with a newline char.

Now fixing perf core will break API, hencing proposing a fix in the perf tool.

Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1433052383-21802-1-git-send-email-maddy@linux.vnet.ibm.com
[ Add spaces around operators ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/pmu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 5d3ab7c..0fcc624 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -112,7 +112,11 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *
 	if (sret < 0)
 		goto error;
 
-	scale[sret] = '\0';
+	if (scale[sret - 1] == '\n')
+		scale[sret - 1] = '\0';
+	else
+		scale[sret] = '\0';
+
 	/*
 	 * save current locale
 	 */
@@ -154,7 +158,10 @@ static int perf_pmu__parse_unit(struct perf_pmu_alias *alias, char *dir, char *n
 
 	close(fd);
 
-	alias->unit[sret] = '\0';
+	if (alias->unit[sret - 1] == '\n')
+		alias->unit[sret - 1] = '\0';
+	else
+		alias->unit[sret] = '\0';
 
 	return 0;
 error:

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-04 14:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-31  6:06 [PATCH] perf/tool: remove newline char when reading event scale and unit Madhavan Srinivasan
2015-06-01 13:28 ` Arnaldo Carvalho de Melo
2015-06-04 14:10 ` [tip:perf/core] perf tools: Remove " tip-bot for Madhavan Srinivasan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox