diff --git a/godeltaprof/compat/scale_test.go b/godeltaprof/compat/scale_test.go index 150ef5d..ffc8c15 100644 --- a/godeltaprof/compat/scale_test.go +++ b/godeltaprof/compat/scale_test.go @@ -32,6 +32,7 @@ func TestScaleMutex(t *testing.T) { const workers = 2 const expectedCount = workers * iters const expectedTime = expectedCount * 1000000 + const e = 0.4 runtime.SetMutexProfileFraction(fraction) @@ -63,8 +64,8 @@ func TestScaleMutex(t *testing.T) { fmt.Println(my.value[0], my.value[1]) fmt.Println(expectedCount, expectedTime) - assert.Less(t, math.Abs(float64(my.value[0])-float64(expectedCount)), 0.4*float64(expectedCount)) - assert.Less(t, math.Abs(float64(my.value[1])-float64(expectedTime)), 0.4*float64(expectedTime)) + assert.Less(t, math.Abs(float64(my.value[0])-float64(expectedCount)), e*float64(expectedCount)) + assert.Less(t, math.Abs(float64(my.value[1])-float64(expectedTime)), e*float64(expectedTime)) } func TestScaleBlock(t *testing.T) { diff --git a/godeltaprof/compat/stub_go20_test.go b/godeltaprof/compat/stub_go20_test.go index 86efa9f..2bd5c34 100644 --- a/godeltaprof/compat/stub_go20_test.go +++ b/godeltaprof/compat/stub_go20_test.go @@ -16,3 +16,21 @@ func TestRuntimeFrameStartLine(t *testing.T) { "runtime_FrameStartLine", "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_FrameStartLine(f *runtime.Frame) int") } + +func TestRuntimeExpandFinalInlineFrame(t *testing.T) { + checkSignature(t, "runtime/pprof", + "runtime_expandFinalInlineFrame", + "func runtime/pprof.runtime_expandFinalInlineFrame(stk []uintptr) []uintptr") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_expandFinalInlineFrame", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_expandFinalInlineFrame(stk []uintptr) []uintptr") +} + +func TestRuntimeCyclesPerSecond(t *testing.T) { + checkSignature(t, "runtime/pprof", + "runtime_cyclesPerSecond", + "func runtime/pprof.runtime_cyclesPerSecond() int64") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_cyclesPerSecond", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_cyclesPerSecond() int64") +} diff --git a/godeltaprof/compat/stub_go21_test.go b/godeltaprof/compat/stub_go21_test.go deleted file mode 100644 index fc5e586..0000000 --- a/godeltaprof/compat/stub_go21_test.go +++ /dev/null @@ -1,26 +0,0 @@ -//go:build go1.21 -// +build go1.21 - -package compat - -import ( - "testing" -) - -func TestRuntimeFrameSymbolName(t *testing.T) { - checkSignature(t, "runtime/pprof", - "runtime_FrameSymbolName", - "func runtime/pprof.runtime_FrameSymbolName(f *runtime.Frame) string") - checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", - "runtime_FrameSymbolName", - "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_FrameSymbolName(f *runtime.Frame) string") -} - -func TestRuntimeFrameStartLine(t *testing.T) { - checkSignature(t, "runtime/pprof", - "runtime_FrameStartLine", - "func runtime/pprof.runtime_FrameStartLine(f *runtime.Frame) int") - checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", - "runtime_FrameStartLine", - "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_FrameStartLine(f *runtime.Frame) int") -} diff --git a/godeltaprof/compat/stub_go22_test.go b/godeltaprof/compat/stub_go22_test.go new file mode 100644 index 0000000..ac19b18 --- /dev/null +++ b/godeltaprof/compat/stub_go22_test.go @@ -0,0 +1,44 @@ +//go:build go1.21 && !go1.23 +// +build go1.21,!go1.23 + +package compat + +import ( + "testing" +) + +func TestRuntimeFrameSymbolName(t *testing.T) { + checkSignature(t, "runtime/pprof", + "runtime_FrameSymbolName", + "func runtime/pprof.runtime_FrameSymbolName(f *runtime.Frame) string") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_FrameSymbolName", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_FrameSymbolName(f *runtime.Frame) string") +} + +func TestRuntimeFrameStartLine(t *testing.T) { + checkSignature(t, "runtime/pprof", + "runtime_FrameStartLine", + "func runtime/pprof.runtime_FrameStartLine(f *runtime.Frame) int") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_FrameStartLine", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_FrameStartLine(f *runtime.Frame) int") +} + +func TestRuntimeExpandFinalInlineFrame(t *testing.T) { + checkSignature(t, "runtime/pprof", + "runtime_expandFinalInlineFrame", + "func runtime/pprof.runtime_expandFinalInlineFrame(stk []uintptr) []uintptr") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_expandFinalInlineFrame", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_expandFinalInlineFrame(stk []uintptr) []uintptr") +} + +func TestRuntimeCyclesPerSecond(t *testing.T) { + checkSignature(t, "runtime/pprof", + "runtime_cyclesPerSecond", + "func runtime/pprof.runtime_cyclesPerSecond() int64") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_cyclesPerSecond", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_cyclesPerSecond() int64") +} diff --git a/godeltaprof/compat/stub_go23_test.go b/godeltaprof/compat/stub_go23_test.go new file mode 100644 index 0000000..bf495a9 --- /dev/null +++ b/godeltaprof/compat/stub_go23_test.go @@ -0,0 +1,42 @@ +//go:build go1.23 +// +build go1.23 + +package compat + +import "testing" + +func TestRuntimeFrameSymbolName(t *testing.T) { + checkSignature(t, "runtime/pprof", + "runtime_FrameSymbolName", + "func runtime/pprof.runtime_FrameSymbolName(f *runtime.Frame) string") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_FrameSymbolName", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_FrameSymbolName(f *runtime.Frame) string") +} + +func TestRuntimeFrameStartLine(t *testing.T) { + checkSignature(t, "runtime/pprof", + "runtime_FrameStartLine", + "func runtime/pprof.runtime_FrameStartLine(f *runtime.Frame) int") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_FrameStartLine", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_FrameStartLine(f *runtime.Frame) int") +} + +func TestRuntimeExpandFinalInlineFrame(t *testing.T) { + checkSignature(t, "runtime/pprof", + "runtime_expandFinalInlineFrame", + "func runtime/pprof.runtime_expandFinalInlineFrame(stk []uintptr) []uintptr") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_expandFinalInlineFrame", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_expandFinalInlineFrame(stk []uintptr) []uintptr") +} + +func TestRuntimeCyclesPerSecond(t *testing.T) { + checkSignature(t, "runtime", + "pprof_cyclesPerSecond", + "func runtime.pprof_cyclesPerSecond() int64") + checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", + "runtime_cyclesPerSecond", + "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_cyclesPerSecond() int64") +} diff --git a/godeltaprof/compat/stub_test.go b/godeltaprof/compat/stub_test.go index c9d97cf..3d94fe8 100644 --- a/godeltaprof/compat/stub_test.go +++ b/godeltaprof/compat/stub_test.go @@ -10,30 +10,6 @@ import ( "golang.org/x/tools/go/packages" ) -func TestSignatureExpandFinalInlineFrame(t *testing.T) { - checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", - "runtime_expandFinalInlineFrame", - "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_expandFinalInlineFrame(stk []uintptr) []uintptr") -} - -func TestSignatureCyclesPerSecond(t *testing.T) { - checkSignature(t, "github.com/grafana/pyroscope-go/godeltaprof/internal/pprof", - "runtime_cyclesPerSecond", - "func github.com/grafana/pyroscope-go/godeltaprof/internal/pprof.runtime_cyclesPerSecond() int64") -} - -func TestSignatureCyclesPerSecondRuntime(t *testing.T) { - checkSignature(t, "runtime/pprof", - "runtime_cyclesPerSecond", - "func runtime/pprof.runtime_cyclesPerSecond() int64") -} - -func TestSignatureExpandFinalInlineFrameRuntime(t *testing.T) { - checkSignature(t, "runtime/pprof", - "runtime_expandFinalInlineFrame", - "func runtime/pprof.runtime_expandFinalInlineFrame(stk []uintptr) []uintptr") -} - func checkSignature(t *testing.T, pkg string, name string, expectedSignature string) { cfg := &packages.Config{ Mode: packages.NeedImports | packages.NeedExportFile | packages.NeedTypes | packages.NeedSyntax, diff --git a/godeltaprof/internal/pprof/stub.go b/godeltaprof/internal/pprof/stub.go index 41dee8b..5b7d583 100644 --- a/godeltaprof/internal/pprof/stub.go +++ b/godeltaprof/internal/pprof/stub.go @@ -1,14 +1,5 @@ package pprof -// unsafe is required for go:linkname -import _ "unsafe" - -//go:linkname runtime_expandFinalInlineFrame runtime/pprof.runtime_expandFinalInlineFrame -func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr - -//go:linkname runtime_cyclesPerSecond runtime/pprof.runtime_cyclesPerSecond -func runtime_cyclesPerSecond() int64 - func Runtime_cyclesPerSecond() int64 { return runtime_cyclesPerSecond() } diff --git a/godeltaprof/internal/pprof/stub_go20.go b/godeltaprof/internal/pprof/stub_go20.go index d271cbc..7a32846 100644 --- a/godeltaprof/internal/pprof/stub_go20.go +++ b/godeltaprof/internal/pprof/stub_go20.go @@ -3,7 +3,10 @@ package pprof -import "runtime" +import ( + "runtime" + _ "unsafe" +) // runtime_FrameStartLine is defined in runtime/symtab.go. func runtime_FrameStartLine(f *runtime.Frame) int { @@ -14,3 +17,9 @@ func runtime_FrameStartLine(f *runtime.Frame) int { func runtime_FrameSymbolName(f *runtime.Frame) string { return f.Function } + +//go:linkname runtime_expandFinalInlineFrame runtime/pprof.runtime_expandFinalInlineFrame +func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr + +//go:linkname runtime_cyclesPerSecond runtime/pprof.runtime_cyclesPerSecond +func runtime_cyclesPerSecond() int64 diff --git a/godeltaprof/internal/pprof/stub_go22.go b/godeltaprof/internal/pprof/stub_go22.go new file mode 100644 index 0000000..02c726f --- /dev/null +++ b/godeltaprof/internal/pprof/stub_go22.go @@ -0,0 +1,27 @@ +//go:build go1.21 && !go1.23 +// +build go1.21,!go1.23 + +package pprof + +import ( + "runtime" + _ "unsafe" +) + +// runtime_FrameStartLine is defined in runtime/symtab.go. +// +//go:noescape +//go:linkname runtime_FrameStartLine runtime/pprof.runtime_FrameStartLine +func runtime_FrameStartLine(f *runtime.Frame) int + +// runtime_FrameSymbolName is defined in runtime/symtab.go. +// +//go:noescape +//go:linkname runtime_FrameSymbolName runtime/pprof.runtime_FrameSymbolName +func runtime_FrameSymbolName(f *runtime.Frame) string + +//go:linkname runtime_expandFinalInlineFrame runtime/pprof.runtime_expandFinalInlineFrame +func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr + +//go:linkname runtime_cyclesPerSecond runtime/pprof.runtime_cyclesPerSecond +func runtime_cyclesPerSecond() int64 diff --git a/godeltaprof/internal/pprof/stub_go21.go b/godeltaprof/internal/pprof/stub_go23.go similarity index 61% rename from godeltaprof/internal/pprof/stub_go21.go rename to godeltaprof/internal/pprof/stub_go23.go index 178ce25..37ccbe8 100644 --- a/godeltaprof/internal/pprof/stub_go21.go +++ b/godeltaprof/internal/pprof/stub_go23.go @@ -1,5 +1,5 @@ -//go:build go1.21 -// +build go1.21 +//go:build go1.23 +// +build go1.23 package pprof @@ -19,3 +19,9 @@ func runtime_FrameStartLine(f *runtime.Frame) int //go:noescape //go:linkname runtime_FrameSymbolName runtime/pprof.runtime_FrameSymbolName func runtime_FrameSymbolName(f *runtime.Frame) string + +//go:linkname runtime_expandFinalInlineFrame runtime/pprof.runtime_expandFinalInlineFrame +func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr + +//go:linkname runtime_cyclesPerSecond runtime.pprof_cyclesPerSecond +func runtime_cyclesPerSecond() int64