提交
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package runtimex_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.yun.ink/pkg/runtimex"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetgId(t *testing.T) {
|
||||||
|
t.Log("测试获取goroutine_id")
|
||||||
|
t.Log("goroutine_id:", runtimex.GetGid())
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user