Standard library / runtime/pprof
pprof.StopCPUProfile()
Stop CPU profiling and wait for pending writes. The example verifies a compressed profile, not sample counts. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func StopCPUProfile()Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "runtime" "runtime/pprof" "time")
func main() { var b bytes.Buffer if err := pprof.StartCPUProfile(&b); err != nil { panic(err) } end := time.Now().Add(120 * time.Millisecond) var n uint64 = 1 for time.Now().Before(end) { for i := 0; i < 1000; i++ { n = n*1664525 + 1013904223 } } runtime.KeepAlive(n) pprof.StopCPUProfile() fmt.Println(b.Len() > 2 && b.Bytes()[0] == 0x1f && b.Bytes()[1] == 0x8b)}