Skip to content

Commit d0c37ee

Browse files
committed
Merge #10383: [logging] log system time and mock time
761392d [logging] log system time and mock time (John Newbery) Tree-SHA512: 0a4b3ad74bcac201be490fe12e4b45adeabc39030ac46f40e1aeb2a20b2f3963e4468e65798d8aaeca1818759cab55ff2b2aa214500aa11571492c3301dd31c1
2 parents b6ee855 + 761392d commit d0c37ee

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
@@ -306,10 +306,14 @@ static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fSt
306306
return str;
307307

308308
if (*fStartedNewLine) {
309-
int64_t nTimeMicros = GetLogTimeMicros();
309+
int64_t nTimeMicros = GetTimeMicros();
310310
strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000);
311311
if (fLogTimeMicros)
312312
strStamped += strprintf(".%06d", nTimeMicros%1000000);
313+
int64_t mocktime = GetMockTime();
314+
if (mocktime) {
315+
strStamped += " (mocktime: " + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", mocktime) + ")";
316+
}
313317
strStamped += ' ' + str;
314318
} else
315319
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)