Skip to content

Commit

Permalink
fix(godeltaprof): handle renamed runtime.pprof_cyclesPerSecond (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev authored May 22, 2024
1 parent ffd2615 commit 491e627
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 64 deletions.
5 changes: 3 additions & 2 deletions godeltaprof/compat/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions godeltaprof/compat/stub_go20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
26 changes: 0 additions & 26 deletions godeltaprof/compat/stub_go21_test.go

This file was deleted.

44 changes: 44 additions & 0 deletions godeltaprof/compat/stub_go22_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
42 changes: 42 additions & 0 deletions godeltaprof/compat/stub_go23_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
24 changes: 0 additions & 24 deletions godeltaprof/compat/stub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions godeltaprof/internal/pprof/stub.go
Original file line number Diff line number Diff line change
@@ -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()
}
11 changes: 10 additions & 1 deletion godeltaprof/internal/pprof/stub_go20.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
27 changes: 27 additions & 0 deletions godeltaprof/internal/pprof/stub_go22.go
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build go1.21
// +build go1.21
//go:build go1.23
// +build go1.23

package pprof

Expand All @@ -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

0 comments on commit 491e627

Please sign in to comment.