Skip to content

Commit 2c88c1d

Browse files
mknyszekgopherbot
authored andcommitted
[release-branch.go1.22] 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. 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]>
1 parent 4c50f91 commit 2c88c1d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/cmd/trace/v2/main.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,35 @@ func Main(traceFile, httpAddr, pprof string, debug int) error {
2828
}
2929
defer tracef.Close()
3030

31+
// Handle requests for profiles.
32+
if pprof != "" {
33+
parsed, err := parseTrace(tracef)
34+
if err != nil {
35+
return err
36+
}
37+
var f traceviewer.ProfileFunc
38+
switch pprof {
39+
case "net":
40+
f = pprofByGoroutine(computePprofIO(), parsed)
41+
case "sync":
42+
f = pprofByGoroutine(computePprofBlock(), parsed)
43+
case "syscall":
44+
f = pprofByGoroutine(computePprofSyscall(), parsed)
45+
case "sched":
46+
f = pprofByGoroutine(computePprofSched(), parsed)
47+
default:
48+
return fmt.Errorf("unknown pprof type %s\n", pprof)
49+
}
50+
records, err := f(&http.Request{})
51+
if err != nil {
52+
return fmt.Errorf("failed to generate pprof: %v\n", err)
53+
}
54+
if err := traceviewer.BuildProfile(records).Write(os.Stdout); err != nil {
55+
return fmt.Errorf("failed to generate pprof: %v\n", err)
56+
}
57+
return nil
58+
}
59+
3160
// Debug flags.
3261
switch debug {
3362
case 1:

0 commit comments

Comments
 (0)