perf session: Remove impossible condition check
PATCH 1/4 perf session: Remove impossible condition check
The 'size' cannot be 0 because it was set to 8 on the above line in case it was 0 and never changed.
--- tools/perf/util/session.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
tools/perf/util/session.c +1 -2
@@ -1004,8 +1004,7 @@ more: } } -if (size ==0 || - (skip =perf_session__process_event (self, &event, tool, head)) <0 ) { +if ((skip =perf_session__process_event (self, &event, tool, head)) <0 ) {dump_printf ("%#" PRIx64" [%#x]: skipping unknown header type: %d\n" , head, event.header.size, event.header.type);/*
Signature · 1 line
1.7.6
PATCH 2/4 perf stat: Introduce get_ratio_color() helper
The get_ratio_color() returns appropriate color string based on @ratio. It helps reducing code duplication.
--- tools/perf/builtin-stat.c | 91 +++++++++++++++++--------------------------- 1 files changed, 35 insertions(+), 56 deletions(-)
tools/perf/builtin-stat.c +35 -56
@@ -578,6 +578,33 @@ static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg) avg / avg_stats(&walltime_nsecs_stats)); } +/* used for get_ratio_color() */ +enum grc_type { +GRC_STALLED_CYCLES_FE , +GRC_STALLED_CYCLES_BE , +GRC_CACHE_MISSES , +GRC_MAX_NR +}; + +static const char *get_ratio_color (enum grc_type type,double ratio) +{ +static const double grc_table[GRC_MAX_NR ][3 ] = { + [GRC_STALLED_CYCLES_FE ] = {50.0 ,30.0 ,10.0 }, + [GRC_STALLED_CYCLES_BE ] = {75.0 ,50.0 ,20.0 }, + [GRC_CACHE_MISSES ] = {20.0 ,10.0 ,5.0 }, + }; +const char *color =PERF_COLOR_NORMAL ; + +if (ratio > grc_table[type][0 ]) + color =PERF_COLOR_RED ; +else if (ratio > grc_table[type][1 ]) + color =PERF_COLOR_MAGENTA ; +else if (ratio > grc_table[type][2 ]) + color =PERF_COLOR_YELLOW ; + +return color; +} +static void print_stalled_cycles_frontend (int cpu,struct perf_evsel *evsel__used ,double avg) {double total, ratio =0.0 ;
@@ -588,13 +615,7 @@ static void print_stalled_cycles_frontend(int cpu, struct perf_evsel *evsel __usif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >50.0 ) - color =PERF_COLOR_RED ; -else if (ratio >30.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >10.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_STALLED_CYCLES_FE , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -611,13 +632,7 @@ static void print_stalled_cycles_backend(int cpu, struct perf_evsel *evsel __useif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >75.0 ) - color =PERF_COLOR_RED ; -else if (ratio >50.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >20.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_STALLED_CYCLES_BE , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -634,13 +649,7 @@ static void print_branch_misses(int cpu, struct perf_evsel *evsel __used, doubleif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -657,13 +666,7 @@ static void print_l1_dcache_misses(int cpu, struct perf_evsel *evsel __used, douif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -680,13 +683,7 @@ static void print_l1_icache_misses(int cpu, struct perf_evsel *evsel __used, douif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -703,13 +700,7 @@ static void print_dtlb_cache_misses(int cpu, struct perf_evsel *evsel __used, doif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -726,13 +717,7 @@ static void print_itlb_cache_misses(int cpu, struct perf_evsel *evsel __used, doif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -749,13 +734,7 @@ static void print_ll_cache_misses(int cpu, struct perf_evsel *evsel __used, doubif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
Signature · 1 line
1.7.6
PATCH 3/4 perf top: Fix a memory leak
In reply to Namhyung KimThe 'buf' should be freed when symbol wasn't found too.
--- tools/perf/builtin-top.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
tools/perf/builtin-top.c +0 -1
@@ -351,7 +351,6 @@ static void perf_top__prompt_symbol(struct perf_top *top, const char *msg)if (!found) {fprintf (stderr,"Sorry, %s is not active.\n" , buf);sleep (1 ); -return ; }else perf_top__parse_source (top, found);
Signature · 1 line
1.7.6
PATCH 4/4 perf script: Kill script_spec__delete
In reply to Namhyung KimAs script_spec__delete() frees given struct script_spec it should not be called if we failed to allocate the struct. Also it's the only caller of the function, we can get rid of the function itself.
--- tools/perf/builtin-script.c | 13 +------------ 1 files changed, 1 insertions(+), 12 deletions(-)
tools/perf/builtin-script.c +1 -12
@@ -536,12 +536,6 @@ static struct script_spec *script_spec__new(const char *spec,return s; } -static void script_spec__delete (struct script_spec *s) -{ -free (s->spec); -free (s); -} -static void script_spec__add (struct script_spec *s) {list_add_tail (&s->node, &script_specs);
@@ -567,16 +561,11 @@ static struct script_spec *script_spec__findnew(const char *spec, s =script_spec__new (spec, ops);if (!s) - goto out_delete_spec; +return NULL ;script_spec__add (s);return s; - -out_delete_spec: -script_spec__delete (s); - -return NULL ; }int script_spec_register (const char *spec,struct scripting_ops *ops)
Signature · 1 line
1.7.6
Commit-ID: 29c9862f1b818bf4caa4c48a30dbe5f25c84ee08 Gitweb: http://git.kernel.org/tip/29c9862f1b818bf4caa4c48a30dbe5f25c84ee08 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 28 Dec 2011 00:35:48 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 3 Jan 2012 14:35:02 -0200
perf session: Remove impossible condition check
The 'size' cannot be 0 because it was set to 8 on the above line in case it was 0 and never changed.
--- tools/perf/util/session.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
tools/perf/util/session.c +1 -2
@@ -1015,8 +1015,7 @@ more: } } -if (size ==0 || - (skip =perf_session__process_event (self, &event, tool, head)) <0 ) { +if ((skip =perf_session__process_event (self, &event, tool, head)) <0 ) {dump_printf ("%#" PRIx64" [%#x]: skipping unknown header type: %d\n" , head, event.header.size, event.header.type);/*
[tip:perf/core] perf stat: Introduce get_ratio_color() helper
In reply to Namhyung KimCommit-ID: 15e6392feec311f1e409d77e1ccfe51c1d940365 Gitweb: http://git.kernel.org/tip/15e6392feec311f1e409d77e1ccfe51c1d940365 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 28 Dec 2011 00:35:49 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 3 Jan 2012 14:36:32 -0200
perf stat: Introduce get_ratio_color() helper
The get_ratio_color() returns appropriate color string based on @ratio. It helps reducing code duplication.
--- tools/perf/builtin-stat.c | 91 +++++++++++++++++--------------------------- 1 files changed, 35 insertions(+), 56 deletions(-)
tools/perf/builtin-stat.c +35 -56
@@ -578,6 +578,33 @@ static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg) avg / avg_stats(&walltime_nsecs_stats)); } +/* used for get_ratio_color() */ +enum grc_type { +GRC_STALLED_CYCLES_FE , +GRC_STALLED_CYCLES_BE , +GRC_CACHE_MISSES , +GRC_MAX_NR +}; + +static const char *get_ratio_color (enum grc_type type,double ratio) +{ +static const double grc_table[GRC_MAX_NR ][3 ] = { + [GRC_STALLED_CYCLES_FE ] = {50.0 ,30.0 ,10.0 }, + [GRC_STALLED_CYCLES_BE ] = {75.0 ,50.0 ,20.0 }, + [GRC_CACHE_MISSES ] = {20.0 ,10.0 ,5.0 }, + }; +const char *color =PERF_COLOR_NORMAL ; + +if (ratio > grc_table[type][0 ]) + color =PERF_COLOR_RED ; +else if (ratio > grc_table[type][1 ]) + color =PERF_COLOR_MAGENTA ; +else if (ratio > grc_table[type][2 ]) + color =PERF_COLOR_YELLOW ; + +return color; +} +static void print_stalled_cycles_frontend (int cpu,struct perf_evsel *evsel__used ,double avg) {double total, ratio =0.0 ;
@@ -588,13 +615,7 @@ static void print_stalled_cycles_frontend(int cpu, struct perf_evsel *evsel __usif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >50.0 ) - color =PERF_COLOR_RED ; -else if (ratio >30.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >10.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_STALLED_CYCLES_FE , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -611,13 +632,7 @@ static void print_stalled_cycles_backend(int cpu, struct perf_evsel *evsel __useif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >75.0 ) - color =PERF_COLOR_RED ; -else if (ratio >50.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >20.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_STALLED_CYCLES_BE , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -634,13 +649,7 @@ static void print_branch_misses(int cpu, struct perf_evsel *evsel __used, doubleif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -657,13 +666,7 @@ static void print_l1_dcache_misses(int cpu, struct perf_evsel *evsel __used, douif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -680,13 +683,7 @@ static void print_l1_icache_misses(int cpu, struct perf_evsel *evsel __used, douif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -703,13 +700,7 @@ static void print_dtlb_cache_misses(int cpu, struct perf_evsel *evsel __used, doif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -726,13 +717,7 @@ static void print_itlb_cache_misses(int cpu, struct perf_evsel *evsel __used, doif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
@@ -749,13 +734,7 @@ static void print_ll_cache_misses(int cpu, struct perf_evsel *evsel __used, doubif (total) ratio = avg / total *100.0 ; - color =PERF_COLOR_NORMAL ; -if (ratio >20.0 ) - color =PERF_COLOR_RED ; -else if (ratio >10.0 ) - color =PERF_COLOR_MAGENTA ; -else if (ratio >5.0 ) - color =PERF_COLOR_YELLOW ; + color =get_ratio_color (GRC_CACHE_MISSES , ratio);fprintf (output," # " );color_fprintf (output, color,"%6.2f%%" , ratio);
[tip:perf/core] perf top: Fix a memory leak
In reply to Namhyung KimCommit-ID: 057a174a064f68bac042d618ce3c6ea3ccd9a8aa Gitweb: http://git.kernel.org/tip/057a174a064f68bac042d618ce3c6ea3ccd9a8aa Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 28 Dec 2011 00:35:50 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 3 Jan 2012 14:37:19 -0200
perf top: Fix a memory leak
The 'buf' should be freed when symbol wasn't found too.
--- tools/perf/builtin-top.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
tools/perf/builtin-top.c +0 -1
@@ -351,7 +351,6 @@ static void perf_top__prompt_symbol(struct perf_top *top, const char *msg)if (!found) {fprintf (stderr,"Sorry, %s is not active.\n" , buf);sleep (1 ); -return ; }else perf_top__parse_source (top, found);
[tip:perf/core] perf script: Kill script_spec__delete
In reply to Namhyung KimCommit-ID: 466e2876bcb9ddc9b92502c46689679bee7d72a0 Gitweb: http://git.kernel.org/tip/466e2876bcb9ddc9b92502c46689679bee7d72a0 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 28 Dec 2011 00:35:51 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 3 Jan 2012 15:06:34 -0200
perf script: Kill script_spec__delete
As script_spec__delete() frees given struct script_spec it should not be called if we failed to allocate the struct. Also it's the only caller of the function, we can get rid of the function itself.
--- tools/perf/builtin-script.c | 13 +------------ 1 files changed, 1 insertions(+), 12 deletions(-)
tools/perf/builtin-script.c +1 -12
@@ -536,12 +536,6 @@ static struct script_spec *script_spec__new(const char *spec,return s; } -static void script_spec__delete (struct script_spec *s) -{ -free (s->spec); -free (s); -} -static void script_spec__add (struct script_spec *s) {list_add_tail (&s->node, &script_specs);
@@ -567,16 +561,11 @@ static struct script_spec *script_spec__findnew(const char *spec, s =script_spec__new (spec, ops);if (!s) - goto out_delete_spec; +return NULL ;script_spec__add (s);return s; - -out_delete_spec: -script_spec__delete (s); - -return NULL ; }int script_spec_register (const char *spec,struct scripting_ops *ops)