22#define MEASUREMENT_H
33
44#include < string>
5+ #ifdef _WIN32
6+ #include < process.h>
7+ #else
8+ #include < unistd.h>
9+ #endif
510
611#include " callgrind.h"
712
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+
825inline std::string get_version () {
926#ifdef CODSPEED_VERSION
1027 return {CODSPEED_VERSION};
@@ -13,22 +30,40 @@ inline std::string get_version() {
1330#endif
1431}
1532
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+ }
1744
1845inline 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 ());
2149}
2250
2351__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.
2455 CALLGRIND_ZERO_STATS;
2556 CALLGRIND_START_INSTRUMENTATION;
57+
58+ instrument_hooks_start_benchmark (get_hooks ());
2659}
2760
2861__attribute__ ((always_inline)) inline void measurement_stop(
29- const std::string & name) {
62+ const std::string& name) {
3063 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 ());
3267};
3368
3469#endif // MEASUREMENT_H
0 commit comments