Add real timestamp to log output when mock time is enabled (#2604)

* Implement IsMockTime to test for mock time

* Add real timestamp to log output when mock time is enabled

This makes debugging on Travis easier as it gives a hint about timing
behavior.
This commit is contained in:
Alexander Block 2019-01-03 10:21:19 +01:00 committed by UdjinM6
parent 0648496e21
commit 968eb3fc5d
3 changed files with 11 additions and 1 deletions

View File

@ -316,8 +316,12 @@ static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fSt
return str; return str;
if (*fStartedNewLine) { if (*fStartedNewLine) {
if (IsMockTime()) {
int64_t nRealTimeMicros = GetTimeMicros();
strStamped = DateTimeStrFormat("(real %Y-%m-%d %H:%M:%S) ", nRealTimeMicros/1000000);
}
int64_t nTimeMicros = GetLogTimeMicros(); int64_t nTimeMicros = GetLogTimeMicros();
strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000); strStamped += DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000);
if (fLogTimeMicros) if (fLogTimeMicros)
strStamped += strprintf(".%06d", nTimeMicros%1000000); strStamped += strprintf(".%06d", nTimeMicros%1000000);
strStamped += ' ' + str; strStamped += ' ' + str;

View File

@ -29,6 +29,11 @@ void SetMockTime(int64_t nMockTimeIn)
nMockTime = nMockTimeIn; nMockTime = nMockTimeIn;
} }
bool IsMockTime()
{
return nMockTime != 0;
}
int64_t GetTimeMillis() int64_t GetTimeMillis()
{ {
int64_t now = (boost::posix_time::microsec_clock::universal_time() - int64_t now = (boost::posix_time::microsec_clock::universal_time() -

View File

@ -25,6 +25,7 @@ int64_t GetTimeMicros();
int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable
int64_t GetLogTimeMicros(); int64_t GetLogTimeMicros();
void SetMockTime(int64_t nMockTimeIn); void SetMockTime(int64_t nMockTimeIn);
bool IsMockTime();
void MilliSleep(int64_t n); void MilliSleep(int64_t n);
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime); std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime);