From patchwork Wed Apr 12 08:37:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9676803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4475760383 for ; Wed, 12 Apr 2017 08:37:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37F552808C for ; Wed, 12 Apr 2017 08:37:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CC0128338; Wed, 12 Apr 2017 08:37:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5EE12808C for ; Wed, 12 Apr 2017 08:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752546AbdDLIh6 (ORCPT ); Wed, 12 Apr 2017 04:37:58 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34510 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752803AbdDLIhu (ORCPT ); Wed, 12 Apr 2017 04:37:50 -0400 Received: by mail-wm0-f68.google.com with SMTP id x75so4882977wma.1 for ; Wed, 12 Apr 2017 01:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PLJB4OGOCZePChKEuODo6SwkET65pzuzt0wKe9KIEHA=; b=lshUlORFzRi11wsljcjnjZASNuA53kSTc4ZfufupXBvQqVAmeMffH/xuIZ113pu9nl wWZR41fhG4DTNmBOumWTHhXn9bNxiz2Fz3gffqQjweHTsZMQhg2dxNlaF3opm/wtJ9my 10IiICxGSC3BS7iyHakBptfk8Ov80g/BMIsKmosdIawA0vj7W6IHbqyp6G1IwKPEavy3 +GZQzitlEkc6ULcKw2VDdR/6g0IteWFnU28kIs6uFquiHljfEySQP3POOam1pHBuj2Vu zcefKSrghnZ3NnawPosotU438btIrlfjRMGb1ud3tUwApwbrlnFEj+u4lWoEzZuqb/Pi 6hjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PLJB4OGOCZePChKEuODo6SwkET65pzuzt0wKe9KIEHA=; b=aPyTKaSLrc+Sx4kki0Qq2JnF3dUj2M1nVyurkusLXvRBqXJU+SPdi5rivuBfGj086A ZnuWLs2V68PzD1LZYQ1lL6rNcN4iupU0jzWuWVJ2RIuGZbM4FtSQE8eP5b4EA48mWbBW VXc1HoX6xedDzNBDyAe/MceiaX8Avj0+C8wU3JcBGxa5Cq4YbxWjFq5NsPJUs+wA7gcb Wb584iQWJBv61SK0NXpz1JNcFNdXopkD0z8YJ3Kah45Y4NTshzpVk3OGnQSsusV38DVq E2ZqKbpcAQeS6I5M305eeYxdN/DrqEtFKsXRp79IOju3M3EhCOPLCdlmo8ZSkqE4+4OX sAbw== X-Gm-Message-State: AN3rC/6zQGUi4F+M776rjvIjNqALi2LCac51EOxEq+7JGTfaA48Wtt7r evMR00wQqzIPYdnOuv8= X-Received: by 10.28.16.148 with SMTP id 142mr18339430wmq.75.1491986268711; Wed, 12 Apr 2017 01:37:48 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:8b2:dc00:6c54:829e:388a:2472]) by smtp.gmail.com with ESMTPSA id j32sm18990332wre.67.2017.04.12.01.37.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 01:37:48 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH 2/5] add show_allocation_stats() Date: Wed, 12 Apr 2017 10:37:00 +0200 Message-Id: <20170412083703.11552-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170412083703.11552-1-luc.vanoostenryck@gmail.com> References: <20170412083703.11552-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There exist some function to display the stats from each allocator (show__alloc()) but these functions need to be called one by one and deosn't allow to make some totals. Chnage this by adding show_allocation_stats() which display (in a more consise way) the stats from every allocator, together with the totals. Signed-off-by: Luc Van Oostenryck --- Makefile | 1 + allocate.h | 1 + stats.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 stats.c diff --git a/Makefile b/Makefile index 3ac100744..7ba2dbd82 100644 --- a/Makefile +++ b/Makefile @@ -107,6 +107,7 @@ LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \ char.o sort.o allocate.o compat-$(OS).o ptrlist.o \ builtin.o \ opcode.o \ + stats.o \ flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o LIB_FILE= libsparse.a diff --git a/allocate.h b/allocate.h index 6e6c3a614..64bb6dd64 100644 --- a/allocate.h +++ b/allocate.h @@ -29,6 +29,7 @@ extern void *allocate(struct allocator_struct *desc, unsigned int size); extern void free_one_entry(struct allocator_struct *desc, void *entry); extern void show_allocations(struct allocator_struct *); extern void get_allocator_stats(struct allocator_struct *, struct allocator_stats *); +extern void show_allocation_stats(void); #define __DECLARE_ALLOCATOR(type, x) \ extern type *__alloc_##x(int); \ diff --git a/stats.c b/stats.c new file mode 100644 index 000000000..5f2685733 --- /dev/null +++ b/stats.c @@ -0,0 +1,56 @@ +#include +#include "allocate.h" +#include "linearize.h" +#include "storage.h" + +__DECLARE_ALLOCATOR(struct ptr_list, ptrlist); + + +typedef void (*get_t)(struct allocator_stats*); + +static void show_stats(get_t get, struct allocator_stats * tot) +{ + struct allocator_stats x; + + if (get) + get(&x); + else + x = *tot; + fprintf(stderr, "%16s: %8d, %10ld, %10ld, %6.2f%%, %8.2f\n", + x.name, x.allocations, x.useful_bytes, x.total_bytes, + 100 * (double) x.useful_bytes / (x.total_bytes ? : 1), + (double) x.useful_bytes / (x.allocations ? : 1)); + + tot->allocations += x.allocations; + tot->useful_bytes += x.useful_bytes; + tot->total_bytes += x.total_bytes; +} + +void show_allocation_stats(void) +{ + struct allocator_stats tot = { .name = "total", }; + + fprintf(stderr, "%16s: %8s, %10s, %10s, %7s, %8s\n", "allocator", "allocs", + "bytes", "total", "%usage", "average"); + show_stats(get_token_stats, &tot); + show_stats(get_ident_stats, &tot); + show_stats(get_symbol_stats, &tot); + show_stats(get_expression_stats, &tot); + show_stats(get_statement_stats, &tot); + show_stats(get_scope_stats, &tot); + show_stats(get_basic_block_stats, &tot); + show_stats(get_instruction_stats, &tot); + show_stats(get_pseudo_stats, &tot); + show_stats(get_pseudo_user_stats, &tot); + show_stats(get_ptrlist_stats, &tot); + show_stats(get_multijmp_stats, &tot); + show_stats(get_asm_rules_stats, &tot); + show_stats(get_asm_constraint_stats, &tot); + show_stats(get_context_stats, &tot); + show_stats(get_string_stats, &tot); + show_stats(get_bytes_stats, &tot); + //show_stats(get_storage_stats, &tot); + //show_stats(get_storage_hash_stats, &tot); + + show_stats(NULL, &tot); +}