Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Profiling): Get the timing part working again #406

Merged
merged 5 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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