1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-06 02:23:24 +00:00

pacer: factor call stack searching into its own package

This commit is contained in:
Nick Craig-Wood
2025-11-10 13:32:44 +00:00
parent 4d19afdbbf
commit b5e4d39b05
4 changed files with 68 additions and 42 deletions

26
lib/caller/caller.go Normal file
View File

@@ -0,0 +1,26 @@
// Package caller contains functions to examine the call stack.
package caller
import (
"runtime"
"strings"
)
// Present looks for functionName in the call stack and return true if found
//
// Note that this ignores the caller.
func Present(functionName string) bool {
var pcs [48]uintptr
n := runtime.Callers(3, pcs[:]) // skip runtime.Callers, Present and caller
frames := runtime.CallersFrames(pcs[:n])
for {
f, more := frames.Next()
if strings.HasSuffix(f.Function, functionName) {
return true
}
if !more {
break
}
}
return false
}