This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 5/6] Add line map statistics to -fmem-report output
- From: Dodji Seketeli <dodji at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: tromey at redhat dot com, joseph at codesourcery dot com, gdr at integrable-solutions dot net, lopezibanez at gmail dot com
- Date: Fri, 10 Dec 2010 12:11:37 +0100
- Subject: [PATCH 5/6] Add line map statistics to -fmem-report output
- References: <1291979498-1604-1-git-send-email-dodji@redhat.com>
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;
+}
--
Dodji