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
| Name | Type | Description |
|---|---|---|
| value | any | Comparable key identifying a tracked resource or stack. |
| skip | int | Number 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())}