Standard library / runtime/pprof
pprof.Profile.WriteTo()
Write a snapshot to a writer. Debug zero produces gzip-compressed protobuf; one produces readable legacy text. Never expose raw profiles publicly. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (p *Profile) WriteTo(w io.Writer, debug int) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| w | io.Writer | Destination writer; keep it open until profiling or tracing has stopped. |
| debug | int | Output format: 0 is compressed protobuf; 1 is legacy text. Some profiles accept other values. |
Return Value
error
Error from profile output, or nil.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "runtime/pprof" "strings")
func main() { p := pprof.NewProfile("bytemind.resource") p.Add("demo", 0) defer p.Remove("demo") var b bytes.Buffer if err := p.WriteTo(&b, 1); err != nil { panic(err) } fmt.Println(strings.Contains(b.String(), "bytemind.resource profile: total 1"))}