Skip to content

Commit

Permalink
Cleanup function name labeler
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-at-luther committed Feb 8, 2024
1 parent e77df1e commit 640659f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lisp/x/profiler/callgrind.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ func (p *callgrindProfiler) Start(fun *lisp.LVal) func() {
if p.skipTrace(fun) {
return func() {}
}
prettyLabel, _ := p.prettyFunName(fun)
// Mark the time and point of entry. It feels like we're building the call stack in Runtime
// again, but we're not - it's called, not callers.
p.incrementCallRef(p.prettyFunName(fun), fun.Source)
p.incrementCallRef(prettyLabel, fun.Source)

return func() {
p.end(fun)
Expand Down Expand Up @@ -178,7 +179,7 @@ func (p *callgrindProfiler) end(fun *lisp.LVal) {
}
p.Lock()
defer p.Unlock()
fName := p.prettyFunName(fun)
fName, _ := p.prettyFunName(fun)
source, line := getSource(fun)
// Write what function we've been observing and where to find it
fmt.Fprintf(p.writer, "fl=%s\n", p.getRef(source))
Expand Down
3 changes: 2 additions & 1 deletion lisp/x/profiler/go_annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func (p *pprofAnnotator) Start(fun *lisp.LVal) func() {
// if we always ran inside a context, or a whole conditional code path and the added complication that brings
// if we did it that way.
oldContext := p.currentContext
p.currentContext = pprof.WithLabels(p.currentContext, pprof.Labels("function", p.prettyFunName(fun)))
prettyLabel, _ := p.prettyFunName(fun)
p.currentContext = pprof.WithLabels(p.currentContext, pprof.Labels("function", prettyLabel))
// apply the selected labels to the current goroutine (NB this will propagate if the code branches further down...
pprof.SetGoroutineLabels(p.currentContext)

Expand Down
3 changes: 2 additions & 1 deletion lisp/x/profiler/opencensus_annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func (p *ocAnnotator) Start(fun *lisp.LVal) func() {
return func() {}
}
oldContext := p.currentContext
p.currentContext, p.currentSpan = trace.StartSpan(p.currentContext, p.prettyFunName(fun))
prettyLabel, _ := p.prettyFunName(fun)
p.currentContext, p.currentSpan = trace.StartSpan(p.currentContext, prettyLabel)
return func() {
file, line := getSource(fun)
p.currentSpan.Annotate([]trace.Attribute{
Expand Down
3 changes: 2 additions & 1 deletion lisp/x/profiler/opentelemetry_annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func (p *otelAnnotator) Start(fun *lisp.LVal) func() {
return func() {}
}
oldContext := p.currentContext
p.currentContext, p.currentSpan = contextTracer(p.currentContext).Start(p.currentContext, p.prettyFunName(fun))
prettyLabel, _ := p.prettyFunName(fun)
p.currentContext, p.currentSpan = contextTracer(p.currentContext).Start(p.currentContext, prettyLabel)
return func() {
file, line := getSource(fun)
p.currentSpan.AddEvent("source", trace.WithAttributes(attribute.Key("file").String(file), attribute.Key("line").Int64(int64(line))))
Expand Down
14 changes: 7 additions & 7 deletions lisp/x/profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func (p *profiler) Start(fun *lisp.LVal) func() {
return func() {}
}

func (p *profiler) prettyFunName(fun *lisp.LVal) string {
label := ""
// prettyFunName returns a pretty name and original name for a fun. If there is
// no pretty name, then the pretty name is the original name.
func (p *profiler) prettyFunName(fun *lisp.LVal) (string, string) {
origLabel := defaultFunName(p.runtime, fun)
prettyLabel := origLabel
if p.funLabeler != nil {
label = p.funLabeler(p.runtime, fun)
prettyLabel = p.funLabeler(p.runtime, fun)
}
if label == "" {
label = defaultFunName(p.runtime, fun)
}
return label
return prettyLabel, origLabel
}

// skipTrace is a helper function to decide whether to skip tracing.
Expand Down

0 comments on commit 640659f

Please sign in to comment.