Browse Source

[logging] log system time and mock time

tags/v0.15.1
John Newbery 4 years ago
parent
commit
761392db3a
3 changed files with 11 additions and 11 deletions
  1. 5
    1
      src/util.cpp
  2. 5
    9
      src/utiltime.cpp
  3. 1
    1
      src/utiltime.h

+ 5
- 1
src/util.cpp View File

@@ -310,10 +310,14 @@ static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fSt
return str;

if (*fStartedNewLine) {
int64_t nTimeMicros = GetLogTimeMicros();
int64_t nTimeMicros = GetTimeMicros();
strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000);
if (fLogTimeMicros)
strStamped += strprintf(".%06d", nTimeMicros%1000000);
int64_t mocktime = GetMockTime();
if (mocktime) {
strStamped += " (mocktime: " + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", mocktime) + ")";
}
strStamped += ' ' + str;
} else
strStamped = str;

+ 5
- 9
src/utiltime.cpp View File

@@ -31,6 +31,11 @@ void SetMockTime(int64_t nMockTimeIn)
nMockTime.store(nMockTimeIn, std::memory_order_relaxed);
}

int64_t GetMockTime()
{
return nMockTime.load(std::memory_order_relaxed);
}

int64_t GetTimeMillis()
{
int64_t now = (boost::posix_time::microsec_clock::universal_time() -
@@ -52,15 +57,6 @@ int64_t GetSystemTimeInSeconds()
return GetTimeMicros()/1000000;
}

/** Return a time useful for the debug log */
int64_t GetLogTimeMicros()
{
int64_t mocktime = nMockTime.load(std::memory_order_relaxed);
if (mocktime) return mocktime*1000000;

return GetTimeMicros();
}

void MilliSleep(int64_t n)
{


+ 1
- 1
src/utiltime.h View File

@@ -23,8 +23,8 @@ int64_t GetTime();
int64_t GetTimeMillis();
int64_t GetTimeMicros();
int64_t GetSystemTimeInSeconds(); // Like GetTime(), but not mockable
int64_t GetLogTimeMicros();
void SetMockTime(int64_t nMockTimeIn);
int64_t GetMockTime();
void MilliSleep(int64_t n);

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

Loading…
Cancel
Save