mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-23 07:01:23 +00:00
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:
parent
c20ab37ef3
commit
1e11fd82d2
5 changed files with 38 additions and 56 deletions
|
@ -242,4 +242,31 @@ int color_fwrite_lines(FILE *fp, const char *color,
|
|||
return 0;
|
||||
}
|
||||
|
||||
char *get_percent_color(double percent)
|
||||
{
|
||||
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 >= MIN_RED)
|
||||
color = PERF_COLOR_RED;
|
||||
else {
|
||||
if (percent > MIN_GREEN)
|
||||
color = PERF_COLOR_GREEN;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
int percent_color_fprintf(FILE *fp, const char *fmt, double percent)
|
||||
{
|
||||
int r;
|
||||
char *color;
|
||||
|
||||
color = get_percent_color(percent);
|
||||
r = color_fprintf(fp, color, fmt, percent);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
#define PERF_COLOR_CYAN "\033[36m"
|
||||
#define PERF_COLOR_BG_RED "\033[41m"
|
||||
|
||||
#define MIN_GREEN 0.5
|
||||
#define MIN_RED 5.0
|
||||
|
||||
/*
|
||||
* This variable stores the value of color.ui
|
||||
*/
|
||||
|
@ -32,5 +35,7 @@ void color_parse_mem(const char *value, int len, const char *var, char *dst);
|
|||
int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
|
||||
int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
|
||||
int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
|
||||
int percent_color_fprintf(FILE *fp, const char *fmt, double percent);
|
||||
char *get_percent_color(double percent);
|
||||
|
||||
#endif /* COLOR_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue