Skip to content

Commit

Permalink
fix(Profiling): Get the timing part working again (#406)
Browse files Browse the repository at this point in the history
* Use rollup to make a version of the LandmarksFinder code that can be run via puppeteer (this had been unintentionally broken by #385).
* Rollup is only run if the source has changed since last time.
* Make the build script clearer when building a debug (as opposed to test) build.
  • Loading branch information
matatk authored Jan 30, 2021
1 parent 02d7ee6 commit a2d120c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ _site
.jekyll-metadata
.nyc_output
coverage
scripts/wrappedLandmarksFinder.js
5 changes: 3 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,14 @@ async function main() {
const action = isFullBuild ? 'Building' : 'Cleaning'
console.log(chalk.bold(`${action} ${extName} ${extVersion}...`))
const debugMode = argv.debug === true
const debugMsg = debugMode ? ' (debug)' : ''

testMode = argv.testRelease === true
const testModeMessage = testMode ? ' (test version)' : ''
const testMsg = testMode ? ' (test)' : ''

for (const browser of browsers) {
console.log()
logStep(chalk.bold(`${action} for ${browser}${testModeMessage}`))
logStep(chalk.bold(`${action} for ${browser}${testMsg}${debugMsg}`))
clean(browser)
if (isFullBuild) {
copyStaticFiles(browser)
Expand Down
41 changes: 33 additions & 8 deletions scripts/profile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict'
const path = require('path')
const fs = require('fs')

const puppeteer = require('puppeteer')
const rollup = require('rollup')
const stats = require('stats-lite')

const urls = Object.freeze({
Expand Down Expand Up @@ -47,7 +49,7 @@ function doLandmarkInsertionRuns(sites, landmarks, runs) {
for (let repetition = 0; repetition < landmarks; repetition++) {
console.log(`Repetition ${repetition}`)
await insertLandmark(page, repetition)
await page.waitFor(delayAfterInsertingLandmark)
await page.waitForTimeout(delayAfterInsertingLandmark)
}

await page.tracing.stop()
Expand Down Expand Up @@ -85,8 +87,30 @@ async function insertLandmark(page, repetition) {
// Specific landmarksFinder test
//

function timeLandmarksFinding(sites, loops) {
const landmarksFinderPath = path.join('scripts', 'generated-landmarks-finder.js')
async function rollLandmarksFinder() {
const inputPath = path.join('src', 'code', 'landmarksFinder.js')
const outputPath = path.join('scripts', 'wrappedLandmarksFinder.js')

const inputModified = fs.statSync(inputPath).mtime
const outputModified = fs.existsSync(outputPath)
? fs.statSync(outputPath).mtime
: null

if (!fs.existsSync(outputPath) || inputModified > outputModified) {
console.log('Rolluping', inputPath, 'to', outputPath)
const bundle = await rollup.rollup({ input: inputPath })
await bundle.write({
file: outputPath,
format: 'cjs',
exports: 'default'
})
}

return outputPath
}

async function timeLandmarksFinding(sites, loops) {
const landmarksFinderPath = await rollLandmarksFinder()
const results = {}

console.log(`Runing landmarks loop test on ${sites}...`)
Expand All @@ -104,6 +128,7 @@ function timeLandmarksFinding(sites, loops) {
console.log(`Running landmark-finding code ${loops} times...`)
const durations = await page.evaluate(scanAndTallyDurations, loops)
results[site] = {
url: urls[site],
mean: stats.mean(durations),
standardDeviation: stats.stdev(durations)
}
Expand Down Expand Up @@ -141,7 +166,7 @@ function printAndSaveResults(results, loops) {
.replace(/:/, '')
const fileName = `times--${loops}--${roughlyNow}.json`
fs.writeFileSync(fileName, resultsJson)
console.log(`${fileName} written to disk.`)
console.log(`${fileName} written.`)
}


Expand All @@ -161,16 +186,16 @@ async function singleRun(page, traceName, pauseBetweenClicks, postDelay) {
path: traceName,
screenshots: true
})
await page.waitFor(500)
await page.waitForTimeout(500)

console.log(`Clicking buttons (pause: ${pauseBetweenClicks})`)
for (const selector of selectors) {
await page.click(selector)
await page.waitFor(pauseBetweenClicks)
await page.waitForTimeout(pauseBetweenClicks)
}

console.log(`Waiting for ${postDelay} for page to settle`)
await page.waitFor(postDelay)
await page.waitForTimeout(postDelay)

console.log('Stopping tracing')
await page.tracing.stop()
Expand Down Expand Up @@ -201,7 +226,7 @@ function traceWithAndWithoutGuarding() {

async function settle(page) {
console.log('Page loaded; settling...')
await page.waitFor(pageSettlingDelay)
await page.waitForTimeout(pageSettlingDelay)
}

function main() {
Expand Down

0 comments on commit a2d120c

Please sign in to comment.