Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753067AbbLICY1 (ORCPT ); Tue, 8 Dec 2015 21:24:27 -0500 Received: from mail9.hitachi.co.jp ([133.145.228.44]:50807 "EHLO mail9.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753071AbbLICSu (ORCPT ); Tue, 8 Dec 2015 21:18:50 -0500 X-AuditID: 85900ec0-9cdc8b9000001a57-af-56678f87a560 Subject: [PATCH perf/core 04/22] perf refcnt: refcnt shows summary per object From: Masami Hiramatsu To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Adrian Hunter , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Ingo Molnar , Namhyung Kim , Jiri Olsa Date: Wed, 09 Dec 2015 11:10:57 +0900 Message-ID: <20151209021057.10245.89483.stgit@localhost.localdomain> In-Reply-To: <20151209021047.10245.8918.stgit@localhost.localdomain> References: <20151209021047.10245.8918.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2260 Lines: 83 Report refcnt per object(class) summary numbers if any leaks exist, not only the total number. Signed-off-by: Masami Hiramatsu --- tools/perf/util/refcnt.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/perf/util/refcnt.c b/tools/perf/util/refcnt.c index e83e9a8..5348406 100644 --- a/tools/perf/util/refcnt.c +++ b/tools/perf/util/refcnt.c @@ -157,8 +157,48 @@ static void pr_refcnt_object(struct refcnt_object *ref) pr_refcnt_buffer(buf); } +#define REFCNT_STAT_NUM 16 +static struct refcnt_stat_entry { + int counter; + const char *name; +} stat_entry[REFCNT_STAT_NUM] = { {.name = "(others)"}, }; + +static struct refcnt_stat_entry *refcnt_stat__find_entry(const char *name) +{ + int i; + + if (!name) + goto last; + + for (i = 1; i < REFCNT_STAT_NUM; i++) + if (stat_entry[i].name) { + if (strcmp(stat_entry[i].name, name) == 0) + return &stat_entry[i]; + } else { + stat_entry[i].name = name; + return &stat_entry[i]; + } +last: + /* Here, it shorts the slot, let it fold to others */ + return &stat_entry[0]; +} + +static void pr_refcnt_stat(void) +{ + int i; + + for (i = 1; i < REFCNT_STAT_NUM && stat_entry[i].name; i++) + pr_warning(" \"%s\" leaks %d objects\n", + stat_entry[i].name, stat_entry[i].counter); + + if (stat_entry[0].counter) + pr_warning(" And others leak %d objects\n", + stat_entry[0].counter); +} + static void __attribute__((destructor)) refcnt__dump_unreclaimed(void) { + struct refcnt_stat_entry *ent; struct refcnt_object *ref, *n; int h, i = 0; @@ -174,11 +214,15 @@ found: pr_debug("==== [%d] ====\n", i); pr_refcnt_object(ref); } + ent = refcnt_stat__find_entry(ref->name); + if (ent) + ent->counter++; refcnt_object__delete(ref); i++; } pr_warning("REFCNT: Total %d objects are not reclaimed.\n", i); + pr_refcnt_stat(); if (!verbose) pr_warning(" To see all backtraces, rerun with -v option\n"); } -- 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/