10 #define PERF_TIMER_START
11 #define PERF_TIMER_STOP
12 #define PERF_TIMER_DELTA 1
20 #define DLOG_BASENAME_ONLY 1
23 #undef DLOG_BASENAME_ONLY
26 #if DLOG_BASENAME_ONLY
28 #define dLog_pre() fprintf(stderr, "[%s:%i:%s] ", basename(__FILE__), __LINE__, __func__)
30 #define dLog_pre() fprintf(stderr, "[%s:%i:%s] ", __FILE__, __LINE__, __func__)
36 fprintf(stderr, __VA_ARGS__); \
37 fprintf(stderr, "\n"); \
46 if (x) { dBreak(); } \
48 #define dBreakCount(x) \
50 static int count = 0; \
51 if (++count == (x)) dBreak(); \
55 #define PERF_TIMER_START
56 #define PERF_TIMER_STOP
57 #define PERF_TIMER_DELTA 1
60 #define PERF_TIMER_START \
61 struct timeval PERF_TIMER_T1, PERF_TIMER_T2; \
62 gettimeofday(&PERF_TIMER_T1, NULL);
63 #define PERF_TIMER_STOP gettimeofday(&PERF_TIMER_T2, NULL);
64 #define PERF_TIMER_DELTA ((PERF_TIMER_T2.tv_usec - PERF_TIMER_T1.tv_usec) / 1000000.0 + (double)(PERF_TIMER_T2.tv_sec - PERF_TIMER_T1.tv_sec))
68 #define PRINT_BACKTRACE()
71 #define PRINT_BACKTRACE(...) \
73 printf("------------------ %s", __func__); \
74 printf(__VA_ARGS__); \
75 printf(" ------------------\n"); \
76 void **buffer = (void **)malloc(sizeof(void *) * 32); \
77 int depth = backtrace(buffer, 32); \
79 backtrace_symbols_fd(buffer, depth, fileno(stdout)); \
91 #define NARG(...) NARG_(__VA_ARGS__, RSEQ_N())
92 #define NARG_(...) ARG_N(__VA_ARGS__)
93 #define ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
94 #define RSEQ_N() 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
97inline void PRINTARG(
int x) { printf(
"%i", x); }
98inline void PRINTARG(
long x) { printf(
"%li", x); }
99inline void PRINTARG(
size_t x) { printf(
"%li", x); }
102inline void PRINTARG(
bool x) { printf(
"%s", x ?
"true" :
"false"); }
103inline void PRINTARG(
const std::string x) { printf(
"\"%s\"", x.c_str()); }
104inline void PRINTARG(
const char *x) { printf(
"\"%s\"", x); }
105 #ifdef VDC_LIBTRACE_RUNNABLE
106inline void PRINTARG(
const int *i) { printf(
"(int[]){%i}", *i); }
107inline void PRINTARG(
const float *f) { printf(
"(float[]){%f}", *f); }
108inline void PRINTARG(
const double *d) { printf(
"(double[]){%d}", *d); }
109inline void PRINTARG(
const size_t *li) { printf(
"(size_t[]){%li}", *li); }
110inline void PRINTARG(
const long *li) { printf(
"(long[]){%li}", *li); }
112inline void PRINTARG(
const int *i) { printf(
"*[%i]", *i); }
113inline void PRINTARG(
const float *f) { printf(
"*[%f]", *f); }
114inline void PRINTARG(
const double *d) { printf(
"*[%f]", *d); }
115inline void PRINTARG(
const size_t *li) { printf(
"*[%li]", *li); }
116inline void PRINTARG(
const long *li) { printf(
"*[%li]", *li); }
118inline void PRINTARG(
const void *x) { printf(
"%s", x ?
"<ptr>" :
"NULL"); }
133template<
class T>
void PRINTARG(
const std::vector<T> v)
135 #ifdef VDC_LIBTRACE_RUNNABLE
137 string t(__PRETTY_FUNCTION__);
138 int s = t.find(
"[T = ") + strlen(
"[T = ");
139 int f = t.find(
"]", s);
140 t = t.substr(s, f - s);
141 printf(
"vector<%s>(1, ", t.c_str());
145 for (
int i = 0; i < v.size(); i++) {
147 if (i != v.size() - 1) printf(
", ");
149 #ifdef VDC_LIBTRACE_RUNNABLE
159 size_t args = pretty.find(
"(");
160 size_t colons = pretty.substr(0, args).rfind(
"::");
161 if (colons == std::string::npos)
return "";
162 size_t begin = pretty.substr(0, colons).rfind(
" ") + 1;
163 size_t end = colons - begin;
165 return pretty.substr(begin, end) +
"::";
168 #define _CONCAT(a, b) a##b
169 #define PRINTARGS_1(x, ...) \
173 #define PRINTARGS_2(x, ...) \
177 PRINTARGS_1(__VA_ARGS__); \
179 #define PRINTARGS_3(x, ...) \
183 PRINTARGS_2(__VA_ARGS__); \
185 #define PRINTARGS_4(x, ...) \
189 PRINTARGS_3(__VA_ARGS__); \
191 #define PRINTARGS_5(x, ...) \
195 PRINTARGS_4(__VA_ARGS__); \
197 #define PRINTARGS_6(x, ...) \
201 PRINTARGS_5(__VA_ARGS__); \
203 #define PRINTARGS_7(x, ...) \
207 PRINTARGS_6(__VA_ARGS__); \
209 #define PRINTARGS_8(x, ...) \
213 PRINTARGS_7(__VA_ARGS__); \
215 #define PRINTARGS_9(x, ...) \
219 PRINTARGS_8(__VA_ARGS__); \
221 #define _PRINTARGS(n, ...) \
222 _CONCAT(PRINTARGS_, n) \
224 #define PRINTARGS(...) _PRINTARGS(NARG(__VA_ARGS__), __VA_ARGS__)
225 #define FTRACE_PRE() printf("%s%s(", classScopeFromPrettyFunc(__PRETTY_FUNCTION__).c_str(), __func__)
226 #define FTRACE(...) \
229 PRINTARGS(__VA_ARGS__); \
std::string classScopeFromPrettyFunc(const std::string &pretty)