-
Notifications
You must be signed in to change notification settings - Fork 2
/
timers.h
97 lines (81 loc) · 1.77 KB
/
timers.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef _SQLITE_SRC_TIMERS_H_
#define _SQLITE_SRC_TIMERS_H_
#include <sys/time.h>
#include <string.h>
#include <time.h>
#include <stdatomic.h>
enum instrumentation_vars {
open_t,
close_t,
pread_t,
pwrite_t,
read_t,
write_t,
seek_t,
fsync_t,
unlink_t,
bg_thread_t,
memcpy_to_pmem_t,
fsync_noop_t,
neword_t,
payment_t,
ordstat_t,
delivery_t,
slev_t,
INSTRUMENT_NUM,
};
atomic_uint_least64_t Instrustats[INSTRUMENT_NUM];
static const char *Instruprint[INSTRUMENT_NUM] =
{
"open",
"close",
"pread",
"pwrite",
"read",
"write",
"seek",
"fsync",
"unlink",
"bg_thread",
"memcpy_to_pmem",
"fsync_noop",
"neword",
"payment",
"ordstat",
"delivery",
"slev",
};
typedef struct timespec instrumentation_type;
#define INSTRUMENT_CALLS 1
#define INITIALIZE_TIMERS() \
{ \
int i; \
for (i = 0; i < INSTRUMENT_NUM; i++) \
Instrustats[i] = 0; \
} \
#if INSTRUMENT_CALLS
#define START_TIMING(name, start) \
{ \
clock_gettime(CLOCK_MONOTONIC, &start); \
}
#define END_TIMING(name, start) \
{ \
instrumentation_type end; \
clock_gettime(CLOCK_MONOTONIC, &end); \
__atomic_fetch_add(&Instrustats[name], (end.tv_sec - start.tv_sec) * 1000000000 + (end.tv_nsec - start.tv_nsec), __ATOMIC_SEQ_CST); \
}
#define PRINT_TIME() \
{ \
int i; \
printf("\n ----------------------\n"); \
for(i=0; i<INSTRUMENT_NUM; i++) \
if (Instrustats[i] > 0) \
printf("%s: timing = %lu nanoseconds\n", \
Instruprint[i], Instrustats[i]); \
}
#else
#define START_TIMING(name, start) {(void)(start);}
#define END_TIMING(name, start) {(void)(start);}
#define PRINT_TIME() {(void)(Instrustats[0]);}
#endif
#endif