Skip to content

Commit

Permalink
Initialize the start time on first use
Browse files Browse the repository at this point in the history
This ensures the data is properly initialized, the global
static initialization may happen too late otherwise.
  • Loading branch information
milianw committed Apr 22, 2018
1 parent 21cc733 commit 51f3ad7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/track/libheaptrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ using namespace std;
namespace {

using clock = chrono::steady_clock;
const chrono::time_point<clock> s_start = clock::now();
chrono::time_point<clock> startTime()
{
static const chrono::time_point<clock> s_start = clock::now();
return s_start;
}

chrono::milliseconds elapsedTime()
{
return chrono::duration_cast<chrono::milliseconds>(clock::now() - s_start);
return chrono::duration_cast<chrono::milliseconds>(clock::now() - startTime());
}

__pid_t gettid()
Expand Down Expand Up @@ -656,6 +661,8 @@ void heaptrack_init(const char* outputFileName, heaptrack_callback_t initBeforeC
heaptrack_callback_initialized_t initAfterCallback, heaptrack_callback_t stopCallback)
{
RecursionGuard guard;
// initialize
startTime();

debugLog<MinimalOutput>("heaptrack_init(%s)", outputFileName);

Expand Down

0 comments on commit 51f3ad7

Please sign in to comment.