Skip to content

Commit 761392d

Browse files
committed
[logging] log system time and mock time
1 parent 4b766fc commit 761392d

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/util.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,14 @@ static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fSt
310310
return str;
311311

312312
if (*fStartedNewLine) {
313-
int64_t nTimeMicros = GetLogTimeMicros();
313+
int64_t nTimeMicros = GetTimeMicros();
314314
strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000);
315315
if (fLogTimeMicros)
316316
strStamped += strprintf(".%06d", nTimeMicros%1000000);
317+
int64_t mocktime = GetMockTime();
318+
if (mocktime) {
319+
strStamped += " (mocktime: " + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", mocktime) + ")";
320+
}
317321
strStamped += ' ' + str;
318322
} else
319323
strStamped = str;

src/utiltime.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ void SetMockTime(int64_t nMockTimeIn)
3131
nMockTime.store(nMockTimeIn, std::memory_order_relaxed);
3232
}
3333

34+
int64_t GetMockTime()
35+
{
36+
return nMockTime.load(std::memory_order_relaxed);
37+
}
38+
3439
int64_t GetTimeMillis()
3540
{
3641
int64_t now = (boost::posix_time::microsec_clock::universal_time() -
@@ -52,15 +57,6 @@ int64_t GetSystemTimeInSeconds()
5257
return GetTimeMicros()/1000000;
5358
}
5459

55-
/** Return a time useful for the debug log */
56-
int64_t GetLogTimeMicros()
57-
{
58-
int64_t mocktime = nMockTime.load(std::memory_order_relaxed);
59-
if (mocktime) return mocktime*1000000;
60-
61-
return GetTimeMicros();
62-
}
63-
6460
void MilliSleep(int64_t n)
6561
{
6662

src/utiltime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ int64_t GetTime();
2323
int64_t GetTimeMillis();
2424
int64_t GetTimeMicros();
2525
int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable
26-
int64_t GetLogTimeMicros();
2726
void SetMockTime(int64_t nMockTimeIn);
27+
int64_t GetMockTime();
2828
void MilliSleep(int64_t n);
2929

3030
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime);

0 commit comments

Comments
 (0)