Skip to content

cmd/trace: always opening browser, not printing profile #66782

@matthewhughes-uw

Description

@matthewhughes-uw

Go version

go version go1.22.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/my-user/.cache/go-build'
GOENV='/home/my-user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/my-user/.local/share/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/my-user/.local/share/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/tmp/proj/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1974410770=/tmp/go-build -gno-record-gcc-switches'

What did you do?

#!/usr/bin/env bash

set -o errexit -o pipefail -o nounset

# create a trivial module that supports 1.21.0+
go mod init m
go mod edit -go=1.21.0

cat <<'EOF' > lib.go
package lib

func Add(x int, y int) int {
	return x+y
}
EOF

cat <<'EOF' > lib_test.go
package lib

import (
	"testing"
)

func TestAdd(t *testing.T) {
	if Add(1,2) != 3 {
		t.Fatal("forgot how to add")
	}
}
EOF

# generate a trace using go1.21.0 ...
go1.21.0 test -trace=1_21_trace.out ./...

# and go1.21.0
go1.22.0 test -trace=1_22_trace.out ./...

What did you see happen?

When running go tool trace with the trace generated by go1.21.0 with -pprof a profile is printed to stdout:

$ go1.21.0 tool trace -pprof=net 1_21_trace.out | wc -c
93
$ go1.22.0 tool trace -pprof=net 1_21_trace.out | wc -c
90

This is expected

doing the same with the profile from go1.22.0 opens the browser:

$ go1.22.0 tool trace -pprof=net 1_22_trace.out | wc -c
2024/04/11 14:49:17 Preparing trace for viewer...
2024/04/11 14:49:17 Splitting trace for viewer...
2024/04/11 14:49:17 Opening browser. Trace viewer is listening on http://127.0.0.1:40941

This is unexpected

What did you expect to see?

Per the docs:

$ go1.22.0 tool trace -h
Usage of 'go tool trace':
Given a trace file produced by 'go test':
	go test -trace=trace.out pkg

Open a web browser displaying trace:
	go tool trace [flags] [pkg.test] trace.out

Generate a pprof-like profile from the trace:
    go tool trace -pprof=TYPE [pkg.test] trace.out

When I pass the -pprof flag I expect a profile to be generated

Metadata

Metadata

Assignees

Labels

NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions