golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.79k stars 728 forks source link

UI: Include Pprof label in Goroutine name/header in the _call stack_ section of the debugger #3247

Open gm0stache opened 3 months ago

gm0stache commented 3 months ago

Is your feature request related to a problem? Please describe. Pprof labels are not (directly) visible in the call stack section of the debugger.

Describe the solution you'd like I would like the Pprof labels to be visible in the call stack section of the debugger.

Consider the following program:

package main

import (
    "context"
    "fmt"
    "runtime/pprof"
    "strconv"
    "sync"
    "time"
)

func worker(name string) {
    time.Sleep(1 * time.Second)
    fmt.Println("worker finished:", name)
}

func main() {
    wg := sync.WaitGroup{}
    for i := 0; i < 20; i++ {
        wg.Add(1)
        labels := pprof.Labels("worker", strconv.Itoa(i))
        pprof.Do(context.TODO(), labels, func(ctx context.Context) {
            go worker(strconv.Itoa(i))
        })
    }
    wg.Wait()
}

lauch profile:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch file",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${file}",
            "hideSystemGoroutines": true,
            "showPprofLabels": [
                "*"
            ]
        }
    ]
}

When setting a breakpoint for last line im the main function, and debugging the program, I would like to see the goroutines listed in the call stack section with the configured pprof labels clearly visible. It would make debugging goroutines more straight forward.

Additional context

Thanks for all your work and time! Happy to answer any upcoming questions!

BR Gabriel