static void print_summary(const char *filename) { struct sym_ext *sym_ext; struct rb_node *node; printf("\nSorted summary for file %s\n", filename); printf("----------------------------------------------\n\n"); if (RB_EMPTY_ROOT(&root_sym_ext)) { printf(" Nothing higher than %1.1f%%\n", MIN_GREEN); return; } node = rb_first(&root_sym_ext); while (node) { double percent; const char *color; char *path; sym_ext = rb_entry(node, struct sym_ext, node); percent = sym_ext->percent; color = get_percent_color(percent); path = sym_ext->path; color_fprintf(stdout, color, " %7.2f %s", percent, path); node = rb_next(node); } }
int percent_color_fprintf(FILE *fp, const char *fmt, double percent) { int r; const char *color; color = get_percent_color(percent); r = color_fprintf(fp, color, fmt, percent); return r; }
int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...) { va_list args; int len; double percent; const char *color; va_start(args, fmt); len = va_arg(args, int); percent = va_arg(args, double); va_end(args); color = get_percent_color(percent); return color_snprintf(bf, size, color, fmt, len, percent); }
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); }
static int parse_line(FILE *file, struct hist_entry *he, u64 len) { struct symbol *sym = he->sym; char *line = NULL, *tmp, *tmp2; static const char *prev_line; static const char *prev_color; unsigned int offset; size_t line_len; u64 start; s64 line_ip; int ret; char *c; if (getline(&line, &line_len, file) < 0) return -1; if (!line) return -1; c = strchr(line, '\n'); if (c) *c = 0; line_ip = -1; offset = 0; ret = -2; /* * Strip leading spaces: */ tmp = line; while (*tmp) { if (*tmp != ' ') break; tmp++; } if (*tmp) { /* * Parse hexa addresses followed by ':' */ line_ip = strtoull(tmp, &tmp2, 16); if (*tmp2 != ':') line_ip = -1; } start = he->map->unmap_ip(he->map, sym->start); if (line_ip != -1) { const char *path = NULL; unsigned int hits = 0; double percent = 0.0; const char *color; struct sym_priv *priv = symbol__priv(sym); struct sym_ext *sym_ext = priv->ext; struct sym_hist *h = priv->hist; offset = line_ip - start; if (offset < len) hits = h->ip[offset]; if (offset < len && sym_ext) { path = sym_ext[offset].path; percent = sym_ext[offset].percent; } else if (h->sum) percent = 100.0 * hits / h->sum; color = get_percent_color(percent); /* * Also color the filename and line if needed, with * the same color than the percentage. Don't print it * twice for close colored ip with the same filename:line */ if (path) { if (!prev_line || strcmp(prev_line, path) || color != prev_color) { color_fprintf(stdout, color, " %s", path); prev_line = path; prev_color = color; } } color_fprintf(stdout, color, " %7.2f", percent); printf(" : "); color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", line); } else { if (!*line) printf(" :\n"); else printf(" : %s\n", line); } return 0; }