Merge branch 'bcache-for-3.14' of git://evilpiepirate.org/~kent/linux-bcache into...
[cascardo/linux.git] / tools / perf / util / color.c
index 66e44a5..87b8672 100644 (file)
@@ -1,6 +1,7 @@
 #include <linux/kernel.h>
 #include "cache.h"
 #include "color.h"
+#include <math.h>
 
 int perf_use_color_default = -1;
 
@@ -298,10 +299,10 @@ const char *get_percent_color(double percent)
         * entries in green - and keep the low overhead places
         * normal:
         */
-       if (percent >= MIN_RED)
+       if (fabs(percent) >= MIN_RED)
                color = PERF_COLOR_RED;
        else {
-               if (percent > MIN_GREEN)
+               if (fabs(percent) > MIN_GREEN)
                        color = PERF_COLOR_GREEN;
        }
        return color;
@@ -318,15 +319,19 @@ int percent_color_fprintf(FILE *fp, const char *fmt, double percent)
        return r;
 }
 
+int value_color_snprintf(char *bf, size_t size, const char *fmt, double value)
+{
+       const char *color = get_percent_color(value);
+       return color_snprintf(bf, size, color, fmt, value);
+}
+
 int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...)
 {
        va_list args;
        double percent;
-       const char *color;
 
        va_start(args, fmt);
        percent = va_arg(args, double);
        va_end(args);
-       color = get_percent_color(percent);
-       return color_snprintf(bf, size, color, fmt, percent);
+       return value_color_snprintf(bf, size, fmt, percent);
 }