perf top: Delete half-processed hist entries when exit
authorNamhyung Kim <namhyung@kernel.org>
Thu, 10 Dec 2015 07:53:20 +0000 (16:53 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 10 Dec 2015 18:56:58 +0000 (15:56 -0300)
After sample processing is done, hist entries are in both of
hists->entries and hists->entries_in (or hists->entries_collapsed).  So
I guess perf report does not have leaks on hists.

But for perf top, it's possible to have half-processed entries which are
only in hists->entries_in.  Eventually they will go to the
hists->entries and get freed but they cannot be deleted by current
hists__delete_entries().  This patch adds hists__delete_all_entries
function to delete those entries.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-and-Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1449734015-9148-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/hist.c

index 565ea35..56e97f5 100644 (file)
@@ -270,6 +270,8 @@ static void hists__delete_entry(struct hists *hists, struct hist_entry *he)
 
        if (sort__need_collapse)
                rb_erase(&he->rb_node_in, &hists->entries_collapsed);
+       else
+               rb_erase(&he->rb_node_in, hists->entries_in);
 
        --hists->nr_entries;
        if (!he->filtered)
@@ -1567,11 +1569,33 @@ static int hists_evsel__init(struct perf_evsel *evsel)
        return 0;
 }
 
+static void hists__delete_remaining_entries(struct rb_root *root)
+{
+       struct rb_node *node;
+       struct hist_entry *he;
+
+       while (!RB_EMPTY_ROOT(root)) {
+               node = rb_first(root);
+               rb_erase(node, root);
+
+               he = rb_entry(node, struct hist_entry, rb_node_in);
+               hist_entry__delete(he);
+       }
+}
+
+static void hists__delete_all_entries(struct hists *hists)
+{
+       hists__delete_entries(hists);
+       hists__delete_remaining_entries(&hists->entries_in_array[0]);
+       hists__delete_remaining_entries(&hists->entries_in_array[1]);
+       hists__delete_remaining_entries(&hists->entries_collapsed);
+}
+
 static void hists_evsel__exit(struct perf_evsel *evsel)
 {
        struct hists *hists = evsel__hists(evsel);
 
-       hists__delete_entries(hists);
+       hists__delete_all_entries(hists);
 }
 
 /*