Last active
November 18, 2015 00:15
-
-
Save krisselden/fe32b4382396672931d8 to your computer and use it in GitHub Desktop.
Count JS functions in v8.log
This file contains hidden or 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
#!/usr/bin/env node | |
var fs = require('fs'); | |
var file = process.argv.length > 2 ? process.argv[2] : 'v8.log'; | |
var log = fs.createReadStream(file, { | |
flags: 'r', | |
encoding: 'utf8', | |
autoClose: true | |
}); | |
var pattern = /\<JS Function (.*) \(SharedFunctionInfo 0x[a-f0-9]+\)\>/gi | |
var entries = []; | |
var map = Object.create(null); | |
var buffer = ''; | |
function processString(str) { | |
var match; | |
pattern.lastIndex = 0; | |
while (match = pattern.exec(buffer)) { | |
var name = match[1]; | |
var entry = map[name]; | |
if (entry === undefined) { | |
entry = { name: name, count: 1 } | |
entries.push(entry); | |
map[name] = entry; | |
} else { | |
entry.count++; | |
} | |
} | |
} | |
log.on('data', function (chunk) { | |
var newline = chunk.lastIndexOf("\n"); | |
if (newline === -1) { | |
buffer += chunk; | |
return; | |
} | |
buffer += chunk.substring(0, newline); | |
processString(buffer); | |
buffer = chunk.substring(newline); | |
}); | |
log.on('error', function (e) { | |
console.error(e); | |
}); | |
log.on('end', function () { | |
processString(buffer); | |
entries.sort(function (a, b) { | |
return b.count - a.count; | |
}); | |
entries.forEach(function (entry) { | |
console.log(entry.name, entry.count); | |
}); | |
}); | |
log.resume(); |
This file contains hidden or 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
/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --no-sandbox --disable-cache --disable-extensions --js-flags="--trace_deopt" http://localhost:8080/ > v8.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment