Created
June 24, 2019 18:24
-
-
Save billti/a2ee40e60611ec9b37b89c7c00cd39ab 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
/* | |
Post-processing to allow deoptigate to work with browser collected traces. | |
To collect a trace from a Chromium-based browser, run with flags such as the below: | |
%browser_exe% --no-sandbox --disable-extensions --js-flags="--trace-ic --nologfile-per-isolate --logfile=/temp/trace/v8.log" C:\temp\trace\default.html | |
Rename the generated `v8.log` to `v8.pre.log`, to preserve the orignal log | |
before processing with the below (that specific filename is expected). | |
Then run this script in the same directory as `v8.pre.log` to process the | |
log file into something deoptigate can handle (see comments for details). | |
This will create a new `v8.log` file. | |
node striplog.js | |
Then run deoptigate to open the log file, e,g, `npx deoptigate` | |
*/ | |
const fs = require('fs'); | |
let log_text = fs.readFileSync("v8.pre.log", "utf8"); | |
let log_lines = log_text.split('\n'); | |
const badLines = /(extensions::SafeBuiltins:)|(v8\/LoadTimes:)/; | |
// Web servers will have a prefix like: http://localhost:8000/app.js (needs to be just app.js) | |
// Files from Windows something like: file:///C:/temp/app.js (needs to be just /temp/app.js) | |
// Files from Linux something like: file:///home/bill/app.js (needs to be just /home/bill/app.js) | |
const webPrefix = /((https?:\/\/[^\/]*\/)|(file:\/\/\/[a-zA-Z]:)|(file:\/\/))/; | |
let new_lines = ""; | |
log_lines.forEach( line => { | |
// Removes lines containing "extensions::SafeBuiltins:" or "v8/LoadTimes:" | |
if (badLines.test(line)) return; | |
// Remove the http://localhost:8000/-like prefix. | |
const scrubbed_line = line.replace(webPrefix, ""); | |
new_lines += scrubbed_line + "\n"; | |
}); | |
fs.writeFileSync("v8.log", new_lines); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment