perf/tool: remove newline char when reading event scale and unit
PATCH 1/1 perf/tool: remove newline char when reading event scale and unit
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.
--- tools/perf/util/pmu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/util/pmu.c +9 -2
@@ -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 *nclose (fd); - alias->unit[sret] ='\0' ; +if (alias->unit[sret-1 ] =='\n' ) + alias->unit[sret-1 ] ='\0' ; +else + alias->unit[sret] ='\0' ;return 0 ; error:
Signature · 1 line
1.9.1
Em Sun, May 31, 2015 at 11:36:23AM +0530, Madhavan Srinivasan escreveu:
Quoted 8 lines
commit <
fd979c013207> intruducedperf_event_sysfs_showfunction to displayevent_strvalue of an attr inkernel/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 ofperf_event_sysfs_showreturns 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
Quoted 22 lines
tools/perf/util/pmu.c +9
-1+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 *nclose (fd); - alias->unit[sret] ='\0' ; +if (alias->unit[sret-1 ] =='\n' ) + alias->unit[sret-1 ] ='\0' ; +else + alias->unit[sret] ='\0' ;return 0 ; error:Signature · 1 line
1.9.1
tip-bot for Madhavan Srinivasan
merge bot[tip:perf/core] perf tools: Remove newline char when reading event scale and unit
In reply to Madhavan Srinivasanperf tools: Remove newline char when reading event scale and unit
Commit-ID: 9ecae065f3295d7ea5e1c5492170a848ca255a46 Gitweb: http://git.kernel.org/tip/9ecae065f3295d7ea5e1c5492170a848ca255a46 Author: Madhavan Srinivasan <[email protected]> AuthorDate: Sun, 31 May 2015 11:36:23 +0530 Committer: Arnaldo Carvalho de Melo <[email protected]> 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.
--- tools/perf/util/pmu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/util/pmu.c +9 -2
@@ -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 *nclose (fd); - alias->unit[sret] ='\0' ; +if (alias->unit[sret -1 ] =='\n' ) + alias->unit[sret -1 ] ='\0' ; +else + alias->unit[sret] ='\0' ;return 0 ; error: