Skip to content

Commit

Permalink
perf diff: Removing the total_period argument from output code
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Namhyung Kim <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
Jiri Olsa authored and acmel committed Oct 4, 2012
1 parent 1d77822 commit b5ff71c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
4 changes: 2 additions & 2 deletions tools/perf/ui/browsers/hists.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/ui/gtk/browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
\
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 26 additions & 11 deletions tools/perf/ui/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down
15 changes: 5 additions & 10 deletions tools/perf/ui/stdio/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tools/perf/util/hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit b5ff71c

Please sign in to comment.