github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/cmds/elvish/sys/dumpstack.go (about)

     1  package sys
     2  
     3  import "runtime"
     4  
     5  const dumpStackBufSizeInit = 4096
     6  
     7  func DumpStack() string {
     8  	buf := make([]byte, dumpStackBufSizeInit)
     9  	for {
    10  		n := runtime.Stack(buf, true)
    11  		if n < cap(buf) {
    12  			return string(buf[:n])
    13  		}
    14  		buf = make([]byte, cap(buf)*2)
    15  	}
    16  }