Created
November 22, 2019 09:11
-
-
Save krisselden/7addba1ee169f8ab7e1b02efd3c30463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawnChrome } = require("chrome-debugging-client"); | |
const { sleep } = require("race-cancellation"); | |
const fs = require("fs"); | |
const DEVTOOLS_CATEGORIES = [ | |
"-*", | |
"devtools.timeline", | |
"viz", | |
"benchmark", | |
"blink", | |
"cc", | |
"gpu", | |
"v8", | |
"v8.execute", | |
"disabled-by-default-devtools.timeline", | |
"disabled-by-default-devtools.timeline.frame", | |
"toplevel", | |
"blink.console", | |
"blink.user_timing", | |
"latencyInfo", | |
"disabled-by-default-v8.cpu_profiler", | |
"disabled-by-default-v8.cpu_profiler", | |
"disabled-by-default.cpu_profiler", | |
"disabled-by-default.cpu_profiler.debug", | |
"renderer", | |
"cpu_profiler" | |
]; | |
main().catch(e => { | |
console.error("%o", e); | |
}); | |
async function main() { | |
const chrome = spawnChrome({ | |
stdio: "inherit", | |
headless: true, | |
additionalArguments: [ | |
"--enable-logging=stderr", | |
"--v=1", | |
`--crash-dump-dir=${__dirname}/tmp`, | |
"--no-sandbox" | |
] | |
}); | |
try { | |
const browser = chrome.connection; | |
const target = await browser.send("Target.createTarget", { | |
url: "about:blank" | |
}); | |
const page = await browser.attachToTarget(target); | |
await Promise.all([ | |
page.send("Page.enable"), | |
page.send("Runtime.enable"), | |
page.send("Network.enable") | |
]); | |
// CPU throttling causes the v8 sample to crash | |
await page.send("Emulation.setCPUThrottlingRate", { | |
rate: 2 | |
}); | |
await page.send("Tracing.start", { | |
traceConfig: { | |
includedCategories: DEVTOOLS_CATEGORIES | |
} | |
}); | |
await Promise.all([ | |
page.until("Page.loadEventFired"), | |
page.send("Page.navigate", { url: "https://www.tracerbench.com" }) | |
]); | |
await sleep(1000); | |
const events = []; | |
page.on("Tracing.dataCollected", event => { | |
events.push(...event.value); | |
}); | |
await Promise.all([ | |
page.until("Tracing.tracingComplete"), | |
page.send("Tracing.end", { | |
traceConfig: { | |
includedCategories: DEVTOOLS_CATEGORIES | |
} | |
}) | |
]); | |
fs.writeFileSync("trace.json", JSON.stringify(events, null, 2)); | |
await chrome.close(); | |
} finally { | |
await chrome.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment