diff --git a/example-pprof-simple/Makefile b/example-pprof-simple/Makefile index fa67bcf..b0c8dbc 100644 --- a/example-pprof-simple/Makefile +++ b/example-pprof-simple/Makefile @@ -1,9 +1,6 @@ run: GO111MODULE="off" go run -v -x main.go - -prep: - GO111MODULE="off" go get -v . - -build: - GO111MODULE="off" go build -v -x - # go build + @echo + @echo "Run foo.go:" + @echo + GO111MODULE="off" go run foo.go diff --git a/example-pprof-simple/foo.go b/example-pprof-simple/foo.go new file mode 100644 index 0000000..4fd371e --- /dev/null +++ b/example-pprof-simple/foo.go @@ -0,0 +1,38 @@ +package main + +import ( + "runtime/pprof" + "context" + "fmt" + "time" +) + +func main() { + type favContextKey string + + f := func(ctx context.Context, k string) { + ctx2 := context.WithValue(context.Background(), "language", "Go2") + if v := ctx2.Value(k); v != nil { + fmt.Println("found value:", v) + } else { + fmt.Println("key not found:", k) + } + pprof.SetGoroutineLabels(ctx) + + if v := ctx.Value(k); v != nil { + fmt.Println("found value:", v) + } else { + fmt.Println("key not found:", k) + } + } + + ctx := context.WithValue(context.Background(), "language", "Go") + + f(ctx, "language") + f(ctx, "color") + + go f(ctx, "language") + go f(ctx, "color") + + time.Sleep(time.Duration(1) * time.Second) +}