...
1# Test go build -pgo flag.
2# Specifically, the build cache handles profile content correctly.
3
4[short] skip 'compiles and links executables'
5
6# build without PGO
7go build triv.go
8
9# build with PGO, should trigger rebuild
10# starting with an empty profile (the compiler accepts it)
11go build -x -pgo=prof -o triv.exe triv.go
12stderr 'compile.*-pgoprofile=.*prof.*triv.go'
13
14# check that PGO appears in build info
15# N.B. we can't start the stdout check with -pgo because the script assumes that
16# if the first arg starts with - it is a grep flag.
17go version -m triv.exe
18stdout 'build\s+-pgo=.*'${/}'prof'
19
20# store the build ID
21go list -export -json=BuildID -pgo=prof triv.go
22stdout '"BuildID":' # check that output actually contains a build ID
23cp stdout list.out
24
25# build again with the same profile, should be cached
26go build -x -pgo=prof -o triv.exe triv.go
27! stderr 'compile.*triv.go'
28
29# check that the build ID is the same
30go list -export -json=BuildID -pgo=prof triv.go
31cmp stdout list.out
32
33# overwrite the prof
34go run overwrite.go
35
36# build again, profile content changed, should trigger rebuild
37go build -n -pgo=prof triv.go
38stderr 'compile.*-pgoprofile=.*prof.*p.go'
39
40# check that the build ID is different
41go list -export -json=BuildID -pgo=prof triv.go
42! cmp stdout list.out
43
44# build with trimpath, buildinfo path should be trimmed
45go build -x -pgo=prof -trimpath -o triv.exe triv.go
46
47# check that path is trimmed
48go version -m triv.exe
49stdout 'build\s+-pgo=prof'
50
51-- prof --
52-- triv.go --
53package main
54func main() {}
55-- overwrite.go --
56package main
57
58import (
59 "os"
60 "runtime/pprof"
61)
62
63func main() {
64 f, err := os.Create("prof")
65 if err != nil {
66 panic(err)
67 }
68 err = pprof.StartCPUProfile(f)
69 if err != nil {
70 panic(err)
71 }
72 pprof.StopCPUProfile()
73 f.Close()
74}
View as plain text