mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-10-21 19:44:13 +00:00
Add goroutine dump and hang trigger to libbox
This commit is contained in:
parent
351ce12f73
commit
7a3d4e4a8e
1 changed files with 16 additions and 0 deletions
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue