github.com/puellanivis/breton@v0.2.16/lib/os/process/profile.go (about)

     1  package process
     2  
     3  import (
     4  	"os"
     5  	"runtime/pprof"
     6  )
     7  
     8  func setupProfiling() {
     9  	cpuf, err := os.Create(*profile + ".prof")
    10  	if err != nil {
    11  		panic(err)
    12  	}
    13  
    14  	memf, err := os.Create(*profile + ".mprof")
    15  	if err != nil {
    16  		panic(err)
    17  	}
    18  
    19  	_ = pprof.StartCPUProfile(cpuf)
    20  
    21  	AtExit(func() {
    22  		pprof.StopCPUProfile()
    23  		cpuf.Close()
    24  
    25  		_ = pprof.WriteHeapProfile(memf)
    26  		memf.Close()
    27  	})
    28  }