perf_counter tools: Provide helper to print percents color
Among perf annotate, perf report and perf top, we can find the common colored printing of percents according to the following rules: High overhead = > 5%, colored in red Mid overhead = > 0.5%, colored in green Low overhead = < 0.5%, default color Factorize these multiple checks in a single function named percent_color_fprintf() and also provide a get_percent_color() for sites which print percentages and other things at the same time. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Anton Blanchard <anton@samba.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> LKML-Reference: <1246558475-10624-2-git-send-email-fweisbec@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
committed by
Ingo Molnar
parent
c20ab37ef3
commit
1e11fd82d2
@@ -947,25 +947,10 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples)
|
||||
if (exclude_other && !self->parent)
|
||||
return 0;
|
||||
|
||||
if (total_samples) {
|
||||
double percent = self->count * 100.0 / total_samples;
|
||||
char *color = PERF_COLOR_NORMAL;
|
||||
|
||||
/*
|
||||
* We color high-overhead entries in red, mid-overhead
|
||||
* entries in green - and keep the low overhead places
|
||||
* normal:
|
||||
*/
|
||||
if (percent >= 5.0) {
|
||||
color = PERF_COLOR_RED;
|
||||
} else {
|
||||
if (percent >= 0.5)
|
||||
color = PERF_COLOR_GREEN;
|
||||
}
|
||||
|
||||
ret = color_fprintf(fp, color, " %6.2f%%",
|
||||
if (total_samples)
|
||||
ret = percent_color_fprintf(fp, " %6.2f%%",
|
||||
(self->count * 100.0) / total_samples);
|
||||
} else
|
||||
else
|
||||
ret = fprintf(fp, "%12Ld ", self->count);
|
||||
|
||||
list_for_each_entry(se, &hist_entry__sort_list, list) {
|
||||
|
Reference in New Issue
Block a user