On 9/1/20 4:04 PM, Jan Hubicka wrote:
The patch is about usage of MiB in memory allocation reports.
I see it much better readable than values displayed in KiB:

Reading object files: tramp3d-v4.o {GC released 1 MiB} {GC 19 MiB -> 19 MiB} 
{GC 19 MiB}  {heap 12 MiB}
Reading the symbol table:
Merging declarations: {GC released 1 MiB madv_dontneed 0 MiB} {GC 27 MiB -> 27 
MiB} {GC 27 MiB}  {heap 15 MiB}
Reading summaries: <odr> {GC 27 MiB}  {heap 15 MiB} <profile_estimate> {GC 27 MiB}  {heap 15 MiB} <icf> 
{GC 27 MiB}  {heap 15 MiB} <cp> {GC 27 MiB}  {heap 15 MiB} <sra> {GC 27 MiB}  {heap 15 MiB} <fnsummary> 
{GC 30 MiB}  {heap 15 MiB} <pure-const> {GC 30 MiB}  {heap 15 MiB} {GC 30 MiB}
Merging symbols: {heap 15 MiB}Materializing decls:
  <odr> {heap 15 MiB} <whole-program> {heap 15 MiB} <profile_estimate> {heap 15 MiB} <icf> {heap 15 MiB} <devirt> {heap 15 MiB} <cp> 
{heap 15 MiB} <sra> {heap 15 MiB} <cdtor> {heap 15 MiB} <fnsummary> {heap 15 MiB} <inline> {heap 15 MiB} <pure-const> {heap 15 MiB} 
<free-fnsummary> {GC released 1 MiB madv_dontneed 2 MiB} {GC trimmed to 27 MiB, 28 MiB mapped} {heap 15 MiB} <static-var> {heap 15 MiB} <single-use> 
{heap 15 MiB} <comdats> {heap 15 MiB}
Streaming out {GC trimmed to 27 MiB, 28 MiB mapped} {heap 15 MiB} ./a.ltrans0.o 
( 11257 insns) ./a.ltrans1.o ( 11293 insns) ./a.ltrans2.o ( 8669 insns) 
./a.ltrans3.o ( 138934 insns)

One problem I see here is that while it is OK for Firefox builds it is
bit too coarse for smaller testcases where the memory use is still
importnat.  I guess we may just print KBs before the large gets too
large, just like norton commander does? :)

Sure, let's do it using SIZE_AMOUNT macro.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin


Honza

Thoughts?
Thanks,
Martin

>From 8826f267175d456121612332b838e41a9542a513 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Wed, 2 Sep 2020 14:30:16 +0200
Subject: [PATCH 2/3] Use SIZE_AMOUNT macro for GGC memory allocation numbers.

gcc/ChangeLog:

	* ggc-common.c (ggc_prune_overhead_list): Use SIZE_AMOUNT.
	* ggc-page.c (release_pages): Likewise.
	(ggc_collect): Likewise.
	(ggc_trim): Likewise.
	(ggc_grow): Likewise.
	* timevar.c (timer::print): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/timevar1.C: Prune more possible number values.
	* g++.dg/ext/timevar2.C: Likewise.
---
 gcc/ggc-common.c                    |  6 +++---
 gcc/ggc-page.c                      | 15 +++++++--------
 gcc/testsuite/g++.dg/ext/timevar1.C |  3 ++-
 gcc/testsuite/g++.dg/ext/timevar2.C |  3 ++-
 gcc/timevar.c                       |  8 ++++----
 5 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c
index b8782c5824b..50c52fe525b 100644
--- a/gcc/ggc-common.c
+++ b/gcc/ggc-common.c
@@ -1008,7 +1008,7 @@ ggc_prune_overhead_list (void)
       }
 }
 
-/* Print memory used by heap in kb if this info is not available.  */
+/* Print memory used by heap if this info is not available.  */
 
 void
 report_heap_memory_use ()
@@ -1020,7 +1020,7 @@ report_heap_memory_use ()
   #define MALLINFO_FN mallinfo
 #endif
   if (!quiet_flag)
-    fprintf (stderr," {heap %luk}",
-	     (unsigned long) MALLINFO_FN ().arena / ONE_K);
+    fprintf (stderr, " {heap " PRsa (0) "}",
+	     SIZE_AMOUNT (MALLINFO_FN ().arena));
 #endif
 }
diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c
index 53b311c2a52..9405f033a7c 100644
--- a/gcc/ggc-page.c
+++ b/gcc/ggc-page.c
@@ -1164,9 +1164,9 @@ release_pages (void)
     {
       fprintf (stderr, " {GC");
       if (n1)
-	fprintf (stderr, " released %luk", (unsigned long)(n1 / 1024));
+	fprintf (stderr, " released " PRsa (0), SIZE_AMOUNT (n1));
       if (n2)
-	fprintf (stderr, " madv_dontneed %luk", (unsigned long)(n2 / 1024));
+	fprintf (stderr, " madv_dontneed " PRsa (0), SIZE_AMOUNT (n2));
       fprintf (stderr, "}");
     }
 }
