From 904a7f6d485731b1a13d2b667a00480ee4dfa47b Mon Sep 17 00:00:00 2001 From: Maximilian Stoiber Date: Thu, 5 Jul 2018 15:35:42 +0200 Subject: [PATCH] Add --tracing to benchmarks --- .gitignore | 3 +++ .npmignore | 3 +++ benchmarks/run-headless.js | 12 ++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index dc0613080..f3251b97f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ lib sandbox/node_modules *.log test-results.json +mount-deep-tree-trace.json +mount-wide-tree-trace.json +update-dynamic-styles-trace.json diff --git a/.npmignore b/.npmignore index 2cc4fbfa2..234ee7d8d 100644 --- a/.npmignore +++ b/.npmignore @@ -9,5 +9,8 @@ lib sandbox/node_modules *.log test-results.json +mount-deep-tree-trace.json +mount-wide-tree-trace.json +update-dynamic-styles-trace.json benchmarks diff --git a/benchmarks/run-headless.js b/benchmarks/run-headless.js index 74747c810..1b78200cd 100644 --- a/benchmarks/run-headless.js +++ b/benchmarks/run-headless.js @@ -2,26 +2,34 @@ const path = require('path'); const puppeteer = require('puppeteer'); const tests = ['Mount deep tree', 'Mount wide tree', 'Update dynamic styles']; +const tracing = process.argv.some(arg => arg.indexOf('tracing') > -1); + +if (tracing) { + console.log('\nTracing enabled. (note that this might impact benchmark results, we recommend leaving this turned off unless you need a trace)') +} (async () => { console.log('\nStarting headless browser...') const browser = await puppeteer.launch(); const page = await browser.newPage(); - await page.tracing.start({ path: 'benchmark-trace.json' }); console.log('Opening benchmark app...') await page.goto(`file://${path.join(__dirname, './dist/index.html')}`); - console.log('Running benchmarks... (this may take a minute; do not use your machine while these are running!)') + console.log('Running benchmarks... (this may take a minute or two; do not use your machine while these are running!)') for (var i = 0; i < tests.length; i++) { const test = tests[i]; + const traceFile = `${test.toLowerCase().replace(/\s/g, '-')}-trace.json`; // styled-components is auto-selected, so all we gotta do is select the benchmark and press "Run" await page.select('[data-testid="benchmark-picker"]', test); await page.waitForSelector('[data-testid="run-button"]') + if (tracing) await page.tracing.start({ path: traceFile }); await page.click('[data-testid="run-button"]') await page.waitForSelector(`[data-testid="${test} results"]`) + if (tracing) await page.tracing.stop(); const result = await page.$eval(`[data-testid="${test} results"]`, node => node.innerText) console.log(`\n---${test}---`) console.log(result) + console.log('Trace written to', traceFile) } console.log('Done!')