Skip to content

Commit e14aad1

Browse files
mknyszekgopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent ddfab21 commit e14aad1

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)