Skip to content

Commit 74f6096

Browse files
committed
feat: add instrument-hooks
1 parent 8a6b904 commit 74f6096

File tree

7 files changed

+20
-7323
lines changed

7 files changed

+20
-7323
lines changed

core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ endif()
5454
add_library(
5555
codspeed
5656
src/codspeed.cpp
57+
src/measurement.cpp
5758
src/walltime.cpp
5859
src/uri.cpp
5960
src/workspace.cpp

core/include/callgrind.h

Lines changed: 0 additions & 124 deletions
This file was deleted.

core/include/measurement.hpp

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,20 @@
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

1514
extern "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

2722
inline 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
3630
inline 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

Comments
 (0)