@@ -2208,7 +2208,7 @@ ggc_collect (void)
 
   /* Output this later so we do not interfere with release_pages.  */
   if (!quiet_flag)
-    fprintf (stderr, " {GC %luk -> ", (unsigned long) allocated / 1024);
+    fprintf (stderr, " {GC " PRsa (0) " -> ", SIZE_AMOUNT (allocated));
 
   /* Indicate that we've seen collections at this context depth.  */
   G.context_depth_collections = ((unsigned long)1 << (G.context_depth + 1)) - 1;
@@ -2235,7 +2235,7 @@ ggc_collect (void)
   timevar_pop (TV_GC);
 
   if (!quiet_flag)
-    fprintf (stderr, "%luk}", (unsigned long) G.allocated / 1024);
+    fprintf (stderr, PRsa (0) "}", SIZE_AMOUNT (G.allocated));
   if (GGC_DEBUG_LEVEL >= 2)
     fprintf (G.debug_file, "END COLLECTING\n");
 }
@@ -2250,9 +2250,8 @@ ggc_trim ()
   sweep_pages ();
   release_pages ();
   if (!quiet_flag)
-    fprintf (stderr, " {GC trimmed to %luk, %luk mapped}",
-	     (unsigned long) G.allocated / 1024,
-	     (unsigned long) G.bytes_mapped / 1024);
+    fprintf (stderr, " {GC trimmed to " PRsa (0) ", " PRsa (0) " mapped}",
+	     SIZE_AMOUNT (G.allocated), SIZE_AMOUNT (G.bytes_mapped));
   timevar_pop (TV_GC);
 }
 
@@ -2269,7 +2268,7 @@ ggc_grow (void)
   else
     ggc_collect ();
   if (!quiet_flag)
-    fprintf (stderr, " {GC %luk} ", (unsigned long) G.allocated / 1024);
+    fprintf (stderr, " {GC " PRsa (0) "} ", SIZE_AMOUNT (G.allocated));
 }
 
 void
diff --git a/gcc/testsuite/g++.dg/ext/timevar1.C b/gcc/testsuite/g++.dg/ext/timevar1.C
index 3f891a50aba..988a6f8543d 100644
--- a/gcc/testsuite/g++.dg/ext/timevar1.C
+++ b/gcc/testsuite/g++.dg/ext/timevar1.C
@@ -2,7 +2,8 @@
 // { dg-options "-ftime-report" }
 // { dg-allow-blank-lines-in-output 1 }
 // { dg-prune-output "Time variable" }
-// { dg-prune-output " kB" }
+// { dg-prune-output "k" }
+// { dg-prune-output " 0 " }
 // { dg-prune-output "checks" }
 
 void
diff --git a/gcc/testsuite/g++.dg/ext/timevar2.C b/gcc/testsuite/g++.dg/ext/timevar2.C
index dd96d45c01e..46c3e1b4794 100644
--- a/gcc/testsuite/g++.dg/ext/timevar2.C
+++ b/gcc/testsuite/g++.dg/ext/timevar2.C
@@ -1,7 +1,8 @@
 // PR c++/57524
 // { dg-options "-ftime-report" }
 // { dg-prune-output "Time variable" }
-// { dg-prune-output " kB" }
+// { dg-prune-output "k" }
+// { dg-prune-output " 0 " }
 // { dg-prune-output "checks" }
 
 namespace detail {
diff --git a/gcc/timevar.c b/gcc/timevar.c
index a3a882d3204..8fbf5faa4e3 100644
--- a/gcc/timevar.c
+++ b/gcc/timevar.c
@@ -661,8 +661,8 @@ timer::print_row (FILE *fp,
 #endif /* HAVE_WALL_TIME */
 
   /* Print the amount of ggc memory allocated.  */
-  fprintf (fp, "%8u kB (%3.0f%%)",
-	   (unsigned) (elapsed.ggc_mem >> 10),
+  fprintf (fp, PRsa (6) " (%3.0f%%)",
+	   SIZE_AMOUNT (elapsed.ggc_mem),
 	   (total->ggc_mem == 0
 	    ? 0
 	    : (float) elapsed.ggc_mem / total->ggc_mem) * 100);
@@ -712,7 +712,7 @@ timer::print (FILE *fp)
      TIMEVAR.  */
   m_start_time = now;
 
-  fprintf (fp, "\n%-35s%16s%14s%14s%18s\n", "Time variable", "usr", "sys",
+  fprintf (fp, "\n%-35s%16s%14s%14s%14s\n", "Time variable", "usr", "sys",
 	   "wall", "GGC");
   if (m_jit_client_items)
     fputs ("GCC items:\n", fp);
@@ -776,7 +776,7 @@ timer::print (FILE *fp)
 #ifdef HAVE_WALL_TIME
   fprintf (fp, "%8.2f      ", total->wall);
 #endif
-  fprintf (fp, "%9u kB\n", (unsigned) (total->ggc_mem >> 10));
+  fprintf (fp, PRsa (7) "\n", SIZE_AMOUNT (total->ggc_mem));
 
   if (CHECKING_P || flag_checking)
     fprintf (fp, "Extra diagnostic checks enabled; compiler may run slowly.\n");
-- 
2.28.0

Reply via email to