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#ifdef CODSPEED_INSTRUMENTATION
712#include " callgrind.h"
813#endif
914
15+ extern " C" {
16+ #include " core.h"
17+ }
18+
19+ static InstrumentHooks* g_hooks = nullptr ;
20+
21+ inline void measurement_init () {
22+ if (!g_hooks) {
23+ g_hooks = instrument_hooks_init ();
24+ }
25+ }
26+
1027inline std::string get_version () {
1128#ifdef CODSPEED_VERSION
1229 return {CODSPEED_VERSION};
@@ -16,29 +33,41 @@ inline std::string get_version() {
1633}
1734
1835#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 (g_hooks);
38+ }
2039
2140inline 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 (g_hooks, " codspeed-cpp " , version .c_str ());
2443}
2544
2645__attribute__ ((always_inline)) inline void measurement_start() {
27- CALLGRIND_ZERO_STATS;
28- CALLGRIND_START_INSTRUMENTATION;
46+ instrument_hooks_start_benchmark_inline (g_hooks);
47+ }
48+
49+ __attribute__ ((always_inline)) inline void measurement_stop() {
50+ instrument_hooks_stop_benchmark_inline (g_hooks);
2951}
3052
31- __attribute__ ((always_inline)) inline void measurement_stop(
32- const std::string &name) {
33- CALLGRIND_STOP_INSTRUMENTATION;
34- CALLGRIND_DUMP_STATS_AT (name.c_str ());
35- };
53+ __attribute__ ((always_inline)) inline void measurement_executed_benchmark(
54+ const std::string& name) {
55+ #ifdef _WIN32
56+ auto current_pid = _getpid ();
57+ #else
58+ auto current_pid = getpid ();
59+ #endif
60+ instrument_hooks_executed_benchmark (g_hooks, current_pid, name.c_str ());
61+ }
3662#else
3763// Stub implementations for non-instrumentation builds
3864inline bool measurement_is_instrumented () { return false ; }
3965inline void measurement_set_metadata () {}
4066inline void measurement_start () {}
41- inline void measurement_stop (const std::string &name) { (void )name; }
67+ inline void measurement_stop () {}
68+ inline void measurement_executed_benchmark (const std::string& name) {
69+ (void )name;
70+ }
4271#endif
4372
4473#endif // MEASUREMENT_H
0 commit comments