Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:

compat-integration-test-walltime:
runs-on: codspeed-macro
strategy:
matrix:
target: [example, example/compat, example/timing, example/very/nested/module]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -53,7 +56,7 @@ jobs:
with:
mode: walltime
working-directory: example
run: cargo r --manifest-path ../go-runner/Cargo.toml -- test -bench=.
run: cargo r --release --manifest-path ../go-runner/Cargo.toml -- test -bench=. ${{ matrix.target }}

check:
runs-on: ubuntu-latest
Expand Down
45 changes: 45 additions & 0 deletions example/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package example

import "time"

//go:noinline
func recursiveFib(n int) uint64 {
if n <= 1 {
return uint64(n)
}
return recursiveFib(n-1) + recursiveFib(n-2)
}

//go:noinline
func expensiveOperation() uint64 {
// Large memory allocation
data := make([]uint64, 1024*1024) // 8 MiB allocation
for i := range data {
data[i] = 42
}

// Expensive recursive computation that will dominate flamegraph
fibResult := recursiveFib(30)

// More expensive work - sum the data
sum := uint64(0)
for _, v := range data {
sum += v
}

return sum + fibResult
}

//go:noinline
func doWork(n int) uint64 {
if n <= 1 {
return uint64(n)
}
return doWork(n-1) + doWork(n-2)
}

func actualWork() uint64 {
time.Sleep(1 * time.Millisecond)
result := doWork(30)
return 42 + result
}
29 changes: 29 additions & 0 deletions example/setup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package example

import (
"runtime"
"testing"
)

func BenchmarkLargeSetup(b *testing.B) {
expensiveOperation()
b.ResetTimer()

var result uint64
for i := 0; i < b.N; i++ {
result = actualWork()
}
runtime.KeepAlive(result)
}

