summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksey Kandratsenka <alk@tut.by>2014-09-06 16:49:24 -0700
committerAliaksey Kandratsenka <alk@tut.by>2014-09-06 16:49:24 -0700
commit2a28ef24ddf8013bff59914b10902f1fb07bf9b2 (patch)
tree89fb95d44f0120b3aaf6e642ae5a0fba22f2db1e
parentbbf346a856d4a7c5c2ab0e65d7cccf3dc1f23f13 (diff)
downloadgperftools-2a28ef24ddf8013bff59914b10902f1fb07bf9b2.tar.gz
Added remaining memory allocated info to 'Exiting' dump message
This applies patch by user yurivict.
-rwxr-xr-xsrc/heap-profiler.cc22
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