return env
}
-var toolchain = []string{"cmd/asm", "cmd/cgo", "cmd/compile", "cmd/link"}
+var toolchain = []string{"cmd/asm", "cmd/cgo", "cmd/compile", "cmd/link", "cmd/preprofile"}
// The bootstrap command runs a build from scratch,
// stopping at having installed the go_bootstrap command.
return err
}
- // TODO(prattmic): This should use go tool preprofile to actually
- // preprocess the profile. For now, this is a dummy implementation that
- // simply copies the input to the output. This is technically a valid
- // implementation because go tool compile -pgofile accepts either a
- // pprof file or preprocessed file.
- if err := sh.CopyFile(a.Target, p.input, 0644, false); err != nil {
+ if err := sh.run(".", p.input, nil, cfg.BuildToolexec, base.Tool("preprofile"), "-o", a.Target, "-i", p.input); err != nil {
return err
}
# build with PGO, should trigger rebuild
# starting with an empty profile (the compiler accepts it)
go build -x -pgo=prof -o triv.exe triv.go
-stderr 'cp.*prof' # preprocess PGO profile
+stderr 'preprofile.*-i.*prof'
stderr 'compile.*-pgoprofile=.*triv.go'
# check that PGO appears in build info
# build again, profile content changed, should trigger rebuild, including std
go build -n -pgo=prof triv.go
-stderr 'cp.*prof' # preprocess PGO profile
+stderr 'preprofile.*-i.*prof'
stderr 'compile.*-pgoprofile=.*triv.go'
stderr 'compile.*-p runtime.*-pgoprofile=.*'
import (
"os"
"runtime/pprof"
+ "time"
)
func main() {
if err != nil {
panic(err)
}
+ // Spin to ensure we get some samples. If we get no samples, the result
+ // is equivalent to an empty profile.
+ start := time.Now()
+ for time.Since(start) < 100*time.Millisecond {}
pprof.StopCPUProfile()
f.Close()
}
# use default.pgo for a single main package
go build -n -pgo=auto -o a1.exe ./a/a1
-stderr 'cp.*default\.pgo' # preprocess PGO profile
+stderr 'preprofile.*-i.*default\.pgo'
stderr 'compile.*-pgoprofile=.*a1.go'
# check that pgo applied to dependencies
go install -a -n -pgo=auto ./a ./b ./nopgo
# a/default.pgo and b/default.pgo are both preprocessed
-stderr 'cp.*a(/|\\)default\.pgo'
-stderr 'cp.*b(/|\\)default\.pgo'
+stderr 'preprofile.*-i.*a(/|\\\\)default\.pgo'
+stderr 'preprofile.*-i.*b(/|\\\\)default\.pgo'
# a and b built once each with PGO.
# Ideally we would check that the passed profile is the expected profile (here