Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ static int __hpp__color_compare(struct perf_hpp_fmt *fmt,
diff = compute_delta(he, pair);

scnprintf(pfmt, 20, "%%%+d.2f%%%%", dfmt->header_width - 1);
return percent_color_snprintf(hpp->buf, hpp->size,
return delta_color_snprintf(hpp->buf, hpp->size,
pfmt, diff);
case COMPUTE_RATIO:
if (he->dummy)
Expand Down
21 changes: 21 additions & 0 deletions tools/perf/util/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,24 @@ int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...)
color = get_percent_color(percent);
return color_snprintf(bf, size, color, fmt, len, percent);
}

int delta_color_snprintf(char *bf, size_t size, const char *fmt, ...)
{
va_list args;
double diff, percent;
const char *color = PERF_COLOR_NORMAL;

va_start(args, fmt);
diff = va_arg(args, double);
va_end(args);

/* diff command printed second digit after the decimal point. */
percent = roundf(diff * 100) / 100;
if (percent < 0)
color = PERF_COLOR_BLUE;
else {
if (percent > 0)
color = PERF_COLOR_BG_RED;
}
return color_snprintf(bf, size, color, fmt, diff);
}
1 change: 1 addition & 0 deletions tools/perf/util/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int value_color_snprintf(char *bf, size_t size, const char *fmt, double value);
int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...);
int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...);
int percent_color_fprintf(FILE *fp, const char *fmt, double percent);
int delta_color_snprintf(char *bf, size_t size, const char *fmt, ...);
const char *get_percent_color(double percent);

#endif /* __PERF_COLOR_H */