Skip to content

Commit dee9e5c

Browse files
feat(go-runner): collect Go toolchain environment information
Integrate with the new instrument-hooks environment collection API to report Go toolchain metadata (version, OS, arch) alongside benchmark runs. Updates instrument-hooks to e86719c which adds the set_environment/write_environment C API. Generated with AI Agent (Claude Code)
1 parent 12ee23e commit dee9e5c

7 files changed

Lines changed: 44 additions & 14 deletions

File tree

go-runner/overlay/benchmark1.24.0.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ func runBenchmarks(importPath string, matchString func(pat, str string) (bool, e
755755
bstate: bstate,
756756
}
757757
defer main.codspeed.instrument_hooks.Close()
758+
writeGoEnvironment(main.codspeed.instrument_hooks)
758759

759760
if Verbose() {
760761
main.chatty = newChattyPrinter(main.w)

go-runner/overlay/benchmark1.24.0.patch

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,24 +357,25 @@
357357
importPath: importPath,
358358
benchFunc: func(b *B) {
359359
for _, Benchmark := range bs {
360-
@@ -644,6 +754,8 @@
360+
@@ -644,6 +754,9 @@
361361
benchTime: benchTime,
362362
bstate: bstate,
363363
}
364364
+ defer main.codspeed.instrument_hooks.Close()
365+
+ writeGoEnvironment(main.codspeed.instrument_hooks)
365366
+
366367
if Verbose() {
367368
main.chatty = newChattyPrinter(main.w)
368369
}
369-
@@ -672,6 +784,7 @@
370+
@@ -672,6 +785,7 @@
370371
chatty: b.chatty,
371372
bench: true,
372373
},
373374
+ codspeed: b.codspeed,
374375
benchFunc: b.benchFunc,
375376
benchTime: b.benchTime,
376377
}
377-
@@ -679,6 +792,8 @@
378+
@@ -679,6 +793,8 @@
378379
}
379380
r := b.doBench()
380381
if b.failed {
@@ -383,7 +384,7 @@
383384
// The output could be very long here, but probably isn't.
384385
// We print it all, regardless, because we don't want to trim the reason
385386
// the benchmark failed.
386-
@@ -686,6 +801,8 @@
387+
@@ -686,6 +802,8 @@
387388
continue
388389
}
389390
results := r.String()
@@ -392,7 +393,7 @@
392393
if b.chatty != nil {
393394
fmt.Fprintf(b.w, "%-*s\t", s.maxLen, benchName)
394395
}
395-
@@ -746,6 +863,7 @@
396+
@@ -746,6 +864,7 @@
396397
chatty: b.chatty,
397398
bench: true,
398399
},

go-runner/overlay/benchmark1.25.0.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ func runBenchmarks(importPath string, matchString func(pat, str string) (bool, e
756756
bstate: bstate,
757757
}
758758
defer main.codspeed.instrument_hooks.Close()
759+
writeGoEnvironment(main.codspeed.instrument_hooks)
759760

760761
if Verbose() {
761762
main.chatty = newChattyPrinter(main.w)

go-runner/overlay/benchmark1.25.0.patch

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,24 +226,25 @@
226226
importPath: importPath,
227227
benchFunc: func(b *B) {
228228
for _, Benchmark := range bs {
229-
@@ -724,6 +755,8 @@
229+
@@ -724,6 +755,9 @@
230230
benchTime: benchTime,
231231
bstate: bstate,
232232
}
233233
+ defer main.codspeed.instrument_hooks.Close()
234+
+ writeGoEnvironment(main.codspeed.instrument_hooks)
234235
+
235236
if Verbose() {
236237
main.chatty = newChattyPrinter(main.w)
237238
}
238-
@@ -752,6 +785,7 @@
239+
@@ -752,6 +786,7 @@
239240
chatty: b.chatty,
240241
bench: true,
241242
},
242243
+ codspeed: b.codspeed,
243244
benchFunc: b.benchFunc,
244245
benchTime: b.benchTime,
245246
}
246-
@@ -760,6 +794,8 @@
247+
@@ -760,6 +795,8 @@
247248
}
248249
r := b.doBench()
249250
if b.failed {
@@ -252,7 +253,7 @@
252253
// The output could be very long here, but probably isn't.
253254
// We print it all, regardless, because we don't want to trim the reason
254255
// the benchmark failed.
255-
@@ -767,6 +803,8 @@
256+
@@ -767,6 +804,8 @@
256257
continue
257258
}
258259
results := r.String()
@@ -261,7 +262,7 @@
261262
if b.chatty != nil {
262263
fmt.Fprintf(b.w, "%-*s\t", s.maxLen, benchName)
263264
}
264-
@@ -827,6 +865,7 @@
265+
@@ -827,6 +866,7 @@
265266
chatty: b.chatty,
266267
bench: true,
267268
},

go-runner/overlay/codspeed.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import (
1313
"time"
1414
)
1515

16+
func writeGoEnvironment(hooks *InstrumentHooks) {
17+
hooks.SetEnvironment("go", "version", runtime.Version())
18+
hooks.WriteEnvironment(uint32(os.Getpid()))
19+
}
20+
1621
type codspeed struct {
1722
instrument_hooks *InstrumentHooks
1823

go-runner/overlay/instrument-hooks.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ package testing
44
#cgo CFLAGS: -I@@INSTRUMENT_HOOKS_DIR@@/includes -Wno-format -Wno-format-security
55
#include "@@INSTRUMENT_HOOKS_DIR@@/dist/core.c"
66
7-
#define MARKER_TYPE_BENCHMARK_START c_MARKER_TYPE_BENCHMARK_START__249
8-
#define MARKER_TYPE_BENCHMARK_END c_MARKER_TYPE_BENCHMARK_END__250
9-
typedef struct instruments_root_InstrumentHooks__547 InstrumentHooks;
7+
#define MARKER_TYPE_BENCHMARK_START c_MARKER_TYPE_BENCHMARK_START__247
8+
#define MARKER_TYPE_BENCHMARK_END c_MARKER_TYPE_BENCHMARK_END__248
9+
typedef struct instrument_hooks_InstrumentHooks__547 InstrumentHooks;
1010
*/
1111
import "C"
1212
import (
@@ -95,3 +95,24 @@ func (i *InstrumentHooks) AddBenchmarkTimestamps(startTimestamp, endTimestamp ui
9595
C.instrument_hooks_add_marker(i.hooks, C.uint32_t(pid), C.MARKER_TYPE_BENCHMARK_START, C.uint64_t(startTimestamp))
9696
C.instrument_hooks_add_marker(i.hooks, C.uint32_t(pid), C.MARKER_TYPE_BENCHMARK_END, C.uint64_t(endTimestamp))
9797
}
98+
99+
func (i *InstrumentHooks) SetEnvironment(sectionName, key, value string) {
100+
if i.hooks == nil {
101+
return
102+
}
103+
sectionNameC := C.CString(sectionName)
104+
keyC := C.CString(key)
105+
valueC := C.CString(value)
106+
defer C.free(unsafe.Pointer(sectionNameC))
107+
defer C.free(unsafe.Pointer(keyC))
108+
defer C.free(unsafe.Pointer(valueC))
109+
110+
C.instrument_hooks_set_environment(i.hooks, (*C.uint8_t)(unsafe.Pointer(sectionNameC)), (*C.uint8_t)(unsafe.Pointer(keyC)), (*C.uint8_t)(unsafe.Pointer(valueC)))
111+
}
112+
113+
func (i *InstrumentHooks) WriteEnvironment(pid uint32) {
114+
if i.hooks == nil {
115+
return
116+
}
117+
C.instrument_hooks_write_environment(i.hooks, C.uint32_t(pid))
118+
}

go-runner/src/runner/overlay/instrument_hooks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use tar::Archive;
66
use tempfile::TempDir;
77

88
const INSTRUMENT_HOOKS_REPO: &str = "CodSpeedHQ/instrument-hooks";
9-
const INSTRUMENT_HOOKS_COMMIT: &str = "1752e9e4eae585e26703932d0055a1473dd77048";
9+
const INSTRUMENT_HOOKS_COMMIT: &str = "e86719c70c9c0b1646db182a7c748230e243dace";
1010

1111
/// Get the instrument-hooks directory, downloading if necessary
1212
/// Downloads to /tmp/codspeed-instrument-hooks-{commit}/

0 commit comments

Comments
 (0)