Bug 846687 - Set the transport as non-seekable if the server sends Accept-Ranges...
[gecko.git] / tools / page-loader / graph.pl
blobbb8b04d1299241d54ad9057d1325f1e6b8ce2fdf
1 #!/usr/bin/perl
2 #
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 use CGI::Carp qw(fatalsToBrowser);
7 use CGI::Request;
8 use URLTimingDataSet;
9 use URLTimingGraph;
11 my $request = new CGI::Request;
13 my $id = $request->param('id'); #XXX need to check for valid parameter id
14 my $id2 = $request->param('id2') || undef; # possible comparison test
16 # set up the data for the first graph
17 my $rs = URLTimingDataSet->new($id);
18 my @data = ();
19 push @data, [ map($_->[1], @{$rs->{sorted}}) ]; # URL
20 push @data, [ map($_->[4], @{$rs->{sorted}}) ]; # median
21 # '7' is the first slot for individual test run data
22 for (my $idx = 7; $idx < (7+$rs->{count}); $idx++) {
23 push @data, [ map($_->[$idx], @{$rs->{sorted}}) ];
27 # set up the data for the second graph, if requested a second id
28 # need to sort according to the first chart's ordering
29 my $rs2;
30 if ($id2) {
31 $rs2 = URLTimingDataSet->new($id2);
32 my @order = map($_->[0], @{$rs->{sorted}}); # get the first chart's order
33 my @resort = ();
34 for my $i (@order) {
35 for (@{$rs2->{sorted}}) {
36 if ($i == $_->[0]) {
37 push @resort, $_;
38 last;
42 push @data, [ map($_->[4], @resort) ]; # median
43 for (my $idx = 7; $idx < (7+$rs2->{count}); $idx++) {
44 push @data, [ map($_->[$idx], @resort) ];
48 # and now convert 'NaN' to undef, if they exist in the data.
49 for (@data) { for (@$_) { $_ = undef if $_ eq "NaN"; } }
51 # set up the chart parameters
52 my $args = {};
53 $args->{cgimode} = 1;
54 $args->{title} = "id=$id";
56 # need to draw first visit as dotted with points
57 my $types = ['lines','lines']; for (1..$rs->{count}-1) { push @$types, undef; }
58 my $dclrs = []; for (0..$rs->{count}) { push @$dclrs, 'lred'; }
59 my $legend = [$id]; for (1..$rs->{count}) { push @$legend, undef; }
60 if ($id2) {
61 push @$types, 'lines'; for (1..$rs2->{count}) { push @$types, undef; }
62 for (0..$rs2->{count}) { push @$dclrs, 'lblue'; }
63 push @$legend, $id2; for (1..$rs2->{count}) { push @$legend, undef; }
65 $args->{types} = $types;
66 $args->{dclrs} = $dclrs;
67 $args->{legend} = $legend;
69 #XXX set min to zero, and round max to 1000
70 $args->{y_max_value} = maxDataOrCap();
71 ## nope $args->{y_min_value} = 1000;
72 $args->{width} = 800;
73 $args->{height} = 720;
75 my $g = URLTimingGraph->new(\@data, $args);
76 $g->plot();
78 exit;
81 sub maxDataOrCap {
82 my $max;
83 warn $rs->{maximum};
84 if ($rs2 && ($rs->{maximum} < $rs2->{maximum})) {
85 $max = $rs2->{maximum};
86 } else {
87 $max = $rs->{maximum};
89 warn $max;
90 #return $max > 10000 ? 10000 : 1000*int($max/1000)+1000;
91 # just return whatever, rounded to 1000
92 return 1000*int($max/1000)+1000;