Created
November 5, 2012 20:47
-
-
Save buley/4020247 to your computer and use it in GitHub Desktop.
Analyze Jank
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 path = require('path') | |
, fs = require('fs'); | |
file = '' | |
stream = fs.createReadStream( path.normalize( process.argv[ 2 ] ) ); | |
stream.on( 'data', function(data) { | |
file += data.toString(); | |
} ); | |
stream.on( 'end', function() { | |
stream = JSON.parse( file ); | |
var x = 0, xlen = stream.length, jank_ct = 0, jank_paths = {}; | |
for(; x < xlen; x += 1) { | |
item = stream[ x ]; | |
/*console.log( item );*/ | |
var children = item.children, y = 0, ylen = ( 'undefined' !== typeof children ) ? children.length : 0, previous = null, child = null; | |
for(; y < ylen; y += 1) { | |
child = children[ y ]; | |
var since = 0; | |
if ( null !== previous ) { | |
since = child.startTime - previous.endTime; | |
if( !isNaN( since ) ) { | |
if( since > 16.6 ) { | |
jank_ct++; | |
z = 0, zitems = item.children || [], zlen = zitems.length, chain = []; | |
for(; z < zlen; z += 1 ) { | |
ch = zitems[ z ]; | |
chain.push(ch.type) | |
} | |
key = chain.join(' -> ') | |
if ('undefined' === typeof jank_paths[ key ] ) { | |
jank_paths[ key ] = 1; | |
} else { | |
jank_paths[ key ]++; | |
} | |
} | |
} | |
} | |
/*console.log( child );*/ | |
previous = child; | |
} | |
} | |
console.log( jank_paths ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment