Index: memlog.cpp
===================================================================
--- memlog.cpp	(revision 22f928f0ff6602dd7b645cd85f43e354c35b7957)
+++ memlog.cpp	(revision 21d3542f78e3142d061b6b79565ed7ac0b2abbcf)
@@ -6,4 +6,5 @@
 #include <cstdio>
 #include <cstring>
+#include <cstdint>
 
 // NOTE: This source makes very minimal use of C++11 features. It can still be
@@ -29,4 +30,5 @@
 #ifdef __bgq__
 #include <spi/include/kernel/location.h>
+#include <spi/include/kernel/memory.h>
 #endif
 
@@ -45,4 +47,10 @@
 static char self_path[PATH_MAX+1] = { '\0' };
 
+#ifdef __bgq__
+int on_bgq = 0;
+#endif
+
+void *initial_brk = 0;
+
 __attribute__((__constructor__))
 static void record_init() {
@@ -54,6 +62,8 @@
   // If we're really running on a BG/Q compute node, use the job rank instead
   // of the pid because the node name might not really be globally unique.
-  if (!strcmp(u.sysname, "CNK") && !strcmp(u.machine, "BGQ"))
+  if (!strcmp(u.sysname, "CNK") && !strcmp(u.machine, "BGQ")) {
     id = (int) Kernel_GetRank();
+    on_bgq = 1;
+  }
 #endif
 
@@ -81,4 +91,6 @@
   const char *link_name = "/proc/self/exe";
   readlink(link_name, self_path, PATH_MAX);
+
+  initial_brk = sbrk(0);
 }
 
@@ -128,4 +140,15 @@
   fprintf(log_file, "\t%ld.%06ld %ld %ld", usage.ru_utime.tv_sec,
           usage.ru_utime.tv_usec, usage.ru_maxrss, syscall(SYS_gettid));
+
+  // Some other memory stats (like with maxrss, report these in KB).
+  size_t arena_size = ((size_t) sbrk(0)) - (size_t) initial_brk;
+
+  uint64_t mmap_size = 0;
+#ifdef __bgq__
+  if (on_bgq)
+    (void) Kernel_GetMemorySize(KERNEL_MEMSIZE_MMAP, &mmap_size);
+#endif
+
+  fprintf(log_file, " %ld %ld", arena_size >> 10, mmap_size >> 10);
 
   if (!show_backtrace)
Index: memlog_analyze
===================================================================
--- memlog_analyze	(revision c83befcdedb97e864aa9a6bb10dc1b7d6ad01f6e)
+++ memlog_analyze	(revision 21d3542f78e3142d061b6b79565ed7ac0b2abbcf)
@@ -64,5 +64,6 @@
       my $state = shift(@parts);
 
-      my ($time, $then_max_rss, $tid) = split(/\s+/, $state);
+      my ($time, $then_max_rss, $tid, $then_arena, $then_mmap) =
+        split(/\s+/, $state);
       if ($pot_max_rss < $then_max_rss) {
         $pot_max_rss = $then_max_rss;
@@ -94,4 +95,6 @@
 # The first step is to determine the high-water mark.
 my $max_rss = 0;
+my $arena = 0;
+my $mmap = 0;
 foreach my $line (<MEMLOG>) {
   chomp($line);
@@ -101,7 +104,10 @@
   my $state = shift(@parts);
 
-  my ($time, $then_max_rss, $tid) = split(/\s+/, $state);
+  my ($time, $then_max_rss, $tid, $then_arena, $then_mmap) =
+    split(/\s+/, $state);
   if ($max_rss < $then_max_rss) {
     $max_rss = $then_max_rss;
+    $arena = $then_arena;
+    $mmap = $then_mmap;
   }
 }
@@ -131,5 +137,6 @@
   }
 
-  my ($time, $then_max_rss, $tid) = split(/\s+/, $state);
+  my ($time, $then_max_rss, $tid, $then_arena, $then_mmap) =
+    split(/\s+/, $state);
   $active_alloc_time = $time;
 
@@ -146,4 +153,10 @@
 # Convert maxrss, currently in KB, to bytes.
 $max_rss *= 1024;
+if (defined $arena) {
+  $arena *= 1024;
+}
+if (defined $mmap) {
+  $mmap *= 1024;
+}
 
 my $total_size = 0;
@@ -162,5 +175,6 @@
 
   my ($size, $ptr) = ($op =~ /^M: (\d+) 0x(\w+)/);
-  my ($time, $then_max_rss, $tid) = split(/\s+/, $state);
+  my ($time, $then_max_rss, $tid, $then_arena, $then_mmap) =
+    split(/\s+/, $state);
 
   $total_size += $size;
@@ -249,4 +263,9 @@
 }
 
+sub format_bytes_or_unk($) {
+  my $b = $_[0];
+  return defined($b) ? format_bytes($b) : "(unknown)";
+}
+
 print DOT ("digraph \"memlog\" {\n");
 print DOT ("size=\"8,11\";\n");
@@ -254,12 +273,20 @@
 
 my $find_type = $find_leaks ? " (leaks)" : "";
-printf DOT ("Legend [shape=box, fontsize=100, shape=oval," .
-            "label=\"Total: %s active$find_type at maxrss = %s after %s s\"];\n",
+print DOT "subgraph cluster_key {\n";
+print DOT "\trank=min;\n";
+print DOT "\tlabel=\"memlog\";\n";
+print DOT "\tfontsize=100;\n";
+print DOT "\trankdir=UR;\n";
+printf DOT ("Legend [shape=box, fontsize=100, shape=plaintext," .
+            "label=\"Total: %s active$find_type at maxrss = %s after %s s\\narena: %s\\nmmap: %s\"];\n",
             format_bytes($total_size), format_bytes($max_rss),
-            $active_alloc_time);
-
-printf TXT ("memlog: Total: %s active$find_type at maxrss = %s after %s s\n\n",
+            $active_alloc_time, format_bytes_or_unk($arena),
+            format_bytes_or_unk($mmap));
+print DOT "}\n";
+
+printf TXT ("memlog: Total: %s active$find_type at maxrss = %s after %s s\n\tarena: %s\tmmap: %s\n\n",
             format_bytes($total_size), format_bytes($max_rss),
-            $active_alloc_time);
+            $active_alloc_time, format_bytes_or_unk($arena),
+            format_bytes_or_unk($mmap));
 
 my %cached_names;
