cmd/trace/v2: handle the -pprof flag

Turns out we ported all the profile generation, but forgot to actually
support the command line flags for them! This change fixes the issue by
handling the different kinds of profiles and writing them out to stdout.

Fixes #66782.

Change-Id: I7756fb4636ce8daaf11ed471be79c86ce3d463cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/578318
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Anthony Knyszek 2024-04-11 20:30:24 +00:00 committed by Gopher Robot
parent ddfab21e46
commit e14aad1faf
1 changed files with 29 additions and 0 deletions

View File

@ -28,6 +28,35 @@ func Main(traceFile, httpAddr, pprof string, debug int) error {
}
defer tracef.Close()
// Handle requests for profiles.
if pprof != "" {
parsed, err := parseTrace(tracef)
if err != nil {
return err
}
var f traceviewer.ProfileFunc
switch pprof {
case "net":
f = pprofByGoroutine(computePprofIO(), parsed)
case "sync":
f = pprofByGoroutine(computePprofBlock(), parsed)
case "syscall":
f = pprofByGoroutine(computePprofSyscall(), parsed)
case "sched":
f = pprofByGoroutine(computePprofSched(), parsed)
default:
return fmt.Errorf("unknown pprof type %s\n", pprof)
}
records, err := f(&http.Request{})
if err != nil {
return fmt.Errorf("failed to generate pprof: %v\n", err)
}
if err := traceviewer.BuildProfile(records).Write(os.Stdout); err != nil {
return fmt.Errorf("failed to generate pprof: %v\n", err)
}
return nil
}
// Debug flags.
switch debug {
case 1: