Add goroutine dump and hang trigger to libbox

This commit is contained in:
世界
2026-10-02 18:00:09 +08:00
parent 351ce12f73
commit 7a3d4e4a8e
+16
View File
@@ -1,6 +1,7 @@
package libbox
import (
"runtime"
"time"
"unsafe"
)
@@ -10,3 +11,18 @@ func TriggerGoPanic() {
*(*int)(unsafe.Pointer(uintptr(0))) = 0
})
}
func TriggerGoHang(seconds int32) {
time.Sleep(time.Duration(seconds) * time.Second)
}
func GoroutineDump() string {
buffer := make([]byte, 64*1024)
for {
n := runtime.Stack(buffer, true)
if n < len(buffer) {
return string(buffer[:n])
}
buffer = make([]byte, 2*len(buffer))
}
}