Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753140AbbLNIPr (ORCPT ); Mon, 14 Dec 2015 03:15:47 -0500 Received: from terminus.zytor.com ([198.137.202.10]:52191 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752740AbbLNIPp (ORCPT ); Mon, 14 Dec 2015 03:15:45 -0500 Date: Mon, 14 Dec 2015 00:15:10 -0800 From: tip-bot for Namhyung Kim Message-ID: Cc: adrian.hunter@intel.com, andi@firstfloor.org, a.p.zijlstra@chello.nl, fweisbec@gmail.com, namhyung@kernel.org, acme@redhat.com, masami.hiramatsu.pt@hitachi.com, hpa@zytor.com, tglx@linutronix.de, eranian@google.com, jolsa@redhat.com, mingo@kernel.org, dsahern@gmail.com, linux-kernel@vger.kernel.org Reply-To: jolsa@redhat.com, mingo@kernel.org, eranian@google.com, dsahern@gmail.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, hpa@zytor.com, namhyung@kernel.org, acme@redhat.com, masami.hiramatsu.pt@hitachi.com, adrian.hunter@intel.com, andi@firstfloor.org, fweisbec@gmail.com, a.p.zijlstra@chello.nl In-Reply-To: <1449734015-9148-2-git-send-email-namhyung@kernel.org> References: <1449734015-9148-2-git-send-email-namhyung@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf top: Delete half-processed hist entries when exit Git-Commit-ID: 61fa0e94ca6ab62db5e095a5528150bf9962196d X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3066 Lines: 87 Commit-ID: 61fa0e94ca6ab62db5e095a5528150bf9962196d Gitweb: http://git.kernel.org/tip/61fa0e94ca6ab62db5e095a5528150bf9962196d Author: Namhyung Kim AuthorDate: Thu, 10 Dec 2015 16:53:20 +0900 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 10 Dec 2015 15:56:58 -0300 perf top: Delete half-processed hist entries when exit 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 Tested-and-Acked-by: Masami Hiramatsu Cc: Adrian Hunter Cc: Andi Kleen Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1449734015-9148-2-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/hist.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 565ea35..56e97f5 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -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); } /* -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/