Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(godeltaprof): handle renamed runtime.pprof_cyclesPerSecond #107

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 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) {

Choose a reason for hiding this comment

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

I think you forgot to remove this test:

func TestSignatureCyclesPerSecondRuntime(t *testing.T) {
checkSignature(t, "runtime/pprof",
"runtime_cyclesPerSecond",
"func runtime/pprof.runtime_cyclesPerSecond() int64")
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I think all of the tests in stub_tests.go are duplicated by the version-specific tests. So I removed all tests from stub_test.go.

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")
}
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
Loading