func BenchmarkLargeSetupInLoop(b *testing.B) {
var result uint64
for i := 0; i < b.N; i++ {
b.StopTimer()
expensiveOperation()
b.StartTimer()

result = actualWork()
}
runtime.KeepAlive(result)
}
2 changes: 1 addition & 1 deletion example/sleep_test.go → example/timing/sleep_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package example
package timing

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep100ns",
"uri": "example/sleep_test.go::BenchmarkSleep100ns",
"name": "BenchmarkLargeSetup",
"uri": "example/setup_test.go::BenchmarkLargeSetup",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -81,8 +81,31 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep100ns_Loop",
"uri": "example/sleep_test.go::BenchmarkSleep100ns_Loop",
"name": "BenchmarkLargeSetupInLoop",
"uri": "example/setup_test.go::BenchmarkLargeSetupInLoop",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
"max_time_ns": null,
"max_rounds": null
},
"stats": "[stats]"
}
]
},
{
"creator": {
"name": "codspeed-go",
"version": "[version]",
"pid": "[pid]"
},
"instrument": {
"type": "walltime"
},
"benchmarks": [
{
"name": "BenchmarkQuicktest",
"uri": "example/compat/quicktest_test.go::BenchmarkQuicktest",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -92,8 +115,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep100us",
"uri": "example/sleep_test.go::BenchmarkSleep100us",
"name": "BenchmarkTestifyWithNew",
"uri": "example/compat/testify_test.go::BenchmarkTestifyWithNew",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -103,8 +126,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep100us_Loop",
"uri": "example/sleep_test.go::BenchmarkSleep100us_Loop",
"name": "BenchmarkTestifyWithT",
"uri": "example/compat/testify_test.go::BenchmarkTestifyWithT",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -114,8 +137,31 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep10ms",
"uri": "example/sleep_test.go::BenchmarkSleep10ms",
"name": "BenchmarkWithSlogAssert",
"uri": "example/compat/slogassert_test.go::BenchmarkWithSlogAssert",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
"max_time_ns": null,
"max_rounds": null
},
"stats": "[stats]"
}
]
},
{
"creator": {
"name": "codspeed-go",
"version": "[version]",
"pid": "[pid]"
},
"instrument": {
"type": "walltime"
},
"benchmarks": [
{
"name": "BenchmarkSleep100ns",
"uri": "example/timing/sleep_test.go::BenchmarkSleep100ns",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -125,8 +171,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep10ms_Loop",
"uri": "example/sleep_test.go::BenchmarkSleep10ms_Loop",
"name": "BenchmarkSleep100ns_Loop",
"uri": "example/timing/sleep_test.go::BenchmarkSleep100ns_Loop",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -136,8 +182,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep10us",
"uri": "example/sleep_test.go::BenchmarkSleep10us",
"name": "BenchmarkSleep100us",
"uri": "example/timing/sleep_test.go::BenchmarkSleep100us",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -147,8 +193,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep10us_Loop",
"uri": "example/sleep_test.go::BenchmarkSleep10us_Loop",
"name": "BenchmarkSleep100us_Loop",
"uri": "example/timing/sleep_test.go::BenchmarkSleep100us_Loop",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -158,8 +204,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep1ms",
"uri": "example/sleep_test.go::BenchmarkSleep1ms",
"name": "BenchmarkSleep10ms",
"uri": "example/timing/sleep_test.go::BenchmarkSleep10ms",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -169,8 +215,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep1ms_Loop",
"uri": "example/sleep_test.go::BenchmarkSleep1ms_Loop",
"name": "BenchmarkSleep10ms_Loop",
"uri": "example/timing/sleep_test.go::BenchmarkSleep10ms_Loop",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -180,8 +226,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep1us",
"uri": "example/sleep_test.go::BenchmarkSleep1us",
"name": "BenchmarkSleep10us",
"uri": "example/timing/sleep_test.go::BenchmarkSleep10us",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -191,8 +237,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep1us_Loop",
"uri": "example/sleep_test.go::BenchmarkSleep1us_Loop",
"name": "BenchmarkSleep10us_Loop",
"uri": "example/timing/sleep_test.go::BenchmarkSleep10us_Loop",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -202,8 +248,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep50ms",
"uri": "example/sleep_test.go::BenchmarkSleep50ms",
"name": "BenchmarkSleep1ms",
"uri": "example/timing/sleep_test.go::BenchmarkSleep1ms",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -213,31 +259,19 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkSleep50ms_Loop",
"uri": "example/sleep_test.go::BenchmarkSleep50ms_Loop",
"name": "BenchmarkSleep1ms_Loop",
"uri": "example/timing/sleep_test.go::BenchmarkSleep1ms_Loop",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
"max_time_ns": null,
"max_rounds": null
},
"stats": "[stats]"
}
]
},
{
"creator": {
"name": "codspeed-go",
"version": "[version]",
"pid": "[pid]"
},
"instrument": {
"type": "walltime"
},
"benchmarks": [
},
{
"name": "BenchmarkQuicktest",
"uri": "example/compat/quicktest_test.go::BenchmarkQuicktest",
"name": "BenchmarkSleep1us",
"uri": "example/timing/sleep_test.go::BenchmarkSleep1us",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -247,8 +281,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkTestifyWithNew",
"uri": "example/compat/testify_test.go::BenchmarkTestifyWithNew",
"name": "BenchmarkSleep1us_Loop",
"uri": "example/timing/sleep_test.go::BenchmarkSleep1us_Loop",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -258,8 +292,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkTestifyWithT",
"uri": "example/compat/testify_test.go::BenchmarkTestifyWithT",
"name": "BenchmarkSleep50ms",
"uri": "example/timing/sleep_test.go::BenchmarkSleep50ms",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand All @@ -269,8 +303,8 @@ expression: results
"stats": "[stats]"
},
{
"name": "BenchmarkWithSlogAssert",
"uri": "example/compat/slogassert_test.go::BenchmarkWithSlogAssert",
"name": "BenchmarkSleep50ms_Loop",
"uri": "example/timing/sleep_test.go::BenchmarkSleep50ms_Loop",
"config": {
"warmup_time_ns": null,
"min_round_time_ns": null,
Expand Down
21 changes: 21 additions & 0 deletions testing/capi/instrument-hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ typedef struct instruments_root_InstrumentHooks__547 InstrumentHooks;
*/
import "C"
import (
"os"
"runtime"
"unsafe"
)

const (
MarkerTypeSampleStart = 0
MarkerTypeSampleEnd = 1
MarkerTypeBenchmarkStart = 2
MarkerTypeBenchmarkEnd = 3
)
Comment on lines +15 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same feedback as in the Python PR, if there is a way to avoid duplicating this, it would be great


// This will be set in the go-runner
var integrationVersion = "dev"

Expand Down Expand Up @@ -79,3 +87,16 @@ func (i *InstrumentHooks) IsInstrumented() bool {
}
return bool(C.instrument_hooks_is_instrumented(i.hooks))
}

func CurrentTimestamp() uint64 {
return uint64(C.instrument_hooks_current_timestamp())
}

func (i *InstrumentHooks) AddBenchmarkTimestamps(startTimestamp, endTimestamp uint64) {
if i.hooks == nil {
return
}
pid := uint32(os.Getpid())
C.instrument_hooks_add_marker(i.hooks, C.uint32_t(pid), C.uint8_t(MarkerTypeBenchmarkStart), C.uint64_t(startTimestamp))
C.instrument_hooks_add_marker(i.hooks, C.uint32_t(pid), C.uint8_t(MarkerTypeBenchmarkEnd), C.uint64_t(endTimestamp))
}
Loading
Loading