perf top: Fix -z option behavior
authorNamhyung Kim <namhyung@kernel.org>
Tue, 12 Aug 2014 08:16:05 +0000 (17:16 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 13 Aug 2014 20:28:07 +0000 (17:28 -0300)
The current -z option does almost nothing.  It doesn't zero the existing
samples so that we can see profiles of exited process after last
refresh.  It seems it only affects annotation.

This patch clears existing entries before processing if -z option is
given.  For this original decaying logic also moved before processing.

Reported-by: Stephane Eranian <eranian@google.com>
Tested-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1407831366-28892-1-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-top.c
tools/perf/util/hist.c
tools/perf/util/hist.h

index 4b0e15c2b2a835d0930c5ac7e739300cb8006cc3..87a6615a40faa06f8bece3b3e44ed4b177537bef 100644 (file)
@@ -276,11 +276,17 @@ static void perf_top__print_sym_table(struct perf_top *top)
                return;
        }
 
+       if (top->zero) {
+               hists__delete_entries(&top->sym_evsel->hists);
+       } else {
+               hists__decay_entries(&top->sym_evsel->hists,
+                                    top->hide_user_symbols,
+                                    top->hide_kernel_symbols);
+       }
+
        hists__collapse_resort(&top->sym_evsel->hists, NULL);
        hists__output_resort(&top->sym_evsel->hists);
-       hists__decay_entries(&top->sym_evsel->hists,
-                            top->hide_user_symbols,
-                            top->hide_kernel_symbols);
+
        hists__output_recalc_col_len(&top->sym_evsel->hists,
                                     top->print_entries - printed);
        putchar('\n');
@@ -542,11 +548,16 @@ static void perf_top__sort_new_samples(void *arg)
        if (t->evlist->selected != NULL)
                t->sym_evsel = t->evlist->selected;
 
+       if (t->zero) {
+               hists__delete_entries(&t->sym_evsel->hists);
+       } else {
+               hists__decay_entries(&t->sym_evsel->hists,
+                                    t->hide_user_symbols,
+                                    t->hide_kernel_symbols);
+       }
+
        hists__collapse_resort(&t->sym_evsel->hists, NULL);
        hists__output_resort(&t->sym_evsel->hists);
-       hists__decay_entries(&t->sym_evsel->hists,
-                            t->hide_user_symbols,
-                            t->hide_kernel_symbols);
 }
 
 static void *display_thread_tui(void *arg)
index 30df6187ee026acf0fb9f12013fbde891d3bdd70..86569fa3651d00a851e9e38da54df647cc6ba17c 100644 (file)
@@ -277,6 +277,28 @@ void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
        }
 }
 
+void hists__delete_entries(struct hists *hists)
+{
+       struct rb_node *next = rb_first(&hists->entries);
+       struct hist_entry *n;
+
+       while (next) {
+               n = rb_entry(next, struct hist_entry, rb_node);
+               next = rb_next(&n->rb_node);
+
+               rb_erase(&n->rb_node, &hists->entries);
+
+               if (sort__need_collapse)
+                       rb_erase(&n->rb_node_in, &hists->entries_collapsed);
+
+               --hists->nr_entries;
+               if (!n->filtered)
+                       --hists->nr_non_filtered_entries;
+
+               hist_entry__free(n);
+       }
+}
+
 /*
  * histogram, sorted on item, collects periods
  */
index 95405a8fbd9525484eeaae75e88897b7eb2fd20a..8c9c70e18cbbc353631d5fa283118c3f08725c0d 100644 (file)
@@ -152,6 +152,7 @@ void hists__output_resort(struct hists *hists);
 void hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
 
 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
+void hists__delete_entries(struct hists *hists);
 void hists__output_recalc_col_len(struct hists *hists, int max_rows);
 
 u64 hists__total_period(struct hists *hists);