4
4
#include < string>
5
5
#ifdef _WIN32
6
6
#include < process.h>
7
+ #define getpid _getpid
8
+ #define ALWAYS_INLINE __forceinline
7
9
#else
8
10
#include < unistd.h>
9
- #endif
10
-
11
- #ifdef CODSPEED_INSTRUMENTATION
12
- #include " callgrind.h"
11
+ #define ALWAYS_INLINE __attribute__ ((always_inline)) inline
13
12
#endif
14
13
15
14
extern " C" {
16
15
#include " core.h"
17
16
}
18
17
19
- static InstrumentHooks* g_hooks = nullptr ;
18
+ extern InstrumentHooks* g_hooks;
20
19
21
- inline void measurement_init () {
22
- if (!g_hooks) {
23
- g_hooks = instrument_hooks_init ();
24
- }
25
- }
20
+ void measurement_init ();
26
21
27
22
inline std::string get_version () {
28
23
#ifdef CODSPEED_VERSION
@@ -32,7 +27,6 @@ inline std::string get_version() {
32
27
#endif
33
28
}
34
29
35
- #ifdef CODSPEED_INSTRUMENTATION
36
30
inline bool measurement_is_instrumented () {
37
31
return instrument_hooks_is_instrumented (g_hooks);
38
32
}
@@ -42,32 +36,17 @@ inline void measurement_set_metadata() {
42
36
instrument_hooks_set_integration (g_hooks, " codspeed-cpp" , version.c_str ());
43
37
}
44
38
45
- __attribute__ ((always_inline)) inline void measurement_start() {
39
+ ALWAYS_INLINE void measurement_start () {
46
40
instrument_hooks_start_benchmark_inline (g_hooks);
47
41
}
48
42
49
- __attribute__ ((always_inline)) inline void measurement_stop() {
43
+ ALWAYS_INLINE void measurement_stop () {
50
44
instrument_hooks_stop_benchmark_inline (g_hooks);
51
45
}
52
46
53
- __attribute__ ((always_inline)) inline void measurement_executed_benchmark(
54
- const std::string& name) {
55
- #ifdef _WIN32
56
- auto current_pid = _getpid ();
57
- #else
47
+ ALWAYS_INLINE void measurement_set_executed_benchmark (const std::string& name) {
58
48
auto current_pid = getpid ();
59
- #endif
60
49
instrument_hooks_executed_benchmark (g_hooks, current_pid, name.c_str ());
61
50
}
62
- #else
63
- // Stub implementations for non-instrumentation builds
64
- inline bool measurement_is_instrumented () { return false ; }
65
- inline void measurement_set_metadata () {}
66
- inline void measurement_start () {}
67
- inline void measurement_stop () {}
68
- inline void measurement_executed_benchmark (const std::string& name) {
69
- (void )name;
70
- }
71
- #endif
72
51
73
52
#endif // MEASUREMENT_H
0 commit comments