2
2
#define MEASUREMENT_H
3
3
4
4
#include < string>
5
+ #ifdef _WIN32
6
+ #include < process.h>
7
+ #else
8
+ #include < unistd.h>
9
+ #endif
5
10
6
11
#ifdef CODSPEED_INSTRUMENTATION
7
12
#include " callgrind.h"
8
13
#endif
9
14
15
+ extern " C" {
16
+ #include " core.h"
17
+ }
18
+
19
+ inline InstrumentHooks* get_hooks () {
20
+ static InstrumentHooks* g_hooks = nullptr ;
21
+ if (!g_hooks) {
22
+ g_hooks = instrument_hooks_init ();
23
+ }
24
+ return g_hooks;
25
+ }
26
+
10
27
inline std::string get_version () {
11
28
#ifdef CODSPEED_VERSION
12
29
return {CODSPEED_VERSION};
@@ -16,29 +33,45 @@ inline std::string get_version() {
16
33
}
17
34
18
35
#ifdef CODSPEED_INSTRUMENTATION
19
- inline bool measurement_is_instrumented () { return RUNNING_ON_VALGRIND; }
36
+ inline bool measurement_is_instrumented () {
37
+ return instrument_hooks_is_instrumented (get_hooks ());
38
+ }
20
39
21
40
inline void measurement_set_metadata () {
22
- std::string metadata = " Metadata: codspeed-cpp " + get_version ();
23
- CALLGRIND_DUMP_STATS_AT (metadata.c_str ());
41
+ std::string version = get_version ();
42
+ instrument_hooks_set_integration (get_hooks (), " codspeed-cpp" ,
43
+ version.c_str ());
24
44
}
25
45
26
46
__attribute__ ((always_inline)) inline void measurement_start() {
47
+ // Keep the callgrind macros here, so that they are properly inlined.
48
+ // Otherwise, we have an additional function call overhead to the
49
+ // instrument-hooks library.
27
50
CALLGRIND_ZERO_STATS;
28
51
CALLGRIND_START_INSTRUMENTATION;
52
+
53
+ instrument_hooks_start_benchmark (get_hooks ());
29
54
}
30
55
31
56
__attribute__ ((always_inline)) inline void measurement_stop(
32
- const std::string & name) {
57
+ const std::string& name) {
33
58
CALLGRIND_STOP_INSTRUMENTATION;
34
- CALLGRIND_DUMP_STATS_AT (name.c_str ());
59
+
60
+ instrument_hooks_stop_benchmark (get_hooks ());
61
+
62
+ #ifdef _WIN32
63
+ auto current_pid = _getpid ();
64
+ #else
65
+ auto current_pid = getpid ();
66
+ #endif
67
+ instrument_hooks_executed_benchmark (get_hooks (), current_pid, name.c_str ());
35
68
};
36
69
#else
37
70
// Stub implementations for non-instrumentation builds
38
71
inline bool measurement_is_instrumented () { return false ; }
39
72
inline void measurement_set_metadata () {}
40
73
inline void measurement_start () {}
41
- inline void measurement_stop (const std::string & name) { (void )name; }
74
+ inline void measurement_stop (const std::string& name) { (void )name; }
42
75
#endif
43
76
44
77
#endif // MEASUREMENT_H
0 commit comments