forked from berty/weshnet
-
Notifications
You must be signed in to change notification settings - Fork 5
209 lines (186 loc) · 7.34 KB
/
benchmark.yml
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Go benchmark
on:
push:
tags:
- v*
branches:
- main
paths:
- "**"
- "!**.md"
- "go.*"
- "**.go"
- ".github/workflows/benchmark.yml"
pull_request:
paths:
- "**"
- "!**.md"
- "go.*"
- "**.go"
- ".github/workflows/benchmark.yml"
jobs:
benchmark:
if: github.event_name == 'DISABLED'
name: Run benchmarks
runs-on: ubuntu-latest
steps:
- name: Setup asdf
uses: asdf-vm/actions/setup@v1
- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v1
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 50 # this is to make sure we obtain the target base commit#
- name: Setup go
run: |
asdf plugin add golang
asdf install golang
echo "go_version=$(asdf current golang | xargs | cut -d ' ' -f 2)" >> $GITHUB_ENV
go install golang.org/x/perf/cmd/benchstat@latest
asdf reshim golang
- name: Cache go modules
uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-
- name: Run benchmark
run: make go.unittest | tee output_head.txt
working-directory: .
env:
TEST_SPEED: any
GO_TEST_PATH: ./internal/benchmark
GO_TEST_OPTS: -bench=. -test.benchmem -cpuprofile cpu_head.prof -memprofile mem_head.prof -test.timeout=1200s -count=5
- name: Checkout base commit
run: git checkout ${{ github.event.pull_request.base.sha }}
if: github.event_name == 'pull_request'
- name: Cache go modules (main)
uses: actions/[email protected]
if: github.event_name == 'pull_request'
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ env.go_version }}-${{ env.json_cache-versions_go }}-
- name: Run benchmark (main)
run: make go.unittest | tee output_base.txt
if: github.event_name == 'pull_request'
working-directory: .
env:
TEST_SPEED: any
GO_TEST_PATH: ./internal/benchmark
GO_TEST_OPTS: -bench=. -test.benchmem -cpuprofile cpu_base.prof -memprofile mem_base.prof -test.timeout=1200s -count=5
- name: Benchstat
id: benchstat-main
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: |
echo 'Benchmark report' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
benchstat output_head.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
working-directory: .
- name: Benchstat PR
id: benchstat-pr
if: github.event_name == 'pull_request'
run: |
echo 'Benchmark report' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
benchstat output_head.txt output_base.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
working-directory: .
- name: Generate pprof html files
id: pprof-html-files-no-relative
working-directory: .
run: |
mkdir -p pprof_html/head/{cpu,mem}/{top,flamegraph,peek,source}
go tool pprof -http 0.0.0.0:9402 -no_browser ./cpu_head.prof < /dev/null & # https://github.com/google/pprof/issues/401#issuecomment-739576424
sleep 2
curl http://localhost:9402/ui/ > pprof_html/head/cpu/index.html
curl http://localhost:9402/ui/top > pprof_html/head/cpu/top/index.html
curl http://localhost:9402/ui/flamegraph > pprof_html/head/cpu/flamegraph/index.html
curl http://localhost:9402/ui/peek > pprof_html/head/cpu/peek/index.html
curl http://localhost:9402/ui/source > pprof_html/head/cpu/source/index.html
pkill pprof
sleep 2
go tool pprof -http 0.0.0.0:9402 -no_browser ./mem_head.prof < /dev/null &
sleep 2
curl http://localhost:9402/ui/ > pprof_html/head/mem/index.html
curl http://localhost:9402/ui/top > pprof_html/head/mem/top/index.html
curl http://localhost:9402/ui/flamegraph > pprof_html/head/mem/flamegraph/index.html
curl http://localhost:9402/ui/peek > pprof_html/head/mem/peek/index.html
curl http://localhost:9402/ui/source > pprof_html/head/mem/source/index.html
pkill pprof
sleep 2
cat << EOF > pprof_html/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>pprof output</title>
</head>
<body>
<h2>CPU output</h2>
<ul>
<li><a href="./head/cpu/">Graph</a></li>
<li><a href="./head/cpu/top/">Top</a></li>
<li><a href="./head/cpu/flamegraph/">Flamegraph</a></li>
<li><a href="./head/cpu/peek/">Peek</a></li>
<li><a href="./head/cpu/source/">Source</a></li>
</ul>
<h2>Memory output</h2>
<ul>
<li><a href="./head/mem/">Graph</a></li>
<li><a href="./head/mem/top/">Top</a></li>
<li><a href="./head/mem/flamegraph/">Flamegraph</a></li>
<li><a href="./head/mem/peek/">Peek</a></li>
<li><a href="./head/mem/source/">Source</a></li>
</ul>
EOF
- name: Generate pprof html files (PR)
if: github.event_name == 'pull_request'
id: pprof-html-files-pr
working-directory: .
run: |
mkdir -p pprof_html/base_comp/{cpu,mem}
go tool pprof -http 0.0.0.0:9402 --diff_base=./cpu_base.prof -no_browser ./cpu_head.prof < /dev/null &
sleep 2
curl http://localhost:9402/ui/ > pprof_html/base_comp/cpu/index.html
pkill pprof
sleep 2
go tool pprof -http 0.0.0.0:9402 --diff_base=./mem_base.prof -no_browser ./mem_head.prof < /dev/null &
sleep 2
curl http://localhost:9402/ui/ > pprof_html/base_comp/mem/index.html
pkill pprof
sleep 2
cat << EOF >> pprof_html/index.html
<h2>CPU diff against ${{ github.event.pull_request.base.sha }}</h2>
<ul>
<li><a href="./base_comp/cpu/">Graph</a></li>
</ul>
<h2>Memory diff against ${{ github.event.pull_request.base.sha }}</h2>
<ul>
<li><a href="./base_comp/mem/">Graph</a></li>
</ul>
EOF
- name: Generate pprof html files (footer)
id: pprof-html-files-footer
working-directory: .
run: |
cat << EOF >> pprof_html/index.html
</body>
</html>
EOF
# upload arifacts
#
- name: upload artifact (main)
uses: actions/upload-artifact@v3
if: github.ref == 'refs/heads/main'
with:
name: "bench-main"
path: go/pprof_html
- name: upload artifact (PR)
uses: actions/upload-artifact@v3
if: github.event_name == 'pull_request'
with:
name: "bench-${{ github.event.pull_request.number }}"
path: go/pprof_html