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
7 go build triv.go
8
9 # build with PGO, should trigger rebuild
10 # starting with an empty profile (the compiler accepts it)
11 go build -x -pgo=prof -o triv.exe triv.go
12 stderr '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.
17 go version -m triv.exe
18 stdout 'build\s+-pgo=.*'${/}'prof'
19
20 # store the build ID
21 go list -export -json=BuildID -pgo=prof triv.go
22 stdout '"BuildID":' # check that output actually contains a build ID
23 cp stdout list.out
24
25 # build again with the same profile, should be cached
26 go build -x -pgo=prof -o triv.exe triv.go
27 ! stderr 'compile.*triv.go'
28
29 # check that the build ID is the same
30 go list -export -json=BuildID -pgo=prof triv.go
31 cmp stdout list.out
32
33 # overwrite the prof
34 go run overwrite.go
35
36 # build again, profile content changed, should trigger rebuild
37 go build -n -pgo=prof triv.go
38 stderr 'compile.*-pgoprofile=.*prof.*p.go'
39
40 # check that the build ID is different
41 go list -export -json=BuildID -pgo=prof triv.go
42 ! cmp stdout list.out
43
44 # build with trimpath, buildinfo path should be trimmed
45 go build -x -pgo=prof -trimpath -o triv.exe triv.go
46
47 # check that path is trimmed
48 go version -m triv.exe
49 stdout 'build\s+-pgo=prof'
50
51 -- prof --
52 -- triv.go --
53 package main
54 func main() {}
55 -- overwrite.go --
56 package main
57
58 import (
59 "os"
60 "runtime/pprof"
61 )
62
63 func 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 }
75
View as plain text