Skip to content

Commit 863d54a

Browse files
authored
add a single sirun test (#1272)
* example usage of sirun * put sirun output data in artifacts * add script to get sirun results per commit * explicitly use env var in sirun startup test * make CIRCLE_TOKEN optional in get-results.js
1 parent b44467e commit 863d54a

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed

.circleci/config.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,31 @@ node-bench-e2e-base: &node-bench-e2e-base
6969
name: E2E Benchmark
7070
command: yarn bench:e2e
7171

72+
node-bench-sirun-base: &node-bench-sirun-base
73+
resource_class: small
74+
working_directory: ~/dd-trace-js
75+
steps:
76+
- checkout
77+
- *yarn-versions
78+
- *restore-yarn-cache
79+
- *yarn-install
80+
- *save-yarn-cache
81+
- run:
82+
name: Install system deps
83+
command: apt-get update && apt-get install -y valgrind wget
84+
- run:
85+
name: Install sirun
86+
command: wget https://github.com/DataDog/sirun/releases/download/v0.1.3/sirun-v0.1.3-x86_64-unknown-linux-gnu.tar.gz && tar zxf sirun-v0.1.3-x86_64-unknown-linux-gnu.tar.gz && mv sirun /usr/bin
87+
- run:
88+
name: Run sirun
89+
command: |
90+
cd $SIRUN_TEST_DIR
91+
node /root/dd-trace-js/benchmark/sirun/run-all-variants.js | tee /tmp/sirun-output.ndjson
92+
- store_artifacts:
93+
path: /tmp/sirun-output.ndjson
94+
destination: sirun-output.ndjson
95+
96+
7297
node-integration-base: &node-integration-base
7398
resource_class: small
7499
working_directory: ~/dd-trace-js
@@ -253,6 +278,13 @@ jobs:
253278
- PLUGINS=mongodb-core
254279
- image: circleci/mongo
255280

281+
node-bench-sirun-startup-latest:
282+
<<: *node-bench-sirun-base
283+
docker:
284+
- image: node
285+
environment:
286+
- SIRUN_TEST_DIR=/root/dd-trace-js/benchmark/sirun/startup/
287+
256288
# Core tests
257289

258290
node-core-8:
@@ -1092,6 +1124,7 @@ workflows:
10921124
- node-bench-latest
10931125
- node-bench-profiler-latest
10941126
- node-bench-e2e-latest
1127+
- node-bench-sirun-startup-latest
10951128
- node-amqplib
10961129
- node-amqp10
10971130
- node-aws-sdk
@@ -1342,6 +1375,7 @@ workflows:
13421375
- node-bench-latest
13431376
- node-bench-profiler-latest
13441377
- node-bench-e2e-latest
1378+
- node-bench-sirun-startup-latest
13451379
- node-amqplib
13461380
- node-amqp10
13471381
- node-aws-sdk

benchmark/sirun/get-results.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict'
2+
3+
const https = require('https')
4+
const { execSync } = require('child_process')
5+
6+
const { CIRCLE_TOKEN } = process.env
7+
8+
const ref = process.argv.length > 2 ? process.arv[2] : 'HEAD'
9+
const gitCommit = execSync(`git rev-parse ${ref}`).toString().trim()
10+
11+
const circleHeaders = CIRCLE_TOKEN ? {
12+
'circle-token': CIRCLE_TOKEN
13+
} : {}
14+
15+
const statusUrl = ref =>
16+
`https://api.github.com/repos/DataDog/dd-trace-js/commits/${ref}/statuses?per_page=100`
17+
const artifactsUrl = num =>
18+
`https://circleci.com/api/v1.1/project/github/DataDog/dd-trace-js/${num}/artifacts`
19+
20+
function get (url, headers) {
21+
return new Promise((resolve, reject) => {
22+
https.get(url, { headers: Object.assign({
23+
'user-agent': 'dd-results-retriever',
24+
accept: 'application/json'
25+
}, headers) }, async res => {
26+
if (res.statusCode >= 300 && res.statusCode < 400) {
27+
resolve(get(res.headers.location))
28+
return
29+
}
30+
res.on('error', reject)
31+
let payload = ''
32+
for await (const chunk of res) {
33+
payload += chunk
34+
}
35+
resolve(payload)
36+
}).on('error', reject)
37+
})
38+
}
39+
40+
async function getBuildNumsFromGithub (ref) {
41+
const results = JSON.parse(await get(statusUrl(ref)))
42+
const namesAndNums = {}
43+
for (const build of results.filter(s => s.context.includes('-sirun-'))) {
44+
const url = new URL(build.target_url)
45+
namesAndNums[build.context.replace('ci/circleci: ', '')] = url.pathname.split('/').pop()
46+
}
47+
return namesAndNums
48+
}
49+
50+
async function main () {
51+
const builds = await getBuildNumsFromGithub(gitCommit)
52+
const buildData = {}
53+
for (const name in builds) {
54+
const artifacts = JSON.parse(await get(artifactsUrl(builds[name]), circleHeaders))
55+
const artifactUrl = artifacts.find(a => a.path === 'sirun-output.ndjson').url
56+
const testResults = (await get(artifactUrl, circleHeaders))
57+
.trim().split('\n').map(x => JSON.parse(x))
58+
for (const result of testResults) {
59+
const name = result.name
60+
const variant = result.variant
61+
if (!buildData[name]) {
62+
buildData[name] = {}
63+
}
64+
delete result.name
65+
delete result.variant
66+
buildData[name][variant] = result
67+
}
68+
}
69+
// eslint-disable-next-line no-console
70+
console.log(require('util').inspect(buildData, false, null, true))
71+
}
72+
73+
main()

benchmark/sirun/run-all-variants.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
const childProcess = require('child_process')
4+
const path = require('path')
5+
6+
const metaJson = require(path.join(process.cwd(), 'meta.json'))
7+
8+
const env = Object.assign({}, process.env, { SIRUN_NO_STDIO: '1' })
9+
10+
if (metaJson.variants) {
11+
const variants = metaJson.variants
12+
for (const variant in variants) {
13+
const variantEnv = Object.assign({}, env, { SIRUN_VARIANT: variant })
14+
childProcess.execSync(`sirun meta.json`, { env: variantEnv, stdio: 'inherit' })
15+
}
16+
} else {
17+
childProcess.exec(`sirun meta.json`, { env, stdio: 'inherit' })
18+
}

benchmark/sirun/startup/meta.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "startup",
3+
"run": "node startup-test.js",
4+
"cachegrind": true,
5+
"iterations": 10,
6+
"variants": {
7+
"control": {
8+
"env": {
9+
"USE_TRACER": "0"
10+
}
11+
},
12+
"with-tracer": {
13+
"env": {
14+
"USE_TRACER": "1"
15+
}
16+
}
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
if (Number(process.env.USE_TRACER)) {
4+
require('../../..').init()
5+
}

0 commit comments

Comments
 (0)