Improve StackTraceMsg (#14461)

Signed-off-by: dragondriver <jiquan.long@zilliz.com>
pull/14467/head
Jiquan Long 2021-12-28 20:44:46 +08:00 committed by GitHub
parent 58b75d9738
commit ee5a972ced
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -16,13 +16,16 @@ import (
"runtime"
)
const numFuncsInStack = 10
const (
numFuncsInStack = 10
frameNumToSkip = 2
)
// StackTraceMsg returns the stack information, which numFuncs means how many functions do you want to show in the stack
// information.
func StackTraceMsg(numFuncs uint) string {
pc := make([]uintptr, numFuncs)
n := runtime.Callers(0, pc)
n := runtime.Callers(frameNumToSkip, pc)
frames := runtime.CallersFrames(pc[:n])
ret := ""

View File

@ -16,6 +16,14 @@ import (
"testing"
)
func testStackTrace() {
fmt.Println(StackTraceMsg(1))
fmt.Println(StackTraceMsg(5))
fmt.Println(StackTraceMsg(10))
fmt.Println(StackTrace())
}
func TestStackTraceMsg(t *testing.T) {
fmt.Println(StackTraceMsg(1))
fmt.Println(StackTraceMsg(5))
@ -30,6 +38,8 @@ func TestStackTraceMsg(t *testing.T) {
fmt.Println(StackTraceMsg(10))
}()
}()
testStackTrace()
}
func TestStackTrace(t *testing.T) {