diff options
author | Aliaksey Kandratsenka <alk@tut.by> | 2014-09-06 16:49:24 -0700 |
---|---|---|
committer | Aliaksey Kandratsenka <alk@tut.by> | 2014-09-06 16:49:24 -0700 |
commit | 2a28ef24ddf8013bff59914b10902f1fb07bf9b2 (patch) | |
tree | 89fb95d44f0120b3aaf6e642ae5a0fba22f2db1e | |
parent | bbf346a856d4a7c5c2ab0e65d7cccf3dc1f23f13 (diff) | |
download | gperftools-2a28ef24ddf8013bff59914b10902f1fb07bf9b2.tar.gz |
Added remaining memory allocated info to 'Exiting' dump message
This applies patch by user yurivict.
-rwxr-xr-x | src/heap-profiler.cc | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/heap-profiler.cc b/src/heap-profiler.cc index 1da544d..17d8697 100755 --- a/src/heap-profiler.cc +++ b/src/heap-profiler.cc @@ -591,7 +591,27 @@ static void HeapProfilerInit() { // class used for finalization -- dumps the heap-profile at program exit struct HeapProfileEndWriter { - ~HeapProfileEndWriter() { HeapProfilerDump("Exiting"); } + ~HeapProfileEndWriter() { + char buf[128]; + if (heap_profile) { + const HeapProfileTable::Stats& total = heap_profile->total(); + const int64 inuse_bytes = total.alloc_size - total.free_size; + + if ((inuse_bytes >> 20) > 0) { + snprintf(buf, sizeof(buf), ("Exiting, %" PRId64 " MB in use"), + inuse_bytes >> 20); + } else if ((inuse_bytes >> 10) > 0) { + snprintf(buf, sizeof(buf), ("Exiting, %" PRId64 " kB in use"), + inuse_bytes >> 10); + } else { + snprintf(buf, sizeof(buf), ("Exiting, %" PRId64 " bytes in use"), + inuse_bytes); + } + } else { + snprintf(buf, sizeof(buf), ("Exiting")); + } + HeapProfilerDump(buf); + } }; // We want to make sure tcmalloc is up and running before starting the profiler |