From dd464345f330c1103f93daad309e8b44845e96cf Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:36 +0900 Subject: perf diff: Refactor diff displacement possition info Moving the position calculation into the diff command, so the position as prepared inside struct hist_entry data and there's no need to compute in the output display path. Removing 'displacement' from struct perf_hpp as it is no longer needed. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-3-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/stdio/hist.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'tools/perf/ui/stdio/hist.c') diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 882461a4283..d7405f064e8 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -308,7 +308,7 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he, static int hist_entry__fprintf(struct hist_entry *he, size_t size, struct hists *hists, struct hists *pair_hists, - long displacement, u64 total_period, FILE *fp) + u64 total_period, FILE *fp) { char bf[512]; int ret; @@ -316,7 +316,6 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, .buf = bf, .size = size, .total_period = total_period, - .displacement = displacement, .ptr = pair_hists, }; bool color = !symbol_conf.field_sep; @@ -337,15 +336,13 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, } size_t hists__fprintf(struct hists *hists, struct hists *pair, - bool show_displacement, bool show_header, int max_rows, + bool show_header, int max_rows, int max_cols, FILE *fp) { struct sort_entry *se; struct rb_node *nd; size_t ret = 0; u64 total_period; - unsigned long position = 1; - long displacement = 0; unsigned int width; const char *sep = symbol_conf.field_sep; const char *col_width = symbol_conf.col_width_list_str; @@ -449,15 +446,7 @@ print_entries: if (h->filtered) continue; - if (show_displacement) { - if (h->pair != NULL) - displacement = ((long)h->pair->position - - (long)position); - else - displacement = 0; - ++position; - } - ret += hist_entry__fprintf(h, max_cols, hists, pair, displacement, + ret += hist_entry__fprintf(h, max_cols, hists, pair, total_period, fp); if (max_rows && ++nr_rows >= max_rows) -- cgit v1.2.3-70-g09d2 From 5395a04841fcdd9220177f2c21353fe6d4cd0729 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:37 +0900 Subject: perf hists: Separate overhead and baseline columns Currently the overhead and baseline columns are handled within single function and the distinction is made by 'baseline hists' pointer passed by 'struct perf_hpp::ptr'. Since hists pointer is now part of each hist_entry, it's possible to locate paired hists pointer directly from the passed struct hist_entry pointer. Also separating those 2 columns makes the code more obvious. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-4-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/hist.c | 74 ++++++++++++++++++++++++++++++---------------- tools/perf/ui/stdio/hist.c | 11 +++++-- tools/perf/util/hist.h | 1 + 3 files changed, 58 insertions(+), 28 deletions(-) (limited to 'tools/perf/ui/stdio/hist.c') diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 55b9ca8f084..532a60177c3 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -8,9 +8,7 @@ /* hist period print (hpp) functions */ static int hpp__header_overhead(struct perf_hpp *hpp) { - const char *fmt = hpp->ptr ? "Baseline" : "Overhead"; - - return scnprintf(hpp->buf, hpp->size, fmt); + return scnprintf(hpp->buf, hpp->size, "Overhead"); } static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused) @@ -22,17 +20,6 @@ static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) { double percent = 100.0 * he->period / hpp->total_period; - if (hpp->ptr) { - struct hists *old_hists = hpp->ptr; - u64 total_period = old_hists->stats.total_period; - u64 base_period = he->pair ? he->pair->period : 0; - - if (total_period) - percent = 100.0 * base_period / total_period; - else - percent = 0.0; - } - return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); } @@ -41,17 +28,6 @@ static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) double percent = 100.0 * he->period / hpp->total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; - if (hpp->ptr) { - struct hists *old_hists = hpp->ptr; - u64 total_period = old_hists->stats.total_period; - u64 base_period = he->pair ? he->pair->period : 0; - - if (total_period) - percent = 100.0 * base_period / total_period; - else - percent = 0.0; - } - return scnprintf(hpp->buf, hpp->size, fmt, percent); } @@ -159,6 +135,47 @@ static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp, return scnprintf(hpp->buf, hpp->size, fmt, percent); } +static int hpp__header_baseline(struct perf_hpp *hpp) +{ + return scnprintf(hpp->buf, hpp->size, "Baseline"); +} + +static int hpp__width_baseline(struct perf_hpp *hpp __maybe_unused) +{ + return 8; +} + +static double baseline_percent(struct hist_entry *he) +{ + struct hist_entry *pair = he->pair; + struct hists *pair_hists = pair ? pair->hists : NULL; + double percent = 0.0; + + if (pair) { + u64 total_period = pair_hists->stats.total_period; + u64 base_period = pair->period; + + percent = 100.0 * base_period / total_period; + } + + return percent; +} + +static int hpp__color_baseline(struct perf_hpp *hpp, struct hist_entry *he) +{ + double percent = baseline_percent(he); + + return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); +} + +static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he) +{ + double percent = baseline_percent(he); + const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; + + return scnprintf(hpp->buf, hpp->size, fmt, percent); +} + static int hpp__header_samples(struct perf_hpp *hpp) { const char *fmt = symbol_conf.field_sep ? "%s" : "%11s"; @@ -269,6 +286,7 @@ static int hpp__entry_displ(struct perf_hpp *hpp, .entry = hpp__entry_ ## _name struct perf_hpp_fmt perf_hpp__format[] = { + { .cond = false, HPP__COLOR_PRINT_FNS(baseline) }, { .cond = true, HPP__COLOR_PRINT_FNS(overhead) }, { .cond = false, HPP__COLOR_PRINT_FNS(overhead_sys) }, { .cond = false, HPP__COLOR_PRINT_FNS(overhead_us) }, @@ -302,6 +320,8 @@ void perf_hpp__init(bool need_pair, bool show_displacement) perf_hpp__format[PERF_HPP__PERIOD].cond = true; if (need_pair) { + perf_hpp__format[PERF_HPP__OVERHEAD].cond = false; + perf_hpp__format[PERF_HPP__BASELINE].cond = true; perf_hpp__format[PERF_HPP__DELTA].cond = true; if (show_displacement) @@ -321,6 +341,7 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, const char *sep = symbol_conf.field_sep; char *start = hpp->buf; int i, ret; + bool first = true; if (symbol_conf.exclude_other && !he->parent) return 0; @@ -329,9 +350,10 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, if (!perf_hpp__format[i].cond) continue; - if (!sep || i > 0) { + if (!sep || !first) { ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " "); advance_hpp(hpp, ret); + first = false; } if (color && perf_hpp__format[i].color) diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index d7405f064e8..0aa6776caba 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -353,6 +353,7 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, .size = sizeof(bf), .ptr = pair, }; + bool first = true; init_rem_hits(); @@ -364,8 +365,10 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, if (!perf_hpp__format[idx].cond) continue; - if (idx) + if (!first) fprintf(fp, "%s", sep ?: " "); + else + first = false; perf_hpp__format[idx].header(&dummy_hpp); fprintf(fp, "%s", bf); @@ -400,6 +403,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, if (sep) goto print_entries; + first = true; + fprintf(fp, "# "); for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) { unsigned int i; @@ -407,8 +412,10 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, if (!perf_hpp__format[idx].cond) continue; - if (idx) + if (!first) fprintf(fp, "%s", sep ?: " "); + else + first = false; width = perf_hpp__format[idx].width(&dummy_hpp); for (i = 0; i < width; i++) diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index efb8fc8a4d2..b1a2b9d9b65 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -133,6 +133,7 @@ struct perf_hpp_fmt { extern struct perf_hpp_fmt perf_hpp__format[]; enum { + PERF_HPP__BASELINE, PERF_HPP__OVERHEAD, PERF_HPP__OVERHEAD_SYS, PERF_HPP__OVERHEAD_US, -- cgit v1.2.3-70-g09d2 From 41724e4cf6c443d2dc575669b8555f0e2ae427a9 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:38 +0900 Subject: perf tools: Removing hists pair argument from output path The hists pointer is now part of the 'struct hist_entry'. And since the overhead and baseline columns are split now, there's no reason to pass it through the output path. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-5-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-diff.c | 3 +-- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/hist.c | 9 +++++---- tools/perf/ui/stdio/hist.c | 10 +++------- tools/perf/util/hist.h | 4 ++-- 6 files changed, 13 insertions(+), 17 deletions(-) (limited to 'tools/perf/ui/stdio/hist.c') diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 5cb577a3c5b..413c65a1ba3 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -214,8 +214,7 @@ static int __cmd_diff(void) first = false; hists__match(&evsel_old->hists, &evsel->hists); - hists__fprintf(&evsel->hists, &evsel_old->hists, - true, 0, 0, stdout); + hists__fprintf(&evsel->hists, true, 0, 0, stdout); } out_delete: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 6748cac919d..95e7ea879b8 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -320,7 +320,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, const char *evname = perf_evsel__name(pos); hists__fprintf_nr_sample_events(hists, evname, stdout); - hists__fprintf(hists, NULL, true, 0, 0, stdout); + hists__fprintf(hists, true, 0, 0, stdout); fprintf(stdout, "\n\n"); } diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 357115874b7..ff6db808680 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -316,7 +316,7 @@ static void perf_top__print_sym_table(struct perf_top *top) hists__output_recalc_col_len(&top->sym_evsel->hists, top->winsize.ws_row - 3); putchar('\n'); - hists__fprintf(&top->sym_evsel->hists, NULL, false, + hists__fprintf(&top->sym_evsel->hists, false, top->winsize.ws_row - 4 - printed, win_width, stdout); } diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 532a60177c3..6b0138e5f33 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -228,16 +228,17 @@ static int hpp__width_delta(struct perf_hpp *hpp __maybe_unused) static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) { - struct hists *pair_hists = hpp->ptr; + struct hist_entry *pair = he->pair; + struct hists *pair_hists = pair ? pair->hists : NULL; u64 old_total, new_total; double old_percent = 0, new_percent = 0; double diff; const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s"; char buf[32] = " "; - old_total = pair_hists->stats.total_period; - if (old_total > 0 && he->pair) - old_percent = 100.0 * he->pair->period / old_total; + old_total = pair_hists ? pair_hists->stats.total_period : 0; + if (old_total > 0 && pair) + old_percent = 100.0 * pair->period / old_total; new_total = hpp->total_period; if (new_total > 0) diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 0aa6776caba..1340c93aa61 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -307,8 +307,7 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he, } static int hist_entry__fprintf(struct hist_entry *he, size_t size, - struct hists *hists, struct hists *pair_hists, - u64 total_period, FILE *fp) + struct hists *hists, u64 total_period, FILE *fp) { char bf[512]; int ret; @@ -316,7 +315,6 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, .buf = bf, .size = size, .total_period = total_period, - .ptr = pair_hists, }; bool color = !symbol_conf.field_sep; @@ -335,8 +333,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, return ret; } -size_t hists__fprintf(struct hists *hists, struct hists *pair, - bool show_header, int max_rows, +size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, int max_cols, FILE *fp) { struct sort_entry *se; @@ -351,7 +348,6 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, struct perf_hpp dummy_hpp = { .buf = bf, .size = sizeof(bf), - .ptr = pair, }; bool first = true; @@ -453,7 +449,7 @@ print_entries: if (h->filtered) continue; - ret += hist_entry__fprintf(h, max_cols, hists, pair, + ret += hist_entry__fprintf(h, max_cols, hists, total_period, fp); if (max_rows && ++nr_rows >= max_rows) diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index b1a2b9d9b65..b83a2268b5d 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -98,8 +98,8 @@ void hists__output_recalc_col_len(struct hists *hists, int max_rows); void hists__inc_nr_events(struct hists *self, u32 type); size_t hists__fprintf_nr_events(struct hists *self, FILE *fp); -size_t hists__fprintf(struct hists *self, struct hists *pair, - bool show_header, int max_rows, int max_cols, FILE *fp); +size_t hists__fprintf(struct hists *self, bool show_header, int max_rows, + int max_cols, FILE *fp); int hist_entry__inc_addr_samples(struct hist_entry *self, int evidx, u64 addr); int hist_entry__annotate(struct hist_entry *self, size_t privsize); -- cgit v1.2.3-70-g09d2 From b5ff71c3bab10a7a4b321b5de072ac5bd73ef9a4 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Oct 2012 21:49:40 +0900 Subject: perf diff: Removing the total_period argument from output code The total_period is available in struct hists data via the 'struct hist_entry::hists' pointer. There's no need to carry it through the output code path. Removing 'struct perf_hpp::total_period' pointer, because it's no longer needed. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-7-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/hists.c | 4 ++-- tools/perf/ui/gtk/browser.c | 4 ++-- tools/perf/ui/hist.c | 37 ++++++++++++++++++++++++++----------- tools/perf/ui/stdio/hist.c | 15 +++++---------- tools/perf/util/hist.h | 1 - 5 files changed, 35 insertions(+), 26 deletions(-) (limited to 'tools/perf/ui/stdio/hist.c') diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index bbd11c2f69d..d359795454d 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -569,7 +569,8 @@ static int hist_browser__show_callchain(struct hist_browser *browser, static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ - double percent = 100.0 * he->_field / hpp->total_period; \ + struct hists *hists = he->hists; \ + double percent = 100.0 * he->_field / hists->stats.total_period;\ *(double *)hpp->ptr = percent; \ return scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent); \ } @@ -624,7 +625,6 @@ static int hist_browser__show_entry(struct hist_browser *browser, struct perf_hpp hpp = { .buf = s, .size = sizeof(s), - .total_period = browser->hists->stats.total_period, }; ui_browser__gotorc(&browser->b, row, 0); diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c index 2bc08f6af71..3cbb1d622ed 100644 --- a/tools/perf/ui/gtk/browser.c +++ b/tools/perf/ui/gtk/browser.c @@ -49,7 +49,8 @@ static const char *perf_gtk__get_percent_color(double percent) static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ - double percent = 100.0 * he->_field / hpp->total_period; \ + struct hists *hists = he->hists; \ + double percent = 100.0 * he->_field / hists->stats.total_period; \ const char *markup; \ int ret = 0; \ \ @@ -102,7 +103,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) struct perf_hpp hpp = { .buf = s, .size = sizeof(s), - .total_period = hists->stats.total_period, }; nr_cols = 0; diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index e8853f7780a..7f043394bef 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -18,14 +18,16 @@ static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); } static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -45,13 +47,16 @@ static int hpp__width_overhead_sys(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_sys / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_sys / hists->stats.total_period; + return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); } static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_sys / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_sys / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -71,13 +76,16 @@ static int hpp__width_overhead_us(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_us / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_us / hists->stats.total_period; + return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); } static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_us / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_us / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -96,14 +104,17 @@ static int hpp__width_overhead_guest_sys(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_guest_sys / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_guest_sys / hists->stats.total_period; + return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); } static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_guest_sys / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_guest_sys / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -122,14 +133,17 @@ static int hpp__width_overhead_guest_us(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_guest_us(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_guest_us / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_guest_us / hists->stats.total_period; + return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); } static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp, struct hist_entry *he) { - double percent = 100.0 * he->period_guest_us / hpp->total_period; + struct hists *hists = he->hists; + double percent = 100.0 * he->period_guest_us / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -230,6 +244,7 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) { struct hist_entry *pair = he->pair; struct hists *pair_hists = pair ? pair->hists : NULL; + struct hists *hists = he->hists; u64 old_total, new_total; double old_percent = 0, new_percent = 0; double diff; @@ -240,7 +255,7 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) if (old_total > 0 && pair) old_percent = 100.0 * pair->period / old_total; - new_total = hpp->total_period; + new_total = hists->stats.total_period; if (new_total > 0) new_percent = 100.0 * he->period / new_total; diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 1340c93aa61..850c6d293f4 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -292,9 +292,10 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he, static size_t hist_entry__callchain_fprintf(struct hist_entry *he, struct hists *hists, - u64 total_period, FILE *fp) + FILE *fp) { int left_margin = 0; + u64 total_period = hists->stats.total_period; if (sort__first_dimension == SORT_COMM) { struct sort_entry *se = list_first_entry(&hist_entry__sort_list, @@ -307,14 +308,13 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he, } static int hist_entry__fprintf(struct hist_entry *he, size_t size, - struct hists *hists, u64 total_period, FILE *fp) + struct hists *hists, FILE *fp) { char bf[512]; int ret; struct perf_hpp hpp = { .buf = bf, .size = size, - .total_period = total_period, }; bool color = !symbol_conf.field_sep; @@ -327,8 +327,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, ret = fprintf(fp, "%s\n", bf); if (symbol_conf.use_callchain) - ret += hist_entry__callchain_fprintf(he, hists, - total_period, fp); + ret += hist_entry__callchain_fprintf(he, hists, fp); return ret; } @@ -339,7 +338,6 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, struct sort_entry *se; struct rb_node *nd; size_t ret = 0; - u64 total_period; unsigned int width; const char *sep = symbol_conf.field_sep; const char *col_width = symbol_conf.col_width_list_str; @@ -441,16 +439,13 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, goto out; print_entries: - total_period = hists->stats.total_period; - for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); if (h->filtered) continue; - ret += hist_entry__fprintf(h, max_cols, hists, - total_period, fp); + ret += hist_entry__fprintf(h, max_cols, hists, fp); if (max_rows && ++nr_rows >= max_rows) goto out; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index a7f69d69dc6..66cb31fe81d 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -117,7 +117,6 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *he); struct perf_hpp { char *buf; size_t size; - u64 total_period; const char *sep; void *ptr; }; -- cgit v1.2.3-70-g09d2 From b24c28f794e1821c1bba3ef7e9e948ab77ee00ac Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Thu, 4 Oct 2012 21:49:41 +0900 Subject: perf hists: Introduce struct he_stat The struct he_stat is for separating out statistics data of a hist entry. It is required for later changes. It's just a mechanical change and should have no functional differences. Signed-off-by: Namhyung Kim Cc: Arun Sharma Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Jiri Olsa Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1349354994-17853-8-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/hists.c | 8 +++---- tools/perf/ui/gtk/browser.c | 2 +- tools/perf/ui/hist.c | 30 ++++++++++++------------ tools/perf/ui/stdio/hist.c | 2 +- tools/perf/util/hist.c | 52 +++++++++++++++++++++++------------------- tools/perf/util/sort.h | 16 ++++++++----- 6 files changed, 59 insertions(+), 51 deletions(-) (limited to 'tools/perf/ui/stdio/hist.c') diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index d359795454d..0568536ecf6 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -570,7 +570,7 @@ static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ struct hists *hists = he->hists; \ - double percent = 100.0 * he->_field / hists->stats.total_period;\ + double percent = 100.0 * he->stat._field / hists->stats.total_period; \ *(double *)hpp->ptr = percent; \ return scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent); \ } @@ -982,7 +982,7 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser, folded_sign = hist_entry__folded(he); hist_entry__sort_snprintf(he, s, sizeof(s), browser->hists); - percent = (he->period * 100.0) / browser->hists->stats.total_period; + percent = (he->stat.period * 100.0) / browser->hists->stats.total_period; if (symbol_conf.use_callchain) printed += fprintf(fp, "%c ", folded_sign); @@ -990,10 +990,10 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser, printed += fprintf(fp, " %5.2f%%", percent); if (symbol_conf.show_nr_samples) - printed += fprintf(fp, " %11u", he->nr_events); + printed += fprintf(fp, " %11u", he->stat.nr_events); if (symbol_conf.show_total_period) - printed += fprintf(fp, " %12" PRIu64, he->period); + printed += fprintf(fp, " %12" PRIu64, he->stat.period); printed += fprintf(fp, "%s\n", rtrim(s)); diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c index 3cbb1d622ed..4125c628411 100644 --- a/tools/perf/ui/gtk/browser.c +++ b/tools/perf/ui/gtk/browser.c @@ -50,7 +50,7 @@ static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \ struct hist_entry *he) \ { \ struct hists *hists = he->hists; \ - double percent = 100.0 * he->_field / hists->stats.total_period; \ + double percent = 100.0 * he->stat._field / hists->stats.total_period; \ const char *markup; \ int ret = 0; \ \ diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 7f043394bef..f5a1e4f6526 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -19,7 +19,7 @@ static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period / hists->stats.total_period; + double percent = 100.0 * he->stat.period / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); } @@ -27,7 +27,7 @@ static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period / hists->stats.total_period; + double percent = 100.0 * he->stat.period / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -48,7 +48,7 @@ static int hpp__width_overhead_sys(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_sys / hists->stats.total_period; + double percent = 100.0 * he->stat.period_sys / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); } @@ -56,7 +56,7 @@ static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_sys / hists->stats.total_period; + double percent = 100.0 * he->stat.period_sys / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -77,7 +77,7 @@ static int hpp__width_overhead_us(struct perf_hpp *hpp __maybe_unused) static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_us / hists->stats.total_period; + double percent = 100.0 * he->stat.period_us / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); } @@ -85,7 +85,7 @@ static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_us / hists->stats.total_period; + double percent = 100.0 * he->stat.period_us / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -105,7 +105,7 @@ static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_guest_sys / hists->stats.total_period; + double percent = 100.0 * he->stat.period_guest_sys / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); } @@ -114,7 +114,7 @@ static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_guest_sys / hists->stats.total_period; + double percent = 100.0 * he->stat.period_guest_sys / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -134,7 +134,7 @@ static int hpp__color_overhead_guest_us(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_guest_us / hists->stats.total_period; + double percent = 100.0 * he->stat.period_guest_us / hists->stats.total_period; return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); } @@ -143,7 +143,7 @@ static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp, struct hist_entry *he) { struct hists *hists = he->hists; - double percent = 100.0 * he->period_guest_us / hists->stats.total_period; + double percent = 100.0 * he->stat.period_guest_us / hists->stats.total_period; const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; return scnprintf(hpp->buf, hpp->size, fmt, percent); @@ -167,7 +167,7 @@ static double baseline_percent(struct hist_entry *he) if (pair) { u64 total_period = pair_hists->stats.total_period; - u64 base_period = pair->period; + u64 base_period = pair->stat.period; percent = 100.0 * base_period / total_period; } @@ -206,7 +206,7 @@ static int hpp__entry_samples(struct perf_hpp *hpp, struct hist_entry *he) { const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%11" PRIu64; - return scnprintf(hpp->buf, hpp->size, fmt, he->nr_events); + return scnprintf(hpp->buf, hpp->size, fmt, he->stat.nr_events); } static int hpp__header_period(struct perf_hpp *hpp) @@ -225,7 +225,7 @@ static int hpp__entry_period(struct perf_hpp *hpp, struct hist_entry *he) { const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64; - return scnprintf(hpp->buf, hpp->size, fmt, he->period); + return scnprintf(hpp->buf, hpp->size, fmt, he->stat.period); } static int hpp__header_delta(struct perf_hpp *hpp) @@ -253,11 +253,11 @@ static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) old_total = pair_hists ? pair_hists->stats.total_period : 0; if (old_total > 0 && pair) - old_percent = 100.0 * pair->period / old_total; + old_percent = 100.0 * pair->stat.period / old_total; new_total = hists->stats.total_period; if (new_total > 0) - new_percent = 100.0 * he->period / new_total; + new_percent = 100.0 * he->stat.period / new_total; diff = new_percent - old_percent; if (fabs(diff) >= 0.01) diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 850c6d293f4..fbd4e32d074 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -271,7 +271,7 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he, { switch (callchain_param.mode) { case CHAIN_GRAPH_REL: - return callchain__fprintf_graph(fp, &he->sorted_chain, he->period, + return callchain__fprintf_graph(fp, &he->sorted_chain, he->stat.period, left_margin); break; case CHAIN_GRAPH_ABS: diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 040f34c79a5..3197f3f5001 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -135,16 +135,16 @@ static void hist_entry__add_cpumode_period(struct hist_entry *he, { switch (cpumode) { case PERF_RECORD_MISC_KERNEL: - he->period_sys += period; + he->stat.period_sys += period; break; case PERF_RECORD_MISC_USER: - he->period_us += period; + he->stat.period_us += period; break; case PERF_RECORD_MISC_GUEST_KERNEL: - he->period_guest_sys += period; + he->stat.period_guest_sys += period; break; case PERF_RECORD_MISC_GUEST_USER: - he->period_guest_us += period; + he->stat.period_guest_us += period; break; default: break; @@ -153,13 +153,13 @@ static void hist_entry__add_cpumode_period(struct hist_entry *he, static void hist_entry__decay(struct hist_entry *he) { - he->period = (he->period * 7) / 8; - he->nr_events = (he->nr_events * 7) / 8; + he->stat.period = (he->stat.period * 7) / 8; + he->stat.nr_events = (he->stat.nr_events * 7) / 8; } static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) { - u64 prev_period = he->period; + u64 prev_period = he->stat.period; if (prev_period == 0) return true; @@ -167,9 +167,9 @@ static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) hist_entry__decay(he); if (!he->filtered) - hists->stats.total_period -= prev_period - he->period; + hists->stats.total_period -= prev_period - he->stat.period; - return he->period == 0; + return he->stat.period == 0; } static void __hists__decay_entries(struct hists *hists, bool zap_user, @@ -223,7 +223,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template) if (he != NULL) { *he = *template; - he->nr_events = 1; + he->stat.nr_events = 1; if (he->ms.map) he->ms.map->referenced = true; if (symbol_conf.use_callchain) @@ -238,7 +238,7 @@ static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h) if (!h->filtered) { hists__calc_col_len(hists, h); ++hists->nr_entries; - hists->stats.total_period += h->period; + hists->stats.total_period += h->stat.period; } } @@ -270,8 +270,8 @@ static struct hist_entry *add_hist_entry(struct hists *hists, cmp = hist_entry__cmp(entry, he); if (!cmp) { - he->period += period; - ++he->nr_events; + he->stat.period += period; + ++he->stat.nr_events; /* If the map of an existing hist_entry has * become out-of-date due to an exec() or @@ -321,7 +321,9 @@ struct hist_entry *__hists__add_branch_entry(struct hists *self, .cpu = al->cpu, .ip = bi->to.addr, .level = al->level, - .period = period, + .stat = { + .period = period, + }, .parent = sym_parent, .filtered = symbol__parent_filter(sym_parent), .branch_info = bi, @@ -344,7 +346,9 @@ struct hist_entry *__hists__add_entry(struct hists *self, .cpu = al->cpu, .ip = al->addr, .level = al->level, - .period = period, + .stat = { + .period = period, + }, .parent = sym_parent, .filtered = symbol__parent_filter(sym_parent), .hists = self, @@ -412,12 +416,12 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, cmp = hist_entry__collapse(iter, he); if (!cmp) { - iter->period += he->period; - iter->period_sys += he->period_sys; - iter->period_us += he->period_us; - iter->period_guest_sys += he->period_guest_sys; - iter->period_guest_us += he->period_guest_us; - iter->nr_events += he->nr_events; + iter->stat.period += he->stat.period; + iter->stat.period_sys += he->stat.period_sys; + iter->stat.period_us += he->stat.period_us; + iter->stat.period_guest_sys += he->stat.period_guest_sys; + iter->stat.period_guest_us += he->stat.period_guest_us; + iter->stat.nr_events += he->stat.nr_events; if (symbol_conf.use_callchain) { callchain_cursor_reset(&callchain_cursor); @@ -520,7 +524,7 @@ static void __hists__insert_output_entry(struct rb_root *entries, parent = *p; iter = rb_entry(parent, struct hist_entry, rb_node); - if (he->period > iter->period) + if (he->stat.period > iter->stat.period) p = &(*p)->rb_left; else p = &(*p)->rb_right; @@ -581,8 +585,8 @@ static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h if (h->ms.unfolded) hists->nr_entries += h->nr_rows; h->row_offset = 0; - hists->stats.total_period += h->period; - hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; + hists->stats.total_period += h->stat.period; + hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->stat.nr_events; hists__calc_col_len(hists, h); } diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index f070b523c81..5786f323b59 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -43,6 +43,15 @@ extern struct sort_entry sort_sym_from; extern struct sort_entry sort_sym_to; extern enum sort_type sort__first_dimension; +struct he_stat { + u64 period; + u64 period_sys; + u64 period_us; + u64 period_guest_sys; + u64 period_guest_us; + u32 nr_events; +}; + /** * struct hist_entry - histogram entry * @@ -52,16 +61,11 @@ extern enum sort_type sort__first_dimension; struct hist_entry { struct rb_node rb_node_in; struct rb_node rb_node; - u64 period; - u64 period_sys; - u64 period_us; - u64 period_guest_sys; - u64 period_guest_us; + struct he_stat stat; struct map_symbol ms; struct thread *thread; u64 ip; s32 cpu; - u32 nr_events; /* XXX These two should move to some tree widget lib */ u16 row_offset; -- cgit v1.2.3-70-g09d2