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