MCPcopy
hub / github.com/gogf/gf / StackWithFilters

Function StackWithFilters

debug/gdebug/gdebug_stack.go:41–77  ·  view source on GitHub ↗

StackWithFilters returns a formatted stack trace of the goroutine that calls it. It calls runtime.Stack with a large enough buffer to capture the entire trace. The parameter `filters` is a slice of strings, which are used to filter the path of the caller. TODO Improve the performance using debug.S

(filters []string, skip ...int)

Source from the content-addressed store, hash-verified

39//
40// TODO Improve the performance using debug.Stack.
41func StackWithFilters(filters []string, skip ...int) string {
42 number := 0
43 if len(skip) > 0 {
44 number = skip[0]
45 }
46 var (
47 name string
48 space = " "
49 index = 1
50 buffer = bytes.NewBuffer(nil)
51 ok = true
52 pc, file, line, start = callerFromIndex(filters)
53 )
54 for i := start + number; i < maxCallerDepth; i++ {
55 if i != start {
56 pc, file, line, ok = runtime.Caller(i)
57 }
58 if ok {
59 if filterFileByFilters(file, filters) {
60 continue
61 }
62 if fn := runtime.FuncForPC(pc); fn == nil {
63 name = "unknown"
64 } else {
65 name = fn.Name()
66 }
67 if index > 9 {
68 space = " "
69 }
70 fmt.Fprintf(buffer, "%d.%s%s\n %s:%d\n", index, space, name, file, line)
71 index++
72 } else {
73 break
74 }
75 }
76 return buffer.String()
77}

Callers 2

GetStackMethod · 0.92
StackWithFilterFunction · 0.85

Calls 4

callerFromIndexFunction · 0.85
filterFileByFiltersFunction · 0.85
NameMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…