diff options
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/hist.c | 126 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 5 | ||||
-rw-r--r-- | tools/perf/util/sort.c | 11 | ||||
-rw-r--r-- | tools/perf/util/sort.h | 2 |
4 files changed, 119 insertions, 25 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 6e416a62e0d..ecf853cdc0b 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -454,34 +454,80 @@ static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, return ret; } -static size_t hist_entry__fprintf(FILE *fp, struct hist_entry *self, - struct perf_session *session) +static size_t hist_entry__fprintf(struct hist_entry *self, + struct perf_session *session, + struct perf_session *pair_session, + bool show_displacement, + long displacement, FILE *fp) { struct sort_entry *se; + u64 count, total; + const char *sep = symbol_conf.field_sep; size_t ret; if (symbol_conf.exclude_other && !self->parent) return 0; - if (session->events_stats.total) - ret = percent_color_fprintf(fp, - symbol_conf.field_sep ? "%.2f" : " %6.2f%%", - (self->count * 100.0) / session->events_stats.total); + if (pair_session) { + count = self->pair ? self->pair->count : 0; + total = pair_session->events_stats.total; + } else { + count = self->count; + total = session->events_stats.total; + } + + if (total) + ret = percent_color_fprintf(fp, sep ? "%.2f" : " %6.2f%%", + (count * 100.0) / total); else - ret = fprintf(fp, symbol_conf.field_sep ? "%lld" : "%12lld ", self->count); + ret = fprintf(fp, sep ? "%lld" : "%12lld ", count); if (symbol_conf.show_nr_samples) { - if (symbol_conf.field_sep) - fprintf(fp, "%c%lld", *symbol_conf.field_sep, self->count); + if (sep) + fprintf(fp, "%c%lld", *sep, count); else - fprintf(fp, "%11lld", self->count); + fprintf(fp, "%11lld", count); + } + + if (pair_session) { + char bf[32]; + double old_percent = 0, new_percent = 0, diff; + + if (total > 0) + old_percent = (count * 100) / total; + if (session->events_stats.total > 0) + new_percent = (self->count * 100) / session->events_stats.total; + + diff = old_percent - new_percent; + + if ((u64)diff != 0) + snprintf(bf, sizeof(bf), "%+4.2F%%", diff); + else + snprintf(bf, sizeof(bf), " "); + + if (sep) + ret += fprintf(fp, "%c%s", *sep, bf); + else + ret += fprintf(fp, "%11.11s", bf); + + if (show_displacement) { + if (displacement) + snprintf(bf, sizeof(bf), "%+4ld", displacement); + else + snprintf(bf, sizeof(bf), " "); + + if (sep) + fprintf(fp, "%c%s", *sep, bf); + else + fprintf(fp, "%6.6s", bf); + } } list_for_each_entry(se, &hist_entry__sort_list, list) { if (se->elide) continue; - fprintf(fp, "%s", symbol_conf.field_sep ?: " "); + fprintf(fp, "%s", sep ?: " "); ret += se->print(fp, self, se->width ? *se->width : 0); } @@ -504,29 +550,49 @@ static size_t hist_entry__fprintf(FILE *fp, struct hist_entry *self, return ret; } -size_t perf_session__fprintf_hists(struct perf_session *self, FILE *fp) +size_t perf_session__fprintf_hists(struct perf_session *self, + struct perf_session *pair, + bool show_displacement, FILE *fp) { - struct hist_entry *pos; struct sort_entry *se; struct rb_node *nd; size_t ret = 0; + unsigned long position = 1; + long displacement = 0; unsigned int width; + const char *sep = symbol_conf.field_sep; char *col_width = symbol_conf.col_width_list_str; init_rem_hits(); - fprintf(fp, "# Overhead"); + fprintf(fp, "# %s", pair ? "Baseline" : "Overhead"); + if (symbol_conf.show_nr_samples) { - if (symbol_conf.field_sep) - fprintf(fp, "%cSamples", *symbol_conf.field_sep); + if (sep) + fprintf(fp, "%cSamples", *sep); else fputs(" Samples ", fp); } + + if (pair) { + if (sep) + ret += fprintf(fp, "%cDelta", *sep); + else + ret += fprintf(fp, " Delta "); + + if (show_displacement) { + if (sep) + ret += fprintf(fp, "%cDisplacement", *sep); + else + ret += fprintf(fp, " Displ"); + } + } + list_for_each_entry(se, &hist_entry__sort_list, list) { if (se->elide) continue; - if (symbol_conf.field_sep) { - fprintf(fp, "%c%s", *symbol_conf.field_sep, se->header); + if (sep) { + fprintf(fp, "%c%s", *sep, se->header); continue; } width = strlen(se->header); @@ -545,12 +611,17 @@ size_t perf_session__fprintf_hists(struct perf_session *self, FILE *fp) } fprintf(fp, "\n"); - if (symbol_conf.field_sep) + if (sep) goto print_entries; fprintf(fp, "# ........"); if (symbol_conf.show_nr_samples) fprintf(fp, " .........."); + if (pair) { + fprintf(fp, " .........."); + if (show_displacement) + fprintf(fp, " ....."); + } list_for_each_entry(se, &hist_entry__sort_list, list) { unsigned int i; @@ -565,14 +636,23 @@ size_t perf_session__fprintf_hists(struct perf_session *self, FILE *fp) for (i = 0; i < width; i++) fprintf(fp, "."); } - fprintf(fp, "\n"); - fprintf(fp, "#\n"); + fprintf(fp, "\n#\n"); print_entries: for (nd = rb_first(&self->hists); nd; nd = rb_next(nd)) { - pos = rb_entry(nd, struct hist_entry, rb_node); - ret += hist_entry__fprintf(fp, pos, self); + struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); + + if (show_displacement) { + if (h->pair != NULL) + displacement = ((long)h->pair->position - + (long)position); + else + displacement = 0; + ++position; + } + ret += hist_entry__fprintf(h, self, pair, show_displacement, + displacement, fp); } free(rem_sq_bracket); diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index c7ac78d93b0..e5f99b24048 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -21,6 +21,7 @@ void hist_entry__free(struct hist_entry *); void perf_session__output_resort(struct perf_session *self, u64 total_samples); void perf_session__collapse_resort(struct perf_session *self); -size_t perf_session__fprintf_hists(struct perf_session *self, FILE *fp); - +size_t perf_session__fprintf_hists(struct perf_session *self, + struct perf_session *pair, + bool show_displacement, FILE *fp); #endif /* __PERF_HIST_H */ diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index cff1c316fa9..cb0f327de9e 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -303,3 +303,14 @@ void setup_sorting(const char * const usagestr[], const struct option *opts) free(str); } + +void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list, + const char *list_name, FILE *fp) +{ + if (list && strlist__nr_entries(list) == 1) { + if (fp != NULL) + fprintf(fp, "# %s: %s\n", list_name, + strlist__entry(list, 0)->s); + self->elide = true; + } +} diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 925f083e1ee..753f9ea99fb 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -101,5 +101,7 @@ extern int64_t sort__sym_cmp(struct hist_entry *, struct hist_entry *); extern int64_t sort__parent_cmp(struct hist_entry *, struct hist_entry *); extern size_t sort__parent_print(FILE *, struct hist_entry *, unsigned int); extern int sort_dimension__add(const char *); +void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list, + const char *list_name, FILE *fp); #endif /* __PERF_SORT_H */ |