Created
August 31, 2017 15:39
-
-
Save ilyaevseev/279ca73edd91646a3ed8a55e7058c86e to your computer and use it in GitHub Desktop.
Measure webpage load timings.
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
"use strict"; | |
var page = require('webpage').create(), | |
system = require('system'), | |
imgname; | |
if (system.args.length === 1) { | |
console.log('Usage: http2check.js <imagename>'); | |
phantom.exit(1); | |
} | |
imgname = system.args[1]; | |
page.open('https://http2.akamai.com/demo', function() { | |
page.render(imgname + '.png'); | |
phantom.exit(); | |
} ); |
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
"use strict"; | |
var page = require('webpage').create(), | |
system = require('system'), | |
address; | |
if (system.args.length === 1) { | |
console.log('Usage: netlog.js <some URL>'); | |
phantom.exit(1); | |
} else { | |
address = system.args[1]; | |
page.onResourceRequested = function (req) { | |
console.log('requested: ' + JSON.stringify(req, undefined, 4)); | |
}; | |
page.onResourceReceived = function (res) { | |
console.log('received: ' + JSON.stringify(res, undefined, 4)); | |
}; | |
//page.customHeaders = { 'Connection': 'close' }; | |
page.open(address, function (status) { | |
if (status !== 'success') { | |
console.log('FAIL to load the address'); | |
} | |
phantom.exit(); | |
}); | |
} |
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/perl | |
use strict; | |
use warnings; | |
use POSIX qw/strftime/; | |
use Date::Parse; | |
my %urls; | |
my $method; | |
my $timestamp; | |
my $timestart; | |
while(<>) { | |
# print "Line $_"; | |
$method = $1 if /\"method\": \"(.+)\"/; | |
$timestamp = $1 if /\"time\": \"(.+)\"/; | |
my $url = $1 if /\"url\": \"(.+)\"/; | |
next unless $timestamp and $url; | |
my $ts = str2time($timestamp); | |
$timestart ||= $ts; | |
# print "Save $timestamp, $method, $url\n"; | |
my $u = $urls{$url} ||= {}; | |
if ($method) { | |
$u->{START} ||= $ts; | |
} else { | |
$u->{FINISH} = $ts; | |
} | |
($method, $timestamp, $url) = (undef, undef, undef); | |
} | |
sub dt($) { my $a = shift; ($a->{FINISH} || 0) - ($a->{START} || 0) } | |
sub ts($) { my $t = shift or return 0; strftime('%Y-%m-%d %H:%M:%S', localtime($t)) . sprintf(".%03d", ($t - int($t)) * 1000) } | |
while (my ($url, $urlinfo) = each %urls) { | |
print "$url: missing START\n" unless $urlinfo->{START}; | |
print "$url: missing FINISH\n" unless $urlinfo->{FINISH}; | |
} | |
my @k = sort { dt( $urls{$b} ) <=> dt( $urls{$a} ) } keys %urls; | |
foreach (@k) { | |
my $u = $urls{$_}; | |
printf "%-3.4f %-3.4f %s %s %s\n", dt($u), ($u->{START} - $timestart), ts($u->{START}), ts($u->{FINISH}), $_; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment