1
This commit is contained in:
parent
583a9d2358
commit
61a612b594
24
sysutils.go
24
sysutils.go
@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDaySeconds(seconds int64, timeZone int64) int64 {
|
func GetDaySeconds(seconds int64, timeZone int64) int64 {
|
||||||
@ -209,3 +210,26 @@ func AppendSlice[T any](s *[]T, val T) {
|
|||||||
func GetTypeName(v interface{}) string {
|
func GetTypeName(v interface{}) string {
|
||||||
return reflect.TypeOf(v).String()
|
return reflect.TypeOf(v).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PrintCallStack() {
|
||||||
|
// 获取当前函数的调用者信息
|
||||||
|
pc, file, line, ok := runtime.Caller(1)
|
||||||
|
if !ok {
|
||||||
|
fmt.Println("runtime.Caller error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
funcName := runtime.FuncForPC(pc).Name()
|
||||||
|
fmt.Printf("Function: %s\nFile: %s\nLine: %d\n", funcName, file, line)
|
||||||
|
|
||||||
|
// 使用Stack打印完整的调用栈信息,可以用于debug
|
||||||
|
buf := make([]byte, 1024)
|
||||||
|
for {
|
||||||
|
n := runtime.Stack(buf, false)
|
||||||
|
if n < len(buf) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
buf = make([]byte, 2*len(buf))
|
||||||
|
}
|
||||||
|
fmt.Println(string(buf))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user