From b2467801616dfd9e13d85024219f8c13552d4750 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 30 May 2013 01:02:32 +0200 Subject: [PATCH] Add snapshot ID and timestamp to output. --- dumpmallocinfo.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/dumpmallocinfo.cpp b/dumpmallocinfo.cpp index 30aed1e..b10fbc4 100644 --- a/dumpmallocinfo.cpp +++ b/dumpmallocinfo.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -31,19 +32,36 @@ using namespace std; unique_ptr runner; atomic_bool stop{false}; -void dump_malloc_info(unsigned int millisecond_interval) +void dump_malloc_info() +{ + ///TODO: make output destination configurable + FILE* output = stderr; + + static unsigned long id = 0; + + auto duration = chrono::system_clock::now().time_since_epoch(); + auto millis = chrono::duration_cast(duration).count(); + + fprintf(output, "\n", id++, millis); + malloc_info(0, output); + fprintf(output, "\n"); +} + +void thread_dump_malloc_info(unsigned int millisecond_interval) { while(!stop) { - malloc_info(0, stderr); + dump_malloc_info(); this_thread::sleep_for(chrono::milliseconds(millisecond_interval)); } - malloc_info(0, stderr); + // dump one last frame before going back to the main thread + dump_malloc_info(); } void start_dump_malloc_info(unsigned int millisecond_interval) { - cerr << "Will dump malloc info every " << millisecond_interval << "ms" << endl; - malloc_info(0, stderr); + // dump an early first frame before starting up the thread + dump_malloc_info(); + if (runner) { stop_dump_malloc_info(); } -- 2.7.4