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