From patchwork Wed Apr 12 08:36:59 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: 9676801 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 6C8B160383 for ; Wed, 12 Apr 2017 08:37:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E0EB2808C for ; Wed, 12 Apr 2017 08:37:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FB5728338; Wed, 12 Apr 2017 08:37:52 +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 E06B12808C for ; Wed, 12 Apr 2017 08:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753153AbdDLIhv (ORCPT ); Wed, 12 Apr 2017 04:37:51 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34500 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751393AbdDLIht (ORCPT ); Wed, 12 Apr 2017 04:37:49 -0400 Received: by mail-wm0-f66.google.com with SMTP id x75so4882908wma.1 for ; Wed, 12 Apr 2017 01:37:48 -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=axA2la96zOfPWiyJ6VT87hVGg7zGdRgeOLV5f2eogSI=; b=EsdRXXsEHvZuMbRfhnTkflkqThNypIaCTfi3ZfBT8XLoX8KwQ74gwZgy0+iny3WKuF fAniOzG+EUgaZugZ7XqnBC13AXqYIb7f6+PiJQ+YXtZytQWGw9txwJaj7Bl+BRu5UaA/ 0PugSy/0rgq1Y/WuHRfLpYLTKaS5h0tmhZECmDbNvWu+zJj4BFVf1RK/iQA63vgS3rc8 Oej4YknMfjJv0X+QrACvjbf77Z/z0wnd8pALRwdBcMY8U9TpRH/9frBRwKs9rAE1qy5c 4TW3gBlMgKw09RO4FjF3MuRBpViea3JjyzD7Xu95vWs1ZY0oEuPPV+gdvPlfedzOo9uP wMRw== 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=axA2la96zOfPWiyJ6VT87hVGg7zGdRgeOLV5f2eogSI=; b=ciOftmwrIv471nyzBTHnYy83siYit50H8n+b/AaxuhjecgB4tbivA7b96QcghavprX vn7a1RuZ8+CT1sv/06KmmN0UFfIX74KX4vdC90l7HDEYIAACL2JCQvogNKT28X9k2rHv 5ZMwfJpQCCi/Dy4TQlklcvKlDh9V9TwhCsk9zQ8XErtSpm19F5N3bJu7Ut08RS61spDS uyuMUAo8i9h22DQHAKukJ4em3Rfiz87ibxlIDV5Na77CtiVXlkReiNhOEYb01vYXGJ87 1kOLgs4qgcbN/dSGUAB547tKuAdOEXccmxtK0W/Hf3xNb2QqHhTxpxqLMSdiPS5/HGXp hAew== X-Gm-Message-State: AN3rC/6j3BLqvWh5TqbNjhXukrSnkh6BZxyjfRQuCw1lz0SJ2yOgL1GW 1L9j7GvJGBv1dAnGJBo= X-Received: by 10.28.191.75 with SMTP id p72mr17764819wmf.136.1491986267777; Wed, 12 Apr 2017 01:37:47 -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.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 01:37:47 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH 1/5] add get__stats() Date: Wed, 12 Apr 2017 10:36:59 +0200 Message-Id: <20170412083703.11552-2-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 exists a function to display the stats from each allocator but: 1) what it displays is a bit long and fixed 2) it doesn't allow to make totals and stuff. Change this by adding a function that only collect the stats from each allocator. Signed-off-by: Luc Van Oostenryck --- allocate.c | 8 ++++++++ allocate.h | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/allocate.c b/allocate.c index f597caf16..daa4ac247 100644 --- a/allocate.c +++ b/allocate.c @@ -127,6 +127,14 @@ void show_allocations(struct allocator_struct *x) (double) x->useful_bytes / x->allocations); } +void get_allocator_stats(struct allocator_struct *x, struct allocator_stats *s) +{ + s->name = x->name; + s->allocations = x->allocations; + s->useful_bytes = x->useful_bytes; + s->total_bytes = x->total_bytes; +} + ALLOCATOR(ident, "identifiers"); ALLOCATOR(token, "tokens"); ALLOCATOR(context, "contexts"); diff --git a/allocate.h b/allocate.h index 9e51ed7da..6e6c3a614 100644 --- a/allocate.h +++ b/allocate.h @@ -17,16 +17,24 @@ struct allocator_struct { unsigned int allocations, total_bytes, useful_bytes; }; +struct allocator_stats { + const char *name; + unsigned int allocations; + unsigned long total_bytes, useful_bytes; +}; + extern void protect_allocations(struct allocator_struct *desc); extern void drop_all_allocations(struct allocator_struct *desc); 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 *); #define __DECLARE_ALLOCATOR(type, x) \ extern type *__alloc_##x(int); \ extern void __free_##x(type *); \ extern void show_##x##_alloc(void); \ + extern void get_##x##_stats(struct allocator_stats *); \ extern void clear_##x##_alloc(void); \ extern void protect_##x##_alloc(void); #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x) @@ -48,6 +56,10 @@ extern void show_allocations(struct allocator_struct *); { \ show_allocations(&x##_allocator); \ } \ + void get_##x##_stats(struct allocator_stats *s) \ + { \ + get_allocator_stats(&x##_allocator, s); \ + } \ void clear_##x##_alloc(void) \ { \ drop_all_allocations(&x##_allocator); \