mirror of https://github.com/milvus-io/milvus.git
parent
58b75d9738
commit
ee5a972ced
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue