Create a gist now

Instantly share code, notes, and snippets.

@axemclion /index.js
Last active Aug 29, 2015

What would you like to do?
ScrollJank with WebPageTest
// More details in blog post at
/*****
http://bit.ly/wpt-scrolljank
*****/
var url = 'http://nparashuram.com/perfslides';
var wptUrl = 'http://192.168.254.21'; // Location of WPT instance
var POLLING_INTERVAL = 1000 * 10; // Look every 10 seconds
var request = require('request');
function runTest(url, cb) {
var formData = {
url: url,
where: 'Test_loc',
browser: 'Chrome',
location: 'Test:Chrome.Cable',
runs: 1,
fvonly: 1,
video: 'on',
trace: 'on',
f: 'json',
cmdline: '--enable-gpu-benchmarking --enable-thread-composting',
script: '\nnavigate\t' + url + '\nexecAndWait window.chrome.gpuBenchmarking.smoothScrollBy(5000,function(){},0.5,0.5,chrome.gpuBenchmarking.DEFAULT_INPUT,"down",500);'
};
console.log('Starting test on', url);
request.post({
url: wptUrl + '/runtest.php',
formData: formData
}, function(err, httpResponse, body) {
if (err) {
cb(err);
} else {
console.log('Test submitted successfully');
isTestDone(JSON.parse(body).data.jsonUrl, cb);
}
});
}
function isTestDone(url, cb) {
console.log('Checking status on ', url);
(function repeat() {
request.get(url, function(err, resp, body) {
if (err) {
console.log('Error in status URL');
cb(err);
}
var data = JSON.parse(body);
if (data.statusCode !== 200) {
console.log(data.statusText);
setTimeout(repeat, POLLING_INTERVAL);
} else {
cb(undefined, data);
}
});
})();
}
function getLogs(testId, cb) {
var fileUrl = wptUrl + '/getgzip.php?file=1_trace.json&test=' + testId;
console.log('Fetching Logs from ', fileUrl);
var rasterize_time = [],
rasterized_pixel_count = [],
frame_times = [],
frame_timestamps = [],
total = 0;
request(fileUrl, function(err, resp, body) {
var log = JSON.parse(body);
var first_frame = true;
log.traceEvents.forEach(function(event) {
if (event.name === 'BenchmarkInstrumentation::ImplThreadRenderingStats' || event.name === 'BenchmarkInstrumentation::MainThreadRenderingStats') {
var frame_count = event.args['data']['frame_count'];
if (frame_count > 1) throw 'trace contains multi-frame render stats'
if (frame_count == 1) {
frame_timestamps.push(event.ts / 1000);
if (!first_frame) {
frame_times.push(frame_timestamps[frame_timestamps.length - 1] - frame_timestamps[frame_timestamps.length - 2]);
total += frame_times[frame_times.length - 1];
}
first_frame = false;
}
rasterize_time.push(1000.0 * event.args['data']['rasterize_time']);
rasterized_pixel_count.push(event.args['data']['rasterized_pixel_count']);
}
});
cb(total / frame_times.length);
});
}
runTest(url, function(err, data) {
var id = data.data.id;
getLogs(id, console.log.bind(console));
});
//getLogs('141219_A4_F', console.log.bind(console));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment