1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/page-loader/graph.pl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +#!/usr/bin/perl 1.5 +# 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 +use CGI::Carp qw(fatalsToBrowser); 1.10 +use CGI::Request; 1.11 +use URLTimingDataSet; 1.12 +use URLTimingGraph; 1.13 + 1.14 +my $request = new CGI::Request; 1.15 + 1.16 +my $id = $request->param('id'); #XXX need to check for valid parameter id 1.17 +my $id2 = $request->param('id2') || undef; # possible comparison test 1.18 + 1.19 +# set up the data for the first graph 1.20 +my $rs = URLTimingDataSet->new($id); 1.21 +my @data = (); 1.22 +push @data, [ map($_->[1], @{$rs->{sorted}}) ]; # URL 1.23 +push @data, [ map($_->[4], @{$rs->{sorted}}) ]; # median 1.24 +# '7' is the first slot for individual test run data 1.25 +for (my $idx = 7; $idx < (7+$rs->{count}); $idx++) { 1.26 + push @data, [ map($_->[$idx], @{$rs->{sorted}}) ]; 1.27 +} 1.28 + 1.29 + 1.30 +# set up the data for the second graph, if requested a second id 1.31 +# need to sort according to the first chart's ordering 1.32 +my $rs2; 1.33 +if ($id2) { 1.34 + $rs2 = URLTimingDataSet->new($id2); 1.35 + my @order = map($_->[0], @{$rs->{sorted}}); # get the first chart's order 1.36 + my @resort = (); 1.37 + for my $i (@order) { 1.38 + for (@{$rs2->{sorted}}) { 1.39 + if ($i == $_->[0]) { 1.40 + push @resort, $_; 1.41 + last; 1.42 + } 1.43 + } 1.44 + } 1.45 + push @data, [ map($_->[4], @resort) ]; # median 1.46 + for (my $idx = 7; $idx < (7+$rs2->{count}); $idx++) { 1.47 + push @data, [ map($_->[$idx], @resort) ]; 1.48 + } 1.49 +} 1.50 + 1.51 +# and now convert 'NaN' to undef, if they exist in the data. 1.52 +for (@data) { for (@$_) { $_ = undef if $_ eq "NaN"; } } 1.53 + 1.54 +# set up the chart parameters 1.55 +my $args = {}; 1.56 +$args->{cgimode} = 1; 1.57 +$args->{title} = "id=$id"; 1.58 + 1.59 +# need to draw first visit as dotted with points 1.60 +my $types = ['lines','lines']; for (1..$rs->{count}-1) { push @$types, undef; } 1.61 +my $dclrs = []; for (0..$rs->{count}) { push @$dclrs, 'lred'; } 1.62 +my $legend = [$id]; for (1..$rs->{count}) { push @$legend, undef; } 1.63 +if ($id2) { 1.64 + push @$types, 'lines'; for (1..$rs2->{count}) { push @$types, undef; } 1.65 + for (0..$rs2->{count}) { push @$dclrs, 'lblue'; } 1.66 + push @$legend, $id2; for (1..$rs2->{count}) { push @$legend, undef; } 1.67 +} 1.68 +$args->{types} = $types; 1.69 +$args->{dclrs} = $dclrs; 1.70 +$args->{legend} = $legend; 1.71 + 1.72 +#XXX set min to zero, and round max to 1000 1.73 +$args->{y_max_value} = maxDataOrCap(); 1.74 +## nope $args->{y_min_value} = 1000; 1.75 +$args->{width} = 800; 1.76 +$args->{height} = 720; 1.77 + 1.78 +my $g = URLTimingGraph->new(\@data, $args); 1.79 +$g->plot(); 1.80 + 1.81 +exit; 1.82 + 1.83 + 1.84 +sub maxDataOrCap { 1.85 + my $max; 1.86 + warn $rs->{maximum}; 1.87 + if ($rs2 && ($rs->{maximum} < $rs2->{maximum})) { 1.88 + $max = $rs2->{maximum}; 1.89 + } else { 1.90 + $max = $rs->{maximum}; 1.91 + } 1.92 + warn $max; 1.93 + #return $max > 10000 ? 10000 : 1000*int($max/1000)+1000; 1.94 + # just return whatever, rounded to 1000 1.95 + return 1000*int($max/1000)+1000; 1.96 +}