From patchwork Fri Dec 10 11:11:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 75076 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 9EFFDB6F14 for ; Fri, 10 Dec 2010 23:25:55 +1100 (EST) Received: (qmail 25305 invoked by alias); 10 Dec 2010 11:14:23 -0000 Received: (qmail 24730 invoked by uid 22791); 10 Dec 2010 11:13:40 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (140.186.70.92) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 10 Dec 2010 11:12:42 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PR0tV-0000Di-I5 for gcc-patches@gcc.gnu.org; Fri, 10 Dec 2010 06:12:10 -0500 Received: from seketeli.net ([91.121.166.71]:50479 helo=ms.seketeli.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PR0tV-0000DP-9J for gcc-patches@gcc.gnu.org; Fri, 10 Dec 2010 06:12:09 -0500 Received: from adjoa.torimasen.com (torimasen.com [82.237.12.13]) by ms.seketeli.net (Postfix) with ESMTP id E2DCA1608047; Fri, 10 Dec 2010 12:11:40 +0100 (CET) Received: by adjoa.torimasen.com (Postfix, from userid 500) id B942E87E001; Fri, 10 Dec 2010 12:11:38 +0100 (CET) From: Dodji Seketeli To: gcc-patches@gcc.gnu.org Cc: tromey@redhat.com, joseph@codesourcery.com, gdr@integrable-solutions.net, lopezibanez@gmail.com Subject: [PATCH 5/6] Add line map statistics to -fmem-report output Date: Fri, 10 Dec 2010 12:11:37 +0100 Message-Id: <1291979498-1604-7-git-send-email-dodji@redhat.com> In-Reply-To: <1291979498-1604-1-git-send-email-dodji@redhat.com> References: <1291979498-1604-1-git-send-email-dodji@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch adds statistics about the memory consumption of line maps to the output of -fmem-report. It has been useful in trying to reduce the memory consumption of the macro maps support. Tested on x86_64-unknown-linux-gnu against trunk. gcc/ * input.c (SCALE, STAT_LABEL, FORMAT_AMOUNT): New macros. (dump_line_table_statistics): Define new function. * input.h (dump_line_table_statistics): Declare new function. * toplev.c (dump_memory_report): Call dump_line_table_statistics. libcpp/ * line-map.h (linemap_get_statistics): Declare ... * line-map.c (linemap_get_statistics): ... new function. --- gcc/input.c | 67 ++++++++++++++++++++++++++++++++ gcc/input.h | 2 + gcc/toplev.c | 1 + libcpp/include/line-map.h | 7 +++ libcpp/line-map.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 170 insertions(+), 0 deletions(-) diff --git a/gcc/input.c b/gcc/input.c index 6dbc253..6d265f4 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -75,3 +75,70 @@ expand_location (source_location loc) } return xloc; } + +#define SCALE(x) ((unsigned long) ((x) < 1024*10 \ + ? (x) \ + : ((x) < 1024*1024*10 \ + ? (x) / 1024 \ + : (x) / (1024*1024)))) +#define STAT_LABEL(x) ((x) < 1024*10 ? ' ' : ((x) < 1024*1024*10 ? 'k' : 'M')) + +#define FORMAT_AMOUNT(size) SCALE (size), STAT_LABEL (size) + +/* Dump statistics to stderr about the memory usage of the line_table + set of line maps. */ + +void +dump_line_table_statistics (void) +{ + size_t num_ordinary_maps_allocated = 0, num_ordinary_maps_used = 0, + num_macro_maps_used = 0, macro_maps_used_size = 0, + ordinary_maps_allocated_size = 0, ordinary_maps_used_size = 0, + macro_maps_locations_size = 0, duplicated_maps_locations_size = 0, + total_allocated_map_size = 0, total_used_map_size = 0; + + linemap_get_statistics (line_table, + &num_ordinary_maps_allocated, + &num_ordinary_maps_used, + &ordinary_maps_allocated_size, + &ordinary_maps_used_size, + &num_macro_maps_used, + ¯o_maps_used_size, + ¯o_maps_locations_size, + &duplicated_maps_locations_size, + &total_allocated_map_size, + &total_used_map_size); + + fprintf (stderr, "\nLine Table allocations during the compilation process\n"); + fprintf (stderr, "Total allocated maps size: %5lu%c\n", + SCALE (total_allocated_map_size), + STAT_LABEL (total_allocated_map_size)); + fprintf (stderr, "Total used maps size: %5lu%c\n", + SCALE (total_used_map_size), + STAT_LABEL (total_used_map_size)); + fprintf (stderr, "Ordinary map used size: %5lu%c\n", + SCALE (ordinary_maps_used_size), + STAT_LABEL (ordinary_maps_used_size)); + fprintf (stderr, "Macro maps used size: %5lu%c\n", + SCALE (macro_maps_used_size), + STAT_LABEL (macro_maps_used_size)); + fprintf (stderr, "Number of ordinary maps allocated: %5lu%c\n", + SCALE (num_ordinary_maps_allocated), + STAT_LABEL (num_ordinary_maps_allocated)); + fprintf (stderr, "Number of ordinary maps used: %5lu%c\n", + SCALE (num_ordinary_maps_used), + STAT_LABEL (num_ordinary_maps_used)); + fprintf (stderr, "Number of macro maps used: %5lu%c\n", + SCALE (num_macro_maps_used), + STAT_LABEL (num_macro_maps_used)); + fprintf (stderr, "Ordinary maps allocated size: %5lu%c\n", + SCALE (ordinary_maps_allocated_size), + STAT_LABEL (ordinary_maps_allocated_size)); + fprintf (stderr, "Macro maps locations size: %5lu%c\n", + SCALE (macro_maps_locations_size), + STAT_LABEL (macro_maps_locations_size)); + fprintf (stderr, "Duplicated maps locations size: %5lu%c\n", + SCALE (duplicated_maps_locations_size), + STAT_LABEL (duplicated_maps_locations_size)); + fprintf (stderr, "\n"); +} diff --git a/gcc/input.h b/gcc/input.h index 835c95a..ca122b5 100644 --- a/gcc/input.h +++ b/gcc/input.h @@ -55,4 +55,6 @@ extern location_t input_location; ((linemap_location_in_system_header_p (line_table, LOC))) #define in_system_header (in_system_header_at (input_location)) +void dump_line_table_statistics (void); + #endif diff --git a/gcc/toplev.c b/gcc/toplev.c index 78985cb..c86bc90 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -1786,6 +1786,7 @@ target_reinit (void) void dump_memory_report (bool final) { + dump_line_table_statistics (); ggc_print_statistics (); stringpool_statistics (); dump_tree_statistics (); diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 3f58e03..36e7ad2 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -641,4 +641,11 @@ expanded_location linemap_expand_location_full (struct line_maps *, enum location_resolution_kind, const struct line_map**); void linemap_dump_location (struct line_maps *, source_location, FILE *); + +void linemap_get_statistics (struct line_maps *set, + size_t *, size_t *, + size_t *, size_t *, + size_t *, size_t *, + size_t *, size_t *, + size_t *, size_t *); #endif /* !LIBCPP_LINE_MAP_H */ diff --git a/libcpp/line-map.c b/libcpp/line-map.c index a924912..c05c9d5 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -1019,3 +1019,96 @@ linemap_dump_location (struct line_maps *set, fprintf (stream, "{P:%s;F:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%d}", path, from, l, c, s, (void*)map, e, loc); } + +/* Compute and return statistics about the memory consumption of some + parts of the line table SET. */ + +void +linemap_get_statistics (struct line_maps *set, + size_t *num_ordinary_maps_allocated_ptr, + size_t *num_ordinary_maps_used_ptr, + size_t *ordinary_maps_allocated_size_ptr, + size_t *ordinary_maps_used_size_ptr, + size_t *num_macro_maps_used_ptr, + size_t *macro_maps_used_size_ptr, + size_t *macro_maps_locations_size_ptr, + size_t *duplicated_macro_maps_locations_size_ptr, + size_t *total_allocated_map_size_ptr, + size_t *total_used_map_size_ptr) +{ + size_t ordinary_maps_allocated_size, ordinary_maps_used_size, + macro_maps_allocated_size, macro_maps_used_size, + macro_maps_locations_size = 0, duplicated_macro_maps_locations_size = 0, + total_allocated_map_size, total_used_map_size; + struct line_map *cur_map; + + ordinary_maps_allocated_size = + LINEMAPS_ORDINARY_ALLOCATED (set) * sizeof (struct line_map); + + ordinary_maps_used_size = + LINEMAPS_ORDINARY_USED (set) * sizeof (struct line_map); + + macro_maps_allocated_size = + LINEMAPS_MACRO_ALLOCATED (set) * sizeof (struct line_map); + + for (cur_map = LINEMAPS_MACRO_MAPS (set); + cur_map && cur_map <= LINEMAPS_LAST_MACRO_MAP (set); + ++cur_map) + { + unsigned i; + + linemap_assert (linemap_macro_expansion_map_p (cur_map)); + + macro_maps_locations_size += + 2 * MACRO_MAP_NUM_MACRO_TOKENS (cur_map) * sizeof (source_location); + + for (i = 0; i < 2 * MACRO_MAP_NUM_MACRO_TOKENS (cur_map); i+=2) + { + if (MACRO_MAP_LOCATIONS (cur_map)[i] == + MACRO_MAP_LOCATIONS (cur_map)[i + 1]) + duplicated_macro_maps_locations_size += + sizeof (source_location); + } + } + + macro_maps_used_size = + LINEMAPS_MACRO_USED (set) * sizeof (struct line_map) + + macro_maps_locations_size; + + total_used_map_size = ordinary_maps_used_size + macro_maps_used_size; + + total_allocated_map_size = + ordinary_maps_allocated_size + macro_maps_allocated_size + + macro_maps_locations_size; + + if (num_ordinary_maps_allocated_ptr) + *num_ordinary_maps_allocated_ptr = LINEMAPS_ORDINARY_ALLOCATED (set); + + if (num_ordinary_maps_used_ptr) + *num_ordinary_maps_used_ptr = LINEMAPS_ORDINARY_USED (set); + + if (ordinary_maps_allocated_size_ptr) + *ordinary_maps_allocated_size_ptr = ordinary_maps_allocated_size; + + if (ordinary_maps_used_size_ptr) + *ordinary_maps_used_size_ptr = ordinary_maps_used_size; + + if (num_macro_maps_used_ptr) + *num_macro_maps_used_ptr = LINEMAPS_MACRO_USED (set); + + if (macro_maps_used_size_ptr) + *macro_maps_used_size_ptr = macro_maps_used_size; + + if (macro_maps_locations_size_ptr) + *macro_maps_locations_size_ptr = macro_maps_locations_size; + + if (duplicated_macro_maps_locations_size_ptr) + *duplicated_macro_maps_locations_size_ptr = + duplicated_macro_maps_locations_size; + + if (total_allocated_map_size_ptr) + *total_allocated_map_size_ptr = total_allocated_map_size; + + if (total_used_map_size_ptr) + *total_used_map_size_ptr = total_used_map_size; +}