1 # This is a near copy of build_pgo.txt that does not require build IDs
2 # from the new "go list -export" and "go build" to match.
3 # TODO(mark): Delete one of these files once the experiment concludes.
4
5 [short] skip 'compiles and links executables'
6
7 # Permit the build IDs from "go list -export" and "go build" to differ.
8 env GOEXPERIMENT=golistexportnewformat
9
10 # Set up fresh GOCACHE.
11 env GOCACHE=$WORK/gocache
12 mkdir $GOCACHE
13
14 # build without PGO
15 go build triv.go
16
17 # build with PGO, should trigger rebuild
18 # starting with an empty profile (the compiler accepts it)
19 go build -x -pgo=prof -o triv.exe triv.go
20 stderr 'preprofile.*-i.*prof'
21 stderr 'compile.*-pgoprofile=.*triv.go'
22
23 # check that PGO appears in build info
24 # N.B. we can't start the stdout check with -pgo because the script assumes that
25 # if the first arg starts with - it is a grep flag.
26 go version -m triv.exe
27 stdout 'build\s+-pgo=.*'${/}'prof'
28
29 # store the build ID
30 go list -export -json=BuildID -pgo=prof triv.go
31 stdout '"BuildID":' # check that output actually contains a build ID
32 cp stdout list.out
33
34 # build again with the same profile, should be cached
35 go build -x -pgo=prof -o triv.exe triv.go
36 ! stderr 'compile.*triv.go'
37
38 # overwrite the prof
39 go run overwrite.go
40
41 # build again, profile content changed, should trigger rebuild, including std
42 go build -n -pgo=prof triv.go
43 stderr 'preprofile.*-i.*prof'
44 stderr 'compile.*-pgoprofile=.*triv.go'
45 stderr 'compile.*-p runtime.*-pgoprofile=.*'
46
47 # check that the build ID is different
48 go list -export -json=BuildID -pgo=prof triv.go
49 ! cmp stdout list.out
50
51 # build with trimpath, buildinfo path should be trimmed
52 go build -x -pgo=prof -trimpath -o triv.exe triv.go
53
54 # check that path is trimmed
55 go version -m triv.exe
56 stdout 'build\s+-pgo=prof'
57
58 -- prof --
59 -- triv.go --
60 package main
61 func main() {}
62 -- overwrite.go --
63 package main
64
65 import (
66 "os"
67 "runtime/pprof"
68 "time"
69 )
70
71 func main() {
72 f, err := os.Create("prof")
73 if err != nil {
74 panic(err)
75 }
76 err = pprof.StartCPUProfile(f)
77 if err != nil {
78 panic(err)
79 }
80 // Spin to ensure we get some samples. If we get no samples, the result
81 // is equivalent to an empty profile.
82 start := time.Now()
83 for time.Since(start) < 100*time.Millisecond {}
84 pprof.StopCPUProfile()
85 f.Close()
86 }
87
View as plain text