-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/trace: always opening browser, not printing profile #66782
Comments
I see for v2 tracing EDIT: quick hack copying the v1 code that got it working (i.e. printing profiles, I make no guarantees that they are the expected profiles 🙃): diff --git a/src/cmd/trace/v2/main.go b/src/cmd/trace/v2/main.go
index 0a60ef04db..21b247a3f8 100644
--- a/src/cmd/trace/v2/main.go
+++ b/src/cmd/trace/v2/main.go
@@ -27,6 +27,35 @@ func Main(traceFile, httpAddr, pprof string, debug int) error {
return fmt.Errorf("failed to read trace file: %w", err)
}
defer tracef.Close()
+ parsed, err := parseTrace(tracef)
+ if err != nil {
+ return err
+ }
+
+ var pprofFunc traceviewer.ProfileFunc
+ switch pprof {
+ case "net":
+ pprofFunc = pprofByGoroutine(computePprofIO(), parsed)
+ case "sync":
+ pprofFunc = pprofByGoroutine(computePprofBlock(), parsed)
+ case "syscall":
+ pprofFunc = pprofByGoroutine(computePprofSyscall(), parsed)
+ case "sched":
+ pprofFunc = pprofByGoroutine(computePprofSched(), parsed)
+ }
+ if pprofFunc != nil {
+ records, err := pprofFunc(&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)
+ }
+ os.Exit(0)
+ }
+ if pprof != "" {
+ return fmt.Errorf("unknown pprof type %s\n", pprof)
+ }
// Debug flags.
switch debug {
@@ -43,10 +72,6 @@ func Main(traceFile, httpAddr, pprof string, debug int) error {
addr := "http://" + ln.Addr().String()
log.Print("Preparing trace for viewer...")
- parsed, err := parseTrace(tracef)
- if err != nil {
- return err
- }
// N.B. tracef not needed after this point.
// We might double-close, but that's fine; we ignore the error.
tracef.Close() |
@golang/runtime |
Oops! This is an embarrassing oversight. Yeah, all the underlying code was ported, but the command-line flags got lost. |
Change https://go.dev/cl/578318 mentions this issue: |
Change https://go.dev/cl/578356 mentions this issue: |
It gets worse -- turns out for a long time the |
In both the v1 and v2 cmd/trace, pprofMatchingGoroutines will generate no output at all if the filter name passed to it is the empty string. This is rather pointless because there are at least two places where we don't pass a name to filter. Modify pprofMatchingGoroutines to include *all* goroutines in the trace if the name to filter by is not specified. For #66782. Change-Id: I6b72298d676bc93892b075a7426e6e56bc6656c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/578356 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Auto-Submit: Michael Knyszek <[email protected]>
Thanks for the quick fix! |
Change https://go.dev/cl/600255 mentions this issue: |
Change https://go.dev/cl/600275 mentions this issue: |
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]>
In both the v1 and v2 cmd/trace, pprofMatchingGoroutines will generate no output at all if the filter name passed to it is the empty string. This is rather pointless because there are at least two places where we don't pass a name to filter. Modify pprofMatchingGoroutines to include *all* goroutines in the trace if the name to filter by is not specified. For #66782 Fixes #68542 Fixes #68546 Change-Id: I6b72298d676bc93892b075a7426e6e56bc6656c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/578356 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> (cherry picked from commit d1f2cd8) Reviewed-on: https://go-review.googlesource.com/c/go/+/600275 Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
Go version
go version go1.22.2 linux/amd64
Output of
go env
in your module/workspace:What did you do?
What did you see happen?
When running
go tool trace
with the trace generated bygo1.21.0
with-pprof
a profile is printed to stdout:This is expected
doing the same with the profile from
go1.22.0
opens the browser:This is unexpected
What did you expect to see?
Per the docs:
When I pass the
-pprof
flag I expect a profile to be generatedThe text was updated successfully, but these errors were encountered: