-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathtracer.h
59 lines (56 loc) · 2.71 KB
/
tracer.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
/* time tracer */
#pragma once
#include <time.h>
#define time_diff(start, end) \
(end.tv_nsec - start.tv_nsec < 0 \
? (1000000000 + end.tv_nsec - start.tv_nsec) \
: (end.tv_nsec - start.tv_nsec))
#define time_check(_FUNC_) \
do { \
struct timespec time_start; \
struct timespec time_end; \
double during; \
clock_gettime(CLOCK_MONOTONIC, &time_start); \
_FUNC_; \
clock_gettime(CLOCK_MONOTONIC, &time_end); \
during = time_diff(time_start, time_end); \
printf("[tracer] %s: %f ns\n", #_FUNC_, during); \
} while (0)
#define __time_check(_FUNC_) \
do { \
struct timespec time_start; \
struct timespec time_end; \
double during; \
clock_gettime(CLOCK_MONOTONIC, &time_start); \
_FUNC_; \
clock_gettime(CLOCK_MONOTONIC, &time_end); \
during = time_diff(time_start, time_end); \
printf("%f\n", #_FUNC_, during); \
} while (0)
#define time_check_return(_FUNC_) \
({ \
struct timespec time_start; \
struct timespec time_end; \
double during; \
clock_gettime(CLOCK_MONOTONIC, &time_start); \
_FUNC_; \
clock_gettime(CLOCK_MONOTONIC, &time_end); \
during = time_diff(time_start, time_end); \
during; \
})
#define time_check_loop(_FUNC_, times) \
do { \
double sum = 0; \
int i; \
for (i = 0; i < times; i++) \
sum += time_check_return(_FUNC_); \
printf("[tracer] loop %d : %f ns\n", times, sum); \
} while (0)
#define time_check_loop_return(_FUNC_, times) \
({ \
double sum = 0; \
int i; \
for (i = 0; i < times; i++) \
sum += time_check_return(_FUNC_); \
sum; \
})