random tiny perf fixes and cleanups
cover random tiny perf fixes and cleanups
Hello,
This is a patchset for what I found during a code review. As you can see all of these are simple few-liners. Please take a look and consider applying them.
Thanks.
Namhyung Kim (8):
perf report: Document '--call-graph' for optional print_limit argument perf symbols: Get rid of duplicated snprintf()
perf symbols: Fix error path on symbol__init()
perf tools: Fix a memory leak on perf_read_values_destroy perf tools: Remove stale git headlines from top comment perf events: Tidy up perf_event__preprocess_sample
perf report: Fix usage string
perf evlist: Fix error handling on perf_event__mmap
tools/perf/Documentation/perf-report.txt | 5 +++-- tools/perf/builtin-report.c | 8 ++++---- tools/perf/util/config.c | 7 ------- tools/perf/util/event.c | 13 +++++++------ tools/perf/util/evlist.c | 8 ++++++-- tools/perf/util/symbol.c | 11 +++-------- tools/perf/util/usage.c | 5 ----- tools/perf/util/values.c | 1 + 8 files changed, 24 insertions(+), 34 deletions(-)
--
1.7.6
PATCH 1/8 perf report: Document '--call-graph' for optional print_limit argument
The '--call-graph' command line option can receive undocumented optional print_limit argument. Besides, use strtoul() to parse the option since its type is u32.
--- tools/perf/Documentation/perf-report.txt | 5 +++-- tools/perf/builtin-report.c | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-report.txt +3 -2
@@ -80,9 +80,10 @@ OPTIONS --dump-raw-trace:: Dump raw trace in ASCII. --g [type,min,order]:: +-g [type,min[,limit],order]:: --call-graph:: - Display call chains using type, min percent threshold and order. + Display call chains using type, min percent threshold, optional print + limit and order. type can be either: - flat: single column, linear exposure of call chains. - graph: use a graph tree, displaying absolute overhead rates.
tools/perf/builtin-report.c +3 -3
@@ -407,7 +407,7 @@ parse_callchain_opt(const struct option *opt, const char *arg, int unset) goto setup;if (tok2[0 ] !='c' ) { - callchain_param.print_limit =strtod (tok2, &endptr); + callchain_param.print_limit =strtoul (tok2, &endptr,0 ); tok2 =strtok (NULL ,"," );if (!tok2) goto setup;
@@ -485,8 +485,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) "regex filter to identify parent, see: '--sort parent'"),OPT_BOOLEAN ('x' ,"exclude-other" , &symbol_conf.exclude_other,"Only display entries with parent-match" ), -OPT_CALLBACK_DEFAULT ('g' ,"call-graph" , &report,"output_type,min_percent, call_order" , -"Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold and callchain order. " +OPT_CALLBACK_DEFAULT ('g' ,"call-graph" , &report,"output_type,min_percent[,print_limit],call_order" , +"Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit and callchain order. " "Default: fractal,0.5,callee" , &parse_callchain_opt, callchain_default_opt),OPT_BOOLEAN ('G' ,"inverted" , &report.inverted_callchain, "alias for inverted call graph"),
Signature · 1 line
1.7.6
[tip:perf/core] perf report: Document '--call-graph' for optional print_limit argument
Commit-ID: 6581f6e35f7d0338f699fce660adb48e863f2b59 Gitweb: http://git.kernel.org/tip/6581f6e35f7d0338f699fce660adb48e863f2b59 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 13 Dec 2011 00:16:50 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 20 Dec 2011 13:28:13 -0200
perf report: Document '--call-graph' for optional print_limit argument
The '--call-graph' command line option can receive undocumented optional print_limit argument. Besides, use strtoul() to parse the option since its type is u32.
--- tools/perf/Documentation/perf-report.txt | 5 +++-- tools/perf/builtin-report.c | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-report.txt +3 -2
@@ -80,9 +80,10 @@ OPTIONS --dump-raw-trace:: Dump raw trace in ASCII. --g [type,min,order]:: +-g [type,min[,limit],order]:: --call-graph:: - Display call chains using type, min percent threshold and order. + Display call chains using type, min percent threshold, optional print + limit and order. type can be either: - flat: single column, linear exposure of call chains. - graph: use a graph tree, displaying absolute overhead rates.
tools/perf/builtin-report.c +3 -3
@@ -407,7 +407,7 @@ parse_callchain_opt(const struct option *opt, const char *arg, int unset) goto setup;if (tok2[0 ] !='c' ) { - callchain_param.print_limit =strtod (tok2, &endptr); + callchain_param.print_limit =strtoul (tok2, &endptr,0 ); tok2 =strtok (NULL ,"," );if (!tok2) goto setup;
@@ -485,8 +485,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) "regex filter to identify parent, see: '--sort parent'"),OPT_BOOLEAN ('x' ,"exclude-other" , &symbol_conf.exclude_other,"Only display entries with parent-match" ), -OPT_CALLBACK_DEFAULT ('g' ,"call-graph" , &report,"output_type,min_percent, call_order" , -"Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold and callchain order. " +OPT_CALLBACK_DEFAULT ('g' ,"call-graph" , &report,"output_type,min_percent[,print_limit],call_order" , +"Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit and callchain order. " "Default: fractal,0.5,callee" , &parse_callchain_opt, callchain_default_opt),OPT_BOOLEAN ('G' ,"inverted" , &report.inverted_callchain, "alias for inverted call graph"),
PATCH 2/8 perf symbols: Get rid of duplicated snprintf()
In reply to Namhyung KimThe 'path' is set on a upper line, don't need to do it again.
--- tools/perf/util/symbol.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)
tools/perf/util/symbol.c +1 -6
@@ -1757,7 +1757,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg,struct stat st;/*sshfs might return bad dent->d_type, so we have to stat*/ -sprintf (path,"%s/%s" , dir_name, dent->d_name); +snprintf (path,sizeof (path),"%s/%s" , dir_name, dent->d_name);if (stat (path, &st))continue ;
@@ -1766,8 +1766,6 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg, !strcmp(dent->d_name, ".."))continue ; -snprintf (path,sizeof (path),"%s/%s" , - dir_name, dent->d_name); ret =map_groups__set_modules_path_dir (mg, path);if (ret <0 ) goto out;
@@ -1788,9 +1786,6 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg,if (map ==NULL )continue ; -snprintf (path,sizeof (path),"%s/%s" , - dir_name, dent->d_name); - long_name =strdup (path);if (long_name ==NULL ) { ret =-1 ;
Signature · 1 line
1.7.6
[tip:perf/core] perf symbols: Get rid of duplicated snprintf()
Commit-ID: 2b600f9578852d12af59420011e3dadfaa58b043 Gitweb: http://git.kernel.org/tip/2b600f9578852d12af59420011e3dadfaa58b043 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 13 Dec 2011 00:16:51 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 20 Dec 2011 13:34:52 -0200
perf symbols: Get rid of duplicated snprintf()
The 'path' variable is set on a upper line, don't need to do it again.
--- tools/perf/util/symbol.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)
tools/perf/util/symbol.c +1 -6
@@ -1757,7 +1757,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg,struct stat st;/*sshfs might return bad dent->d_type, so we have to stat*/ -sprintf (path,"%s/%s" , dir_name, dent->d_name); +snprintf (path,sizeof (path),"%s/%s" , dir_name, dent->d_name);if (stat (path, &st))continue ;
@@ -1766,8 +1766,6 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg, !strcmp(dent->d_name, ".."))continue ; -snprintf (path,sizeof (path),"%s/%s" , - dir_name, dent->d_name); ret =map_groups__set_modules_path_dir (mg, path);if (ret <0 ) goto out;
@@ -1788,9 +1786,6 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg,if (map ==NULL )continue ; -snprintf (path,sizeof (path),"%s/%s" , - dir_name, dent->d_name); - long_name =strdup (path);if (long_name ==NULL ) { ret =-1 ;
PATCH 3/8 perf symbols: Fix error path on symbol__init()
In reply to Namhyung KimThe order of freeing comm_list and dso_list should be reversed.
--- tools/perf/util/symbol.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/symbol.c +2 -2
@@ -2604,10 +2604,10 @@ int symbol__init(void) symbol_conf.initialized = true;return 0 ; -out_free_dso_list: -strlist__delete (symbol_conf.dso_list); out_free_comm_list:strlist__delete (symbol_conf.comm_list); +out_free_dso_list: +strlist__delete (symbol_conf.dso_list);return -1 ; }
Signature · 1 line
1.7.6
[tip:perf/core] perf symbols: Fix error path on symbol__init()
Commit-ID: d74c896b7e3250a07f7d0315eecdd2ae1a7bc3c3 Gitweb: http://git.kernel.org/tip/d74c896b7e3250a07f7d0315eecdd2ae1a7bc3c3 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 13 Dec 2011 00:16:52 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 20 Dec 2011 13:40:27 -0200
perf symbols: Fix error path on symbol__init()
The order of freeing comm_list and dso_list should be reversed.
--- tools/perf/util/symbol.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/symbol.c +2 -2
@@ -2604,10 +2604,10 @@ int symbol__init(void) symbol_conf.initialized = true;return 0 ; -out_free_dso_list: -strlist__delete (symbol_conf.dso_list); out_free_comm_list:strlist__delete (symbol_conf.comm_list); +out_free_dso_list: +strlist__delete (symbol_conf.dso_list);return -1 ; }
PATCH 4/8 perf tools: Fix a memory leak on perf_read_values_destroy
In reply to Namhyung KimAfter freeing each elements of the @values->value, we should free itself too.
--- tools/perf/util/values.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
tools/perf/util/values.c +1 -0
@@ -32,6 +32,7 @@ void perf_read_values_destroy(struct perf_read_values *values)for (i =0 ; i < values->threads; i++)free (values->value[i]); +free (values->value);free (values->pid);free (values->tid);free (values->counterrawid);
Signature · 1 line
1.7.6
[tip:perf/core] perf tools: Fix a memory leak on perf_read_values_destroy
Commit-ID: 0161d82e9b740caa90f508138d1ae1b9d981b6d3 Gitweb: http://git.kernel.org/tip/0161d82e9b740caa90f508138d1ae1b9d981b6d3 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 13 Dec 2011 00:16:53 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 20 Dec 2011 13:41:34 -0200
perf tools: Fix a memory leak on perf_read_values_destroy
After freeing each elements of the @values->value, we should free itself too.
--- tools/perf/util/values.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
tools/perf/util/values.c +1 -0
@@ -32,6 +32,7 @@ void perf_read_values_destroy(struct perf_read_values *values)for (i =0 ; i < values->threads; i++)free (values->value[i]); +free (values->value);free (values->pid);free (values->tid);free (values->counterrawid);
PATCH 5/8 perf tools: Remove stale git headlines from top comment
In reply to Namhyung KimThese files are parts of PERF not GIT, although they're coming from there :)
--- tools/perf/util/config.c | 7 ------- tools/perf/util/usage.c | 5 ----- 2 files changed, 0 insertions(+), 12 deletions(-)
tools/perf/util/config.c +0 -7
@@ -1,10 +1,3 @@ -/* -* GIT - The information manager from hell -* -* Copyright (C) Linus Torvalds, 2005 -* Copyright (C) Johannes Schindelin, 2005 -* -*/ #include "util.h" #include "cache.h" #include "exec_cmd.h"
tools/perf/util/usage.c +0 -5
@@ -1,8 +1,3 @@ -/* -* GIT - The information manager from hell -* -* Copyright (C) Linus Torvalds, 2005 -*/ #include "util.h" static void report (const char *prefix,const char *err,va_list params)
Signature · 1 line
1.7.6
Re: [PATCH 5/8] perf tools: Remove stale git headlines from top comment
Hi,
Quoted 2 lines · Namhyung Kim
These files are parts of PERF not GIT, although they're coming from there :)
And for some reason, the Copyright vanishes with that? Just a question.
Ciao,
Johannes
Re: [PATCH 5/8] perf tools: Remove stale git headlines from top comment
Quoted 8 lines · Johannes Schindelin
Hi,
Quoted 2 lines · Namhyung Kim
These files are parts of PERF not GIT, although they're coming from there :)
And for some reason, the Copyright vanishes with that? Just a question.
No way does it vanish - we are proud of that heritage.
Kim, removing copyrights is a big no-no. Even if we wanted to do it (we don't) legally it can typically only be done when something has been 100% rewritten and independently authored - which is clearly not the case here.
Thanks,
Ingo
PATCH 5/8 perf tools: Remove stale git headlines from top comment
These files are part of PERF not GIT although they're come from there :)
---
v2: keep original copyright information. (sorry about that :)
tools/perf/util/config.c | 5 ++++- tools/perf/util/usage.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/config.c +4 -1
@@ -1,5 +1,8 @@/* -* GIT - The information manager from hell +* config.c +* +* Helper functions for parsing config items. +* Originally copied from GIT source. * * Copyright (C) Linus Torvalds, 2005 * Copyright (C) Johannes Schindelin, 2005
tools/perf/util/usage.c +4 -1
@@ -1,5 +1,8 @@/* -* GIT - The information manager from hell +* usage.c +* +* Various reporting routines. +* Originally copied from GIT source. * * Copyright (C) Linus Torvalds, 2005 */
Signature · 1 line
1.7.6
[tip:perf/core] perf tools: Remove stale git headlines from top comment
Commit-ID: 5f9273d64a5ccbd3c2b4446cc8b71123ed5d6366 Gitweb: http://git.kernel.org/tip/5f9273d64a5ccbd3c2b4446cc8b71123ed5d6366 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 13 Dec 2011 22:52:03 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 20 Dec 2011 13:43:36 -0200
perf tools: Remove stale git headlines from top comment
These files are part of PERF not GIT although they're come from there :)
--- tools/perf/util/config.c | 5 ++++- tools/perf/util/usage.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/config.c +4 -1
@@ -1,5 +1,8 @@/* -* GIT - The information manager from hell +* config.c +* +* Helper functions for parsing config items. +* Originally copied from GIT source. * * Copyright (C) Linus Torvalds, 2005 * Copyright (C) Johannes Schindelin, 2005
tools/perf/util/usage.c +4 -1
@@ -1,5 +1,8 @@/* -* GIT - The information manager from hell +* usage.c +* +* Various reporting routines. +* Originally copied from GIT source. * * Copyright (C) Linus Torvalds, 2005 */
PATCH 6/8 perf events: Tidy up perf_event__preprocess_sample
In reply to Namhyung KimUse local variable 'dso' to reduce typing a bit and rearrange the if condition. Also NULL check of al->map in the condition is not necessary.
--- tools/perf/util/event.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
tools/perf/util/event.c +7 -6
@@ -814,13 +814,14 @@ int perf_event__preprocess_sample(const union perf_event *event, al->cpu = sample->cpu;if (al->map) { +struct dso *dso = al->map->dso; +if (symbol_conf.dso_list && - (!al->map || !al->map->dso || - !(strlist__has_entry (symbol_conf.dso_list, - al->map->dso->short_name) || - (al->map->dso->short_name != al->map->dso->long_name && -strlist__has_entry (symbol_conf.dso_list, - al->map->dso->long_name))))) + (!dso || !(strlist__has_entry (symbol_conf.dso_list, + dso->short_name) || + (dso->short_name != dso->long_name && +strlist__has_entry (symbol_conf.dso_list, + dso->long_name))))) goto out_filtered; al->sym =map__find_symbol (al->map, al->addr, filter);
Signature · 1 line
1.7.6
[tip:perf/core] perf events: Tidy up perf_event__preprocess_sample
Commit-ID: cb8f4e9aa37c469ddd80dda51469f327606c0118 Gitweb: http://git.kernel.org/tip/cb8f4e9aa37c469ddd80dda51469f327606c0118 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 13 Dec 2011 00:16:55 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 20 Dec 2011 13:50:59 -0200
perf events: Tidy up perf_event__preprocess_sample
Use local variable 'dso' to reduce typing a bit and rearrange the if condition. Also NULL check of al->map in the condition is not necessary.
--- tools/perf/util/event.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
tools/perf/util/event.c +7 -6
@@ -814,13 +814,14 @@ int perf_event__preprocess_sample(const union perf_event *event, al->cpu = sample->cpu;if (al->map) { +struct dso *dso = al->map->dso; +if (symbol_conf.dso_list && - (!al->map || !al->map->dso || - !(strlist__has_entry (symbol_conf.dso_list, - al->map->dso->short_name) || - (al->map->dso->short_name != al->map->dso->long_name && -strlist__has_entry (symbol_conf.dso_list, - al->map->dso->long_name))))) + (!dso || !(strlist__has_entry (symbol_conf.dso_list, + dso->short_name) || + (dso->short_name != dso->long_name && +strlist__has_entry (symbol_conf.dso_list, + dso->long_name))))) goto out_filtered; al->sym =map__find_symbol (al->map, al->addr, filter);
PATCH 7/8 perf report: Fix usage string
In reply to Namhyung Kimperf report does not take a command from command line.
--- tools/perf/builtin-report.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-report.c +1 -1
@@ -432,7 +432,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) {char callchain_default_opt[] ="fractal,0.5,callee" ;const char *const report_usage[] = { -"perf report [<options>] <command>" , +"perf report [<options>]" ,NULL };struct perf_report report = {
Signature · 1 line
1.7.6
[tip:perf/core] perf report: Fix usage string
Commit-ID: fb2baceb5a64990163e93b77ee205d0173202ee6 Gitweb: http://git.kernel.org/tip/fb2baceb5a64990163e93b77ee205d0173202ee6 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 13 Dec 2011 00:16:56 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 22 Dec 2011 10:23:55 -0200
perf report: Fix usage string
perf report does not take a command from command line.
--- tools/perf/builtin-report.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/builtin-report.c +1 -1
@@ -432,7 +432,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) {char callchain_default_opt[] ="fractal,0.5,callee" ;const char *const report_usage[] = { -"perf report [<options>] <command>" , +"perf report [<options>]" ,NULL };struct perf_report report = {
PATCH 8/8 perf evlist: Fix error handling on perf_event__mmap
In reply to Namhyung KimIf mmap syscall fails for some reason, @evlist->mmap->base wil have the value of MAP_FAILED. Since it is defined as -1, it'll cause a subsequent munmap failure, so the original errno will be lost. Fix it.
--- tools/perf/util/evlist.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/evlist.c +6 -2
@@ -487,7 +487,9 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m out_unmap:for (cpu =0 ; cpu < evlist->cpus->nr; cpu++) { -if (evlist->mmap[cpu].base !=NULL ) { +if (evlist->mmap[cpu].base ==MAP_FAILED ) { + evlist->mmap[cpu].base =NULL ; + }else if (evlist->mmap[cpu].base !=NULL ) {munmap (evlist->mmap[cpu].base, evlist->mmap_len); evlist->mmap[cpu].base =NULL ; }
@@ -526,7 +528,9 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in out_unmap:for (thread =0 ; thread < evlist->threads->nr; thread++) { -if (evlist->mmap[thread].base !=NULL ) { +if (evlist->mmap[thread].base ==MAP_FAILED ) { + evlist->mmap[thread].base =NULL ; + }else if (evlist->mmap[thread].base !=NULL ) {munmap (evlist->mmap[thread].base, evlist->mmap_len); evlist->mmap[thread].base =NULL ; }
Signature · 1 line
1.7.6
Em Tue, Dec 13, 2011 at 12:16:49AM +0900, Namhyung Kim escreveu:
Quoted 5 lines
Hello,
This is a patchset for what I found during a code review. As you can see all of these are simple few-liners. Please take a look and consider applying them.
Thanks a lot, all seems ok, will apply later today to my perf/core branch,
- Arnaldo
Quoted 25 lines
Thanks.
Namhyung Kim (8):
perf report: Document '--call-graph' for optionalprint_limitargument perf symbols: Get rid of duplicatedsnprintf()
perf symbols: Fix error path onsymbol__init()
perf tools: Fix a memory leak onperf_read_values_destroyperf tools: Remove stale git headlines from top comment perf events: Tidy upperf_event__preprocess_sample
perf report: Fix usage string
perf evlist: Fix error handling onperf_event__mmaptools/perf/Documentation/perf-report.txt | 5 +++-- tools/perf/builtin-report.c | 8 ++++---- tools/perf/util/config.c | 7 ------- tools/perf/util/event.c | 13 +++++++------ tools/perf/util/evlist.c | 8 ++++++-- tools/perf/util/symbol.c | 11 +++-------- tools/perf/util/usage.c | 5 ----- tools/perf/util/values.c | 1 + 8 files changed, 24 insertions(+), 34 deletions(-)--
1.7.6