[PATCH] Add --devel-progress-mem

Tom de Vries tdevries@suse.de
Thu Mar 4 12:25:14 GMT 2021


Hi,

Add an option --devel-progress-mem that adds memory usage printing to
--devel-progress:
...
$ dwz cc1 -lnone -o cc1.z --devel-progress-mem
read_debug_info .debug_info
user: 4.70
sys : 0.18
VM Peak: 1178532 (1.1G)
VM Current: 1174432 (1.1G)
RSS Peak: 1091784 (1.0G)
RSS Current: 1087992 (1.0G)
partition_dups
user: 0.11
sys : 0.00
VM Peak: 1178532 (1.1G)
VM Current: 1174860 (1.1G)
RSS Peak: 1091784 (1.0G)
RSS Current: 1088372 (1.0G)
...

Any comments?

Thanks,
- Tom

Add --devel-progress-mem

2021-03-04  Tom de Vries  <tdevries@suse.de>

	* dwz.c (print_mem): New function.
	(report_progress): Print memory usage statistics if progress_mem_p.
	(dwz_options, usage): Add --devel-progress-mem entries.
	(main): Set progress_p if progress_mem_p.

---
 dwz.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/dwz.c b/dwz.c
index af1c5af..aec039d 100644
--- a/dwz.c
+++ b/dwz.c
@@ -132,6 +132,23 @@
 #define MAX(A, B) ((A) > (B) ? (A) : (B))
 #define MIN(A, B) ((A) < (B) ? (A) : (B))
 
+/* Print memory amount M (in kb) in both exact and human readable, like so:
+   1382508 (1.3G).  */
+static void
+print_mem (long m)
+{
+  float h = m;
+  int level = 0;
+  const char *unit[] = { "K", "M", "G"};
+  while (h > 1024 && level <= 2)
+    {
+      h = h / 1024;
+      level++;
+    }
+  fprintf (stderr, "%ld (%.1f%s)\n", m, h, unit[level]);
+}
+
+static int progress_mem_p;
 
 static void
 report_progress (void)
@@ -157,6 +174,40 @@ report_progress (void)
   clock_t sys = current.tms_stime - prev.tms_stime;
   fprintf (stderr, "user: %.2f\n", (float)user / (float)ticks_per_second);
   fprintf (stderr, "sys : %.2f\n", (float)sys / (float)ticks_per_second);
+
+  if (progress_mem_p)
+    {
+      FILE *s = fopen ("/proc/self/status", "r");
+      char *p;
+      bool print_next = false;
+      for (p = NULL; fscanf (s, "%ms", &p) && p != NULL; free (p))
+	{
+	  if (print_next)
+	    {
+	      long mem = strtol (p, NULL, 10);
+	      print_mem (mem);
+	      print_next = false;
+	      continue;
+	    }
+
+	  if (!(p[0] == 'V' && p[1] == 'm'))
+	    continue;
+
+	  if (strcmp (&p[2], "Peak:") == 0)
+	    fprintf (stderr, "VM Peak: ");
+	  else if (strcmp (&p[2], "Size:") == 0)
+	    fprintf (stderr, "VM Current: ");
+	  else if (strcmp (&p[2], "HWM:") == 0)
+	    fprintf (stderr, "RSS Peak: ");
+	  else if (strcmp (&p[2], "RSS:") == 0)
+	    fprintf (stderr, "RSS Current: ");
+	  else
+	    continue;
+
+	  print_next = true;
+	}
+      fclose (s);
+    }
 }
 
 #define obstack_chunk_alloc     malloc
@@ -16285,6 +16336,7 @@ static struct option dwz_options[] =
 #if DEVEL
   { "devel-trace",	 no_argument,	    &tracing, 1 },
   { "devel-progress",	 no_argument,	    &progress_p, 1 },
+  { "devel-progress-mem",no_argument,	    &progress_mem_p, 1 },
   { "devel-ignore-size", no_argument,	    &ignore_size, 1 },
   { "devel-ignore-locus",no_argument,	    &ignore_locus, 1 },
   { "devel-force",	 no_argument,	    &force_p, 1 },
@@ -16552,6 +16604,7 @@ usage (const char *progname, int failing)
   fprintf (stream, "%s",
 	   ("  --devel-trace\n"
 	    "  --devel-progress\n"
+	    "  --devel-progress-mem\n"
 	    "  --devel-stats\n"
 	    "  --devel-ignore-size\n"
 	    "  --devel-ignore-locus\n"
@@ -16732,6 +16785,9 @@ main (int argc, char *argv[])
 	}
     }
 
+  if (progress_mem_p)
+    progress_p = 1;
+
   /* Specifying a low-mem die-limit that is larger than or equal to the
      max die-limit has the effect of disabling low-mem mode.  Make this
      explicit by setting it to the 'none' value.  */


More information about the Dwz mailing list