1
0
mirror of https://github.com/DataDog/go-profiler-notes.git synced 2025-07-12 23:50:13 +02:00
Files
go-profiler-notes/guide/cpu-profiler-labels.go

39 lines
528 B
Go
Raw Permalink Normal View History

2021-09-09 23:46:41 +02:00
// +build ignore
package main
import (
"context"
"os"
"runtime/pprof"
"time"
)
func main() {
pprof.StartCPUProfile(os.Stdout)
defer pprof.StopCPUProfile()
go work(context.Background(), "alice")
go work(context.Background(), "bob")
time.Sleep(50 * time.Millisecond)
}
func work(ctx context.Context, user string) {
labels := pprof.Labels("user", user)
pprof.Do(ctx, labels, func(_ context.Context) {
go backgroundWork()
directWork()
})
}
func directWork() {
for {
}
}
func backgroundWork() {
for {
}
}