Skip to content

Commit b96d520

Browse files
committed
runtime, runtime/pprof: add Func.Entry and goroutine-label stubs
Two source-compatibility fills, surfaced compiling larger Go programs under TinyGo: - runtime.Func.Entry: stubbed like the rest of runtime.Func; testify's mock package calls FileLine(f.Entry()). - runtime/pprof goroutine-label API (Labels, Label, ForLabels, WithLabels, SetGoroutineLabels, Do): inert stubs alongside the existing pprof stubs; google.golang.org/grpc references them. Do still calls f, labels are simply not attached.
1 parent bdc4a21 commit b96d520

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/runtime/pprof/label.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package pprof
2+
3+
// TinyGo does not implement pprof goroutine labels, but callers such as
4+
// google.golang.org/grpc reference the label API. Provide inert stubs so they
5+
// compile: labels are simply not attached.
6+
7+
import "context"
8+
9+
// LabelSet is a set of profiling labels (unused under TinyGo).
10+
type LabelSet struct{}
11+
12+
// Labels returns a LabelSet from key/value pairs. Inert under TinyGo.
13+
func Labels(args ...string) LabelSet { return LabelSet{} }
14+
15+
// Label returns the value of the named label; always ("", false) under TinyGo.
16+
func Label(ctx context.Context, key string) (string, bool) { return "", false }
17+
18+
// ForLabels iterates the labels on ctx; a no-op under TinyGo.
19+
func ForLabels(ctx context.Context, f func(key, value string) bool) {}
20+
21+
// WithLabels returns ctx unchanged under TinyGo (labels are not stored).
22+
func WithLabels(ctx context.Context, labels LabelSet) context.Context { return ctx }
23+
24+
// SetGoroutineLabels is a no-op under TinyGo.
25+
func SetGoroutineLabels(ctx context.Context) {}
26+
27+
// Do calls f with ctx; labels are ignored under TinyGo.
28+
func Do(ctx context.Context, labels LabelSet, f func(context.Context)) { f(ctx) }

src/runtime/stack.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ func (f *Func) FileLine(pc uintptr) (file string, line int) {
1515
return "", 0
1616
}
1717

18+
// Entry returns the entry address of the function. Stubbed like the rest of
19+
// runtime.Func on TinyGo; provided so callers that reference it (e.g.
20+
// github.com/stretchr/testify/mock via FileLine(f.Entry())) compile.
21+
func (f *Func) Entry() uintptr {
22+
return 0
23+
}
24+
1825
func Caller(skip int) (pc uintptr, file string, line int, ok bool) {
1926
return 0, "", 0, false
2027
}

0 commit comments

Comments
 (0)