Skip to content

Commit 081dc9f

Browse files
prattmicgopherbot
authored andcommitted
cmd/go: preprocess PGO profiles
Following the previous CL, now actually run the preprofile tool to create the preprocessed output. There is still no build cache integration, so the tool will run on every build even if nothing has changed. For #58102. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Change-Id: I0414377a956889f457e50898737fcaa8a698658d Reviewed-on: https://go-review.googlesource.com/c/go/+/569424 Auto-Submit: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
1 parent 4084bc1 commit 081dc9f

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/cmd/dist/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ func toolenv() []string {
13541354
return env
13551355
}
13561356

1357-
var toolchain = []string{"cmd/asm", "cmd/cgo", "cmd/compile", "cmd/link"}
1357+
var toolchain = []string{"cmd/asm", "cmd/cgo", "cmd/compile", "cmd/link", "cmd/preprofile"}
13581358

13591359
// The bootstrap command runs a build from scratch,
13601360
// stopping at having installed the go_bootstrap command.

src/cmd/go/internal/work/action.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,7 @@ func (p *pgoActor) Act(b *Builder, ctx context.Context, a *Action) error {
476476
return err
477477
}
478478

479-
// TODO(prattmic): This should use go tool preprofile to actually
480-
// preprocess the profile. For now, this is a dummy implementation that
481-
// simply copies the input to the output. This is technically a valid
482-
// implementation because go tool compile -pgofile accepts either a
483-
// pprof file or preprocessed file.
484-
if err := sh.CopyFile(a.Target, p.input, 0644, false); err != nil {
479+
if err := sh.run(".", p.input, nil, cfg.BuildToolexec, base.Tool("preprofile"), "-o", a.Target, "-i", p.input); err != nil {
485480
return err
486481
}
487482

src/cmd/go/testdata/script/build_pgo.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ go build triv.go
99
# build with PGO, should trigger rebuild
1010
# starting with an empty profile (the compiler accepts it)
1111
go build -x -pgo=prof -o triv.exe triv.go
12-
stderr 'cp.*prof' # preprocess PGO profile
12+
stderr 'preprofile.*-i.*prof'
1313
stderr 'compile.*-pgoprofile=.*triv.go'
1414

1515
# check that PGO appears in build info
@@ -36,7 +36,7 @@ go run overwrite.go
3636

3737
# build again, profile content changed, should trigger rebuild, including std
3838
go build -n -pgo=prof triv.go
39-
stderr 'cp.*prof' # preprocess PGO profile
39+
stderr 'preprofile.*-i.*prof'
4040
stderr 'compile.*-pgoprofile=.*triv.go'
4141
stderr 'compile.*-p runtime.*-pgoprofile=.*'
4242

@@ -61,6 +61,7 @@ package main
6161
import (
6262
"os"
6363
"runtime/pprof"
64+
"time"
6465
)
6566

6667
func main() {
@@ -72,6 +73,10 @@ func main() {
7273
if err != nil {
7374
panic(err)
7475
}
76+
// Spin to ensure we get some samples. If we get no samples, the result
77+
// is equivalent to an empty profile.
78+
start := time.Now()
79+
for time.Since(start) < 100*time.Millisecond {}
7580
pprof.StopCPUProfile()
7681
f.Close()
7782
}

src/cmd/go/testdata/script/build_pgo_auto.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# use default.pgo for a single main package
66
go build -n -pgo=auto -o a1.exe ./a/a1
7-
stderr 'cp.*default\.pgo' # preprocess PGO profile
7+
stderr 'preprofile.*-i.*default\.pgo'
88
stderr 'compile.*-pgoprofile=.*a1.go'
99

1010
# check that pgo applied to dependencies

src/cmd/go/testdata/script/build_pgo_auto_multi.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
go install -a -n -pgo=auto ./a ./b ./nopgo
44

55
# a/default.pgo and b/default.pgo are both preprocessed
6-
stderr 'cp.*a(/|\\)default\.pgo'
7-
stderr 'cp.*b(/|\\)default\.pgo'
6+
stderr 'preprofile.*-i.*a(/|\\\\)default\.pgo'
7+
stderr 'preprofile.*-i.*b(/|\\\\)default\.pgo'
88

99
# a and b built once each with PGO.
1010
# Ideally we would check that the passed profile is the expected profile (here

0 commit comments

Comments
 (0)