Skip to content

Commit

Permalink
[release-branch.go1.22] cmd/trace/v2: handle the -pprof flag
Browse files Browse the repository at this point in the history
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.

For #66782
For #68542
For #68546

Change-Id: I7756fb4636ce8daaf11ed471be79c86ce3d463cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/578318
Reviewed-by: Carlos Amedee <[email protected]>
Auto-Submit: Michael Knyszek <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
(cherry picked from commit e14aad1)
Reviewed-on: https://go-review.googlesource.com/c/go/+/600255
Reviewed-by: Michael Knyszek <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Auto-Submit: Dmitri Shuralyov <[email protected]>
  • Loading branch information
mknyszek authored and gopherbot committed Jul 24, 2024
1 parent 4c50f91 commit 2c88c1d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/cmd/trace/v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2c88c1d

Please sign in to comment.