Golang runtime/pprof.Lookup(), NewProfile() functions and WriteTo() method example

package runtime/pprof

Golang runtime/pprof.Lookup(), NewProfile() functions and WriteTo() method usage example

 package main

 import (
 "bytes"
 "fmt"
 "runtime/pprof"
 )

 func main() {

 newp := pprof.NewProfile("test")

 fmt.Println(newp)

 p := pprof.Lookup(newp.Name())

 var buf bytes.Buffer

 if p == nil {
 fmt.Println("Unknown profile")
 } else {
 p.WriteTo(&buf, 1)
 fmt.Println(p)
 fmt.Println(buf.String())
 }
 }

References :

http://golang.org/pkg/runtime/pprof/#Lookup

http://golang.org/pkg/runtime/pprof/#NewProfile

http://golang.org/pkg/runtime/pprof/#Profile.Name

http://golang.org/pkg/runtime/pprof/#Profile.WriteTo

Advertisement