Standard library / runtime/pprof

pprof.Profile.Add()

Associate a comparable key with the current stack. Add panics on duplicate keys and retains the key until Remove. Use only a custom profile. Expected stdout: '1\n'.

Formal Syntax & Structure

go syntaxgo
func (p *Profile) Add(value any, skip int)

Parameters & Attributes

NameTypeDescription
valueanyComparable key identifying a tracked resource or stack.
skipintNumber of caller frames to omit; zero starts at the caller of Add.

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime/pprof")
func main() {  p := pprof.NewProfile("bytemind.resource")  p.Add("demo", 0)  defer p.Remove("demo")  fmt.Println(p.Count())}
Go Reference