-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.h
More file actions
83 lines (68 loc) · 2.53 KB
/
log.h
File metadata and controls
83 lines (68 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// -*- c++ -*-
#ifndef LOG_H
#define LOG_H
#include <memory>
#include <mutex>
#include "spdlog/spdlog.h"
extern std::unique_ptr<spdlog::logger> logger;
void InitializeLogger(const std::string &hostname);
class PerfLog {
struct timeval tv;
bool is_started;
uint32_t duration;
public:
PerfLog();
void Start();
void End();
void Show(const char *msg);
void Show(std::string str) { Show(str.c_str()); }
void Clear();
uint32_t duration_ms() const { return duration; }
};
#define abort_if(cond, ...) \
if (__builtin_expect(cond, 0)) { \
logger->critical(__VA_ARGS__); \
std::abort(); \
}
#define TBD() \
do { \
logger->critical("TBD: Implement {}", __PRETTY_FUNCTION__); \
abort(); \
} while (0) \
#define REMINDER(msg) \
static std::once_flag __call_once_flag; \
std::call_once( \
__call_once_flag, \
[]() { \
auto p = __PRETTY_FUNCTION__; \
logger->critical("TODO: In {}:{}, {} {}", __FILE__, __LINE__, \
__PRETTY_FUNCTION__, msg); \
}) \
// We don't use logger->trace because it's even lower than debug. We would like
// to turn on trace for only some tags.
static bool is_trace_enabled(std::string_view msg = "")
{
return (msg.length() > 0 && msg.at(0) == '\x7f');
}
template <typename ...T>
static void trace(std::string_view fmt, T... args)
{
if (is_trace_enabled(fmt)) {
logger->info(fmt.substr(1).data(), args...);
}
}
template <typename ...T>
static void debug(std::string_view fmt, T... args)
{
if (is_trace_enabled(fmt)) {
logger->debug(fmt.substr(1).data(), args...);
}
}
// Trace tags
#define TRACE_EXEC_ROUTINE // "\x7f" "Trace ExecRoutine: "
#define TRACE_GC // "\x7f" "Trace GC: "
#define TRACE_COMPLETION // "\x7f" "Trace Completion: "
// Debug tags
#define DBG_WORKLOAD // "\x7f" "Workload: "
#define DBG_DISPATCH // "\x7f" "Dispatch: "
#endif /* LOG_H */