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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Michael Knyszek <mknyszek@google.com>
Thanks for the quick fix! |
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: