gitee.com/gricks/utils@v1.0.8/profile.go (about) 1 package utils 2 3 import ( 4 "io" 5 "os" 6 "runtime" 7 8 _ "unsafe" 9 ) 10 11 //go:linkname writeGoroutine runtime/pprof.writeGoroutine 12 func writeGoroutine(w io.Writer, debug int) error 13 14 func WriteGoroutine(filename string, debug int) { 15 f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) 16 if err != nil { 17 return 18 } 19 defer f.Close() 20 writeGoroutine(f, debug) 21 } 22 23 //go:linkname writeHeap runtime/pprof.writeHeap 24 func writeHeap(w io.Writer, debug int) error 25 26 func WriteHeap(filename string, debug int) { 27 f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) 28 if err != nil { 29 return 30 } 31 defer f.Close() 32 runtime.GC() 33 writeHeap(f, debug) 34 }