db_bench -use_stderr_info_logger to print timestamp (#10435)

Summary:
Right now db_bench -use_stderr_info_logger would redirect RocksDB info logging to stderr but no timetamp is printed out. Add timestamp to there.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10435

Test Plan: Run "db_bench -use_stderr_info_logger"

Reviewed By: riversand963

Differential Revision: D38258699

fbshipit-source-id: 3fee6eb1205127b923bc6a660f86bd2742519aec
main
sdong 2 years ago committed by Facebook GitHub Bot
parent 15da225268
commit aec28ebae6
  1. 13
      util/stderr_logger.h

@ -8,6 +8,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include "port/sys_time.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
@ -23,6 +24,18 @@ class StderrLogger : public Logger {
using Logger::Logv; using Logger::Logv;
virtual void Logv(const char* format, va_list ap) override { virtual void Logv(const char* format, va_list ap) override {
const uint64_t thread_id = Env::Default()->GetThreadID();
port::TimeVal now_tv;
port::GetTimeOfDay(&now_tv, nullptr);
const time_t seconds = now_tv.tv_sec;
struct tm t;
port::LocalTimeR(&seconds, &t);
fprintf(stderr, "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx ",
t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min,
t.tm_sec, static_cast<int>(now_tv.tv_usec),
static_cast<long long unsigned int>(thread_id));
vfprintf(stderr, format, ap); vfprintf(stderr, format, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }

Loading…
Cancel
Save