OSDN Git Service

perf hists: Add support for showing relative percentage
authorNamhyung Kim <namhyung@kernel.org>
Thu, 26 Dec 2013 06:11:52 +0000 (15:11 +0900)
committerJiri Olsa <jolsa@redhat.com>
Wed, 16 Apr 2014 15:16:03 +0000 (17:16 +0200)
When filtering by thread, dso or symbol on TUI it also update total
period so that the output shows different result than no filter - the
percentage changed to relative to filtered entries only.  Sometimes
this is not desired since users might expect same results with filter.

So new filtered_* fields to hists->stats to count them separately.
They'll be controlled/used by user later.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1397145720-8063-2-git-send-email-namhyung@kernel.org
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
tools/perf/builtin-report.c
tools/perf/builtin-top.c
tools/perf/util/hist.c
tools/perf/util/hist.h

index c8f2113..2fca56c 100644 (file)
@@ -123,6 +123,8 @@ static int report__add_mem_hist_entry(struct report *rep, struct addr_location *
 
        evsel->hists.stats.total_period += cost;
        hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
+       if (!he->filtered)
+               evsel->hists.stats.nr_non_filtered_samples++;
        err = hist_entry__append_callchain(he, sample);
 out:
        return err;
@@ -176,6 +178,8 @@ static int report__add_branch_hist_entry(struct report *rep, struct addr_locatio
 
                        evsel->hists.stats.total_period += 1;
                        hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
+                       if (!he->filtered)
+                               evsel->hists.stats.nr_non_filtered_samples++;
                } else
                        goto out;
        }
@@ -209,6 +213,8 @@ static int report__add_hist_entry(struct report *rep, struct perf_evsel *evsel,
                err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
 
        evsel->hists.stats.total_period += sample->period;
+       if (!he->filtered)
+               evsel->hists.stats.nr_non_filtered_samples++;
        hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
 out:
        return err;
index 65aaa5b..2526901 100644 (file)
@@ -253,6 +253,9 @@ static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel,
                return NULL;
 
        hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
+       if (!he->filtered)
+               evsel->hists.stats.nr_non_filtered_samples++;
+
        return he;
 }
 
index f38590d..1ed3e2b 100644 (file)
@@ -674,8 +674,8 @@ void hists__output_resort(struct hists *hists)
        next = rb_first(root);
        hists->entries = RB_ROOT;
 
-       hists->nr_entries = 0;
-       hists->stats.total_period = 0;
+       hists->nr_entries = hists->nr_non_filtered_entries = 0;
+       hists->stats.total_period = hists->stats.total_non_filtered_period = 0;
        hists__reset_col_len(hists);
 
        while (next) {
@@ -695,11 +695,16 @@ static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h
                return;
 
        ++hists->nr_entries;
-       if (h->ms.unfolded)
+       ++hists->nr_non_filtered_entries;
+       if (h->ms.unfolded) {
                hists->nr_entries += h->nr_rows;
+               hists->nr_non_filtered_entries += h->nr_rows;
+       }
        h->row_offset = 0;
        hists->stats.total_period += h->stat.period;
+       hists->stats.total_non_filtered_period += h->stat.period;
        hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->stat.nr_events;
+       hists->stats.nr_non_filtered_samples += h->stat.nr_events;
 
        hists__calc_col_len(hists, h);
 }
@@ -722,7 +727,9 @@ void hists__filter_by_dso(struct hists *hists)
        struct rb_node *nd;
 
        hists->nr_entries = hists->stats.total_period = 0;
+       hists->nr_non_filtered_entries = hists->stats.total_non_filtered_period = 0;
        hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
+       hists->stats.nr_non_filtered_samples = 0;
        hists__reset_col_len(hists);
 
        for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
@@ -755,7 +762,9 @@ void hists__filter_by_thread(struct hists *hists)
        struct rb_node *nd;
 
        hists->nr_entries = hists->stats.total_period = 0;
+       hists->nr_non_filtered_entries = hists->stats.total_non_filtered_period = 0;
        hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
+       hists->stats.nr_non_filtered_samples = 0;
        hists__reset_col_len(hists);
 
        for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
@@ -786,7 +795,9 @@ void hists__filter_by_symbol(struct hists *hists)
        struct rb_node *nd;
 
        hists->nr_entries = hists->stats.total_period = 0;
+       hists->nr_non_filtered_entries = hists->stats.total_non_filtered_period = 0;
        hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
+       hists->stats.nr_non_filtered_samples = 0;
        hists__reset_col_len(hists);
 
        for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
index 1f1f513..2135514 100644 (file)
@@ -37,9 +37,11 @@ enum hist_filter {
  */
 struct events_stats {
        u64 total_period;
+       u64 total_non_filtered_period;
        u64 total_lost;
        u64 total_invalid_chains;
        u32 nr_events[PERF_RECORD_HEADER_MAX];
+       u32 nr_non_filtered_samples;
        u32 nr_lost_warned;
        u32 nr_unknown_events;
        u32 nr_invalid_chains;
@@ -83,6 +85,7 @@ struct hists {
        struct rb_root          entries;
        struct rb_root          entries_collapsed;
        u64                     nr_entries;
+       u64                     nr_non_filtered_entries;
        const struct thread     *thread_filter;
        const struct dso        *dso_filter;
        const char              *uid_filter_str;