Index: src/Common/Heap.cc
===================================================================
--- src/Common/Heap.cc	(revision 10cfad9d3d9c4cef2b74f4ef3fab06d8cbe04ae5)
+++ src/Common/Heap.cc	(revision 45040f0642ea065bd868eb5faccdb7c55cc58030)
@@ -21,5 +21,5 @@
 #include <iostream>
 
-//#define WITH_HEAP_STATISTICS
+#define WITH_HEAP_STATISTICS
 
 namespace HeapStats {
@@ -30,10 +30,12 @@
 #else
 	struct StatBlock {
-		const char * name = nullptr;
-		size_t mallocs    = 0;
-		size_t frees      = 0;
+		const char * name  = nullptr;	///< Name of this pass
+		size_t mallocs     = 0;			///< Allocations in this pass
+		size_t frees       = 0;			///< Frees in this pass
+		size_t n_allocs    = 0;			///< Current number of live allocations
+		size_t peak_allocs = 0;			///< Peak number of live allocations this pass
 	};
 
-	StatBlock    passes[100] = {{ "Pre-Parse", 0, 0 }};
+	StatBlock    passes[100] = {{ "Pre-Parse", 0, 0, 0, 0 }};
 	const size_t passes_size = sizeof(passes) / sizeof(passes[0]);
 	size_t       passes_cnt = 1;
@@ -43,4 +45,7 @@
 		passes[passes_cnt].mallocs = 0;
 		passes[passes_cnt].frees   = 0;
+		passes[passes_cnt].n_allocs 
+			= passes[passes_cnt].peak_allocs 
+			= passes[passes_cnt-1].n_allocs;
 		passes_cnt++;
 
@@ -55,10 +60,11 @@
 	}
 
-	void print(const StatBlock& stat, size_t nc, size_t total_mallocs, size_t total_frees) {
+	void print(const StatBlock& stat, size_t nc, size_t total_mallocs, size_t total_frees, size_t overall_peak) {
 		std::cerr << std::setw(nc) << stat.name;
 		std::cerr << " | ";
 
-		print(stat.mallocs, total_mallocs);
-		print(stat.frees  , total_frees  );
+		print(stat.mallocs,     total_mallocs);
+		print(stat.frees,       total_frees  );
+		print(stat.peak_allocs, overall_peak );
 		std::cerr << "\n";
 	}
@@ -75,10 +81,12 @@
 		size_t total_mallocs = 0;
 		size_t total_frees   = 0;
+		size_t overall_peak  = 0;
 		for(size_t i = 0; i < passes_cnt; i++) {
 			nc = std::max(nc, std::strlen(passes[i].name));
 			total_mallocs += passes[i].mallocs;
 			total_frees   += passes[i].frees;
-		}
-		size_t nct = nc + 44;
+			overall_peak = std::max(overall_peak, passes[i].peak_allocs);
+		}
+		size_t nct = nc + 65;
 
 		const char * const title = "Heap Usage Statistic";
@@ -88,12 +96,13 @@
 		print('-', nct);
 		std::cerr << std::setw(nc) << "Pass";
-		std::cerr << " |       Malloc Count |         Free Count |" << std::endl;
+		std::cerr << " |       Malloc Count |         Free Count |        Peak Allocs |" << std::endl;
 
 		print('-', nct);
 		for(size_t i = 0; i < passes_cnt; i++) {
-			print(passes[i], nc, total_mallocs, total_frees);
+			print(passes[i], nc, total_mallocs, total_frees, overall_peak);
 		}
 		print('-', nct);
-		print({"Sum", total_mallocs, total_frees}, nc, total_mallocs, total_frees);
+		print({"Sum", total_mallocs, total_frees, 0, overall_peak}, 
+			nc, total_mallocs, total_frees, overall_peak);
 
 	}
@@ -158,5 +167,10 @@
 		void * malloc( size_t size ) {
 			static auto __malloc = reinterpret_cast<void * (*)(size_t)>(interpose_symbol( "malloc", nullptr ));
-			if( passes_cnt > 0 ) passes[passes_cnt - 1].mallocs++;
+			if( passes_cnt > 0 ) {
+				passes[passes_cnt - 1].mallocs++;
+				passes[passes_cnt - 1].n_allocs++;
+				passes[passes_cnt - 1].peak_allocs 
+					= std::max(passes[passes_cnt - 1].peak_allocs, passes[passes_cnt - 1].n_allocs);
+			}
 			return __malloc( size );
 		}
@@ -164,5 +178,8 @@
 		void free( void * ptr ) {
 			static auto __free = reinterpret_cast<void   (*)(void *)>(interpose_symbol( "free", nullptr ));
-			if( passes_cnt > 0 ) passes[passes_cnt - 1].frees++;
+			if( passes_cnt > 0 ) {
+				passes[passes_cnt - 1].frees++;
+				passes[passes_cnt - 1].n_allocs--;
+			}
 			return __free( ptr );
 		}
@@ -170,5 +187,10 @@
 		void * calloc( size_t nelem, size_t size ) {
 			static auto __calloc = reinterpret_cast<void * (*)(size_t, size_t)>(interpose_symbol( "calloc", nullptr ));
-			if( passes_cnt > 0 ) passes[passes_cnt - 1].mallocs++;
+			if( passes_cnt > 0 ) {
+				passes[passes_cnt - 1].mallocs++;
+				passes[passes_cnt - 1].n_allocs++;
+				passes[passes_cnt - 1].peak_allocs 
+					= std::max(passes[passes_cnt - 1].peak_allocs, passes[passes_cnt - 1].n_allocs);
+			}
 			return __calloc( nelem, size );
 		}
