-
Notifications
You must be signed in to change notification settings - Fork 136
305 lines (301 loc) · 9.9 KB
/
perf.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: Performance testing
on:
pull_request:
paths:
- 'stack-graphs/**'
env:
BASE_REPO: ${{ github.event.pull_request.base.repo.owner.login }}/${{ github.event.pull_request.base.repo.name }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BASE_DIR: base
BASE_DB: base.sqlite
BASE_ARTIFACT: base-perf-results
HEAD_REPO: ${{ github.event.pull_request.head.repo.owner.login }}/${{ github.event.pull_request.head.repo.name }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
HEAD_DIR: head
HEAD_DB: head.sqlite
HEAD_ARTIFACT: head-perf-results
TEST_REPO: microsoft/TypeScript
TEST_REF: v4.9.5
TEST_DIR: test
TEST_SRC: src/compiler
MASSIF_OUT: perf.out
MASSIF_REPORT: perf.txt
TSSG_TS: tree-sitter-stack-graphs-typescript
jobs:
##
## Determine relevant changes
##
changes:
runs-on: ubuntu-latest
outputs:
base-sha: ${{ env.BASE_SHA }}
head-sha: ${{ env.HEAD_SHA }}
done: ${{ steps.done.outputs.cache-hit }}
steps:
- name: "Checkout base code"
uses: actions/checkout@v3
with:
repository: ${{ env.BASE_REPO }}
ref: ${{ env.BASE_SHA }}
path: ${{ env.BASE_DIR }}
fetch-depth: 0
- name: Find last relevant base commit
run: |
printf 'BASE_SHA=%s\n' "$(git rev-list -1 ${{ env.BASE_SHA }} -- stack-graphs)" >> $GITHUB_ENV
working-directory: ${{ env.BASE_DIR }}
- name: "Checkout head code"
uses: actions/checkout@v3
with:
repository: ${{ env.HEAD_REPO }}
ref: ${{ env.HEAD_SHA }}
path: ${{ env.HEAD_DIR }}
fetch-depth: 0
- name: "Find last relevant head commit"
run: |
printf 'HEAD_SHA=%s\n' "$(git rev-list -1 ${{ env.HEAD_SHA }} -- stack-graphs)" >> $GITHUB_ENV
working-directory: ${{ env.HEAD_DIR }}
- name: "Check cached status"
id: done
uses: actions/cache/restore@v3
with:
path: done
key: ${{ runner.os }}-perf-tested-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}
lookup-only: 'true'
##
## Base performance
##
base-perf:
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.done != 'true'
env:
BASE_SHA: ${{ needs.changes.outputs.base-sha }}
steps:
#
# Install tools
#
- name: Install Rust environment
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo
key: ${{ runner.OS }}-cargo-home
- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind
#
# Cache results
#
- name: "Cache base result"
id: cache-base-result
uses: actions/cache@v3
with:
path: |
${{ env.MASSIF_OUT }}
${{ env.MASSIF_REPORT }}
key: ${{ runner.os }}-perf-result-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}
#
# Checkout code
#
- name: "Checkout base code"
if: steps.cache-base-result.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: ${{ env.BASE_REPO }}
ref: ${{ env.BASE_SHA }}
path: ${{ env.BASE_DIR }}
#
# Build code
#
- name: "Build base CLI"
if: steps.cache-base-result.outputs.cache-hit != 'true'
run: cargo build --package ${{ env.TSSG_TS }} --features cli --release
working-directory: ${{ env.BASE_DIR }}
env:
CARGO_PROFILE_RELEASE_DEBUG: true
#
# Test performance
#
- name: Checkout test code
if: steps.cache-base-result.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: ${{ env.TEST_REPO }}
ref: ${{ env.TEST_REF }}
path: ${{ env.TEST_DIR }}
- name: Profile base memory
if: steps.cache-base-result.outputs.cache-hit != 'true'
run: |
valgrind \
--tool=massif \
--massif-out-file=${{ env.MASSIF_OUT }} \
${{ env.BASE_DIR }}/target/release/${{ env.TSSG_TS }} \
index -D ${{ env.BASE_DB }} --max-file-time=30 --hide-error-details -- ${{ env.TEST_DIR }}/${{ env.TEST_SRC }}
ms_print ${{ env.MASSIF_OUT }} > ${{ env.MASSIF_REPORT }}
#
# Upload results
#
- name: Upload results
uses: actions/upload-artifact@v3
with:
name: ${{ env.BASE_ARTIFACT }}
path: |
${{ env.MASSIF_OUT }}
${{ env.MASSIF_REPORT }}
##
## Head performance
##
head-perf:
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.done != 'true'
env:
HEAD_SHA: ${{ needs.changes.outputs.head-sha }}
steps:
#
# Install tools
#
- name: Install Rust environment
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo
key: ${{ runner.OS }}-cargo-home
- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind
#
# Cache results
#
- name: "Cache head result"
id: cache-head-result
uses: actions/cache@v3
with:
path: |
${{ env.MASSIF_OUT }}
${{ env.MASSIF_REPORT }}
key: ${{ runner.os }}-perf-result-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}
#
# Checkout code
#
- name: "Checkout head code"
if: steps.cache-head-result.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: ${{ env.HEAD_REPO }}
ref: ${{ env.HEAD_SHA }}
path: ${{ env.HEAD_DIR }}
#
# Build code
#
- name: "Build head CLI"
if: steps.cache-head-result.outputs.cache-hit != 'true'
run: cargo build --package ${{ env.TSSG_TS }} --features cli --release
working-directory: ${{ env.HEAD_DIR }}
env:
CARGO_PROFILE_RELEASE_DEBUG: true
#
# Test performance
#
- name: Checkout test code
if: steps.cache-head-result.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: ${{ env.TEST_REPO }}
ref: ${{ env.TEST_REF }}
path: ${{ env.TEST_DIR }}
- name: Profile head memory
if: steps.cache-head-result.outputs.cache-hit != 'true'
run: |
valgrind \
--tool=massif \
--massif-out-file=${{ env.MASSIF_OUT }} \
${{ env.HEAD_DIR }}/target/release/${{ env.TSSG_TS }} \
index -D ${{ env.HEAD_DB }} --max-file-time=30 --hide-error-details -- ${{ env.TEST_DIR }}/${{ env.TEST_SRC }}
ms_print ${{ env.MASSIF_OUT }} > ${{ env.MASSIF_REPORT }}
#
# Upload results
#
- name: Upload results
uses: actions/upload-artifact@v3
with:
name: ${{ env.HEAD_ARTIFACT }}
path: |
${{ env.MASSIF_OUT }}
${{ env.MASSIF_REPORT }}
##
## Performance summary
##
perf-summary:
runs-on: ubuntu-latest
needs:
- changes
- base-perf
- head-perf
if: needs.changes.outputs.done != 'true'
env:
BASE_SHA: ${{ needs.changes.outputs.base-sha }}
HEAD_SHA: ${{ needs.changes.outputs.head-sha }}
SRC_DIR: src
COMMENT_JSON: perf-summary.json
steps:
#
# Install tools
#
- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind
#
# Download results
#
- name: Download base results
uses: actions/download-artifact@v3
with:
name: ${{ env.BASE_ARTIFACT }}
path: ${{ env.BASE_ARTIFACT }}
- name: Download head results
uses: actions/download-artifact@v3
with:
name: ${{ env.HEAD_ARTIFACT }}
path: ${{ env.HEAD_ARTIFACT }}
#
# Create report
#
- name: "Checkout code"
uses: actions/checkout@v3
with:
path: ${{ env.SRC_DIR }}
- name: Generate summary
run: |
${{ env.SRC_DIR }}/script/ci-perf-summary-md \
${{ env.BASE_ARTIFACT }}/${{ env.MASSIF_OUT }} \
${{ env.HEAD_ARTIFACT }}/${{ env.MASSIF_OUT }} \
'Comparing base ${{ env.BASE_REPO }}@${{ env.BASE_SHA }} with head ${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }} on [${{ env.TEST_REPO }}@${{ env.TEST_REF }}](${{ github.server_url }}/${{ env.TEST_REPO }}/tree/${{ env.TEST_REF }}). For details see [workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) artifacts. _Note that performance is tested on the last commits with changes in `stack-graphs`, not on every commit._' \
| ${{ env.SRC_DIR }}/script/ci-comment-json > ${{ env.COMMENT_JSON }}
- name: Add summary comment to PR
run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ github.event.pull_request.comments_url }} \
-d '@${{ env.COMMENT_JSON }}'
- name: Create status marker
run: touch done
- name: "Cache status"
uses: actions/cache/save@v3
with:
path: done
key: ${{ runner.os }}-perf-tested-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }}-${{ env.TEST_REPO }}@${{ env.TEST_REF }}/${{ env.TEST_SRC }}