未验证 提交 ee5a972c 编写于 作者: J Jiquan Long 提交者: GitHub

Improve StackTraceMsg (#14461)

Signed-off-by: Ndragondriver <jiquan.long@zilliz.com>
上级 58b75d97
......@@ -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 := ""
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册