-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.h
102 lines (64 loc) · 2.87 KB
/
benchmark.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
98
99
100
101
102
#include "config.h"
#ifndef __BENCHMARK_MACROS__
#define __BENCHMARK_MACROS__
double getMilliseconds();
#if IHPP_BENCHMARK
class ThreadContext;
extern bool benchmark;
extern bool usePinThread;
extern bool useCurrFunc;
extern ThreadContext *__benchmarkThread;
extern ADDRINT __benchmarkFunc;
#define BENCHMARK_VARS unsigned int nodes_created,empty_nodes_created,nodes_copied,forests_copied;
#define BENCHMARK_INIT_VARS nodes_created=empty_nodes_created=nodes_copied=forests_copied=0;
#define BENCHMARK_ON benchmark=true;
#define BENCHMARK_OFF benchmark=false;
#define BENCHMARK_SET_THREAD(ctx) usePinThread=false; __benchmarkThread=(ctx);
#define BENCHMARK_SET_FUNC(addr) useCurrFunc=false; __benchmarkFunc=(addr);
#define __BM_CURR_PIN_TH_CTX globalSharedContext->getThreadCtx(PIN_ThreadUid())
#define __BM_CURR_TH (usePinThread ? __BM_CURR_PIN_TH_CTX : __benchmarkThread)
#define __BM_GET_FUNC (useCurrFunc ? __BM_CURR_TH->getCurrentFunction() : __benchmarkFunc)
#define __BM_CURR_FUNC (__BM_CURR_TH->getFunctionCtx(__BM_GET_FUNC))
#define __BM_INTRAMODE (globalSharedContext->WorkingMode() == WM_IntraMode)
#else
#define BENCHMARK_VARS
#define BENCHMARK_INIT_VARS
#define BENCHMARK_ON
#define BENCHMARK_OFF
#define BENCHMARK_SET_THREAD(tid)
#define BENCHMARK_SET_FUNC(addr)
#endif
inline void BM_inc_nodes_created();
inline void BM_inc_empty_nodes_created();
inline void BM_inc_nodes_copied();
inline void BM_inc_forests_copied();
class BenchmarkObj {
public:
BENCHMARK_VARS
#if IHPP_BENCHMARK
void _BM_sumBenchmarkInfo(BenchmarkObj *obj) {
nodes_created+=obj->nodes_created;
empty_nodes_created+=obj->empty_nodes_created;
nodes_copied+=obj->nodes_copied;
forests_copied+=obj->forests_copied;
}
#endif
};
#endif
#ifdef __IHPP_HEADER__
#if IHPP_BENCHMARK
inline void BM_inc_nodes_created()
{ if (benchmark) ((!__BM_INTRAMODE || !__BM_GET_FUNC) ? __BM_CURR_TH->nodes_created++ : __BM_CURR_FUNC->nodes_created++); }
inline void BM_inc_empty_nodes_created()
{ if (benchmark) ((!__BM_INTRAMODE || !__BM_GET_FUNC) ? __BM_CURR_TH->empty_nodes_created++ : __BM_CURR_FUNC->empty_nodes_created++); }
inline void BM_inc_nodes_copied()
{ if (benchmark) ((!__BM_INTRAMODE || !__BM_GET_FUNC) ? __BM_CURR_TH->nodes_copied++ : __BM_CURR_FUNC->nodes_copied++); }
inline void BM_inc_forests_copied()
{ if (benchmark) ((!__BM_INTRAMODE || !__BM_GET_FUNC) ? __BM_CURR_TH->forests_copied++ : __BM_CURR_FUNC->forests_copied++); }
#else
inline void BM_inc_nodes_created() { }
inline void BM_inc_empty_nodes_created() { }
inline void BM_inc_nodes_copied() { }
inline void BM_inc_forests_copied() { }
#endif
#endif