Files
utils/runtimex/runtimex.go
T

24 lines
371 B
Go
Raw Normal View History

2023-09-16 20:14:20 +08:00
package runtimex
import (
"bytes"
"runtime"
"strconv"
)
// 2023年6月30日19:26:09
// 获取goroutine_id
func GetGid() (gid uint64) {
b := make([]byte, 64)
b = b[:runtime.Stack(b, false)]
b = bytes.TrimPrefix(b, []byte("goroutine "))
b = b[:bytes.IndexByte(b, ' ')]
n, err := strconv.ParseUint(string(b), 10, 64)
if err != nil {
panic(err)
}
return n
}