44#include < string>
55#ifdef _WIN32
66#include < process.h>
7+ #define getpid _getpid
8+ #define ALWAYS_INLINE __forceinline
79#else
810#include < unistd.h>
9- #endif
10-
11- #ifdef CODSPEED_INSTRUMENTATION
12- #include " callgrind.h"
11+ #define ALWAYS_INLINE __attribute__ ((always_inline)) inline
1312#endif
1413
1514extern " C" {
1615#include " core.h"
1716}
1817
19- static InstrumentHooks* g_hooks = nullptr ;
18+ extern InstrumentHooks* g_hooks;
2019
21- inline void measurement_init () {
22- if (!g_hooks) {
23- g_hooks = instrument_hooks_init ();
24- }
25- }
20+ void measurement_init ();
2621
2722inline std::string get_version () {
2823#ifdef CODSPEED_VERSION
@@ -32,7 +27,6 @@ inline std::string get_version() {
3227#endif
3328}
3429
35- #ifdef CODSPEED_INSTRUMENTATION
3630inline bool measurement_is_instrumented () {
3731 return instrument_hooks_is_instrumented (g_hooks);
3832}
@@ -42,32 +36,17 @@ inline void measurement_set_metadata() {
4236 instrument_hooks_set_integration (g_hooks, " codspeed-cpp" , version.c_str ());
4337}
4438
45- __attribute__ ((always_inline)) inline void measurement_start() {
39+ ALWAYS_INLINE void measurement_start () {
4640 instrument_hooks_start_benchmark_inline (g_hooks);
4741}
4842
49- __attribute__ ((always_inline)) inline void measurement_stop() {
43+ ALWAYS_INLINE void measurement_stop () {
5044 instrument_hooks_stop_benchmark_inline (g_hooks);
5145}
5246
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) {
5848 auto current_pid = getpid ();
59- #endif
6049 instrument_hooks_executed_benchmark (g_hooks, current_pid, name.c_str ());
6150}
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
7251
7352#endif // MEASUREMENT_H
0 commit comments