Bug 453883, ensure true/false marcos are available, r=joshmoz, sr=jst
[wine-gecko.git] / tools / page-loader / graph.pl
blob5f31e0cb11a91a3db3b09874e7a1035562e6d48c
1 #!/usr/bin/perl
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is Mozilla page-loader test, released Aug 5, 2001.
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 2001
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s):
24 # John Morrison <jrgm@netscape.com>, original author
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
38 # ***** END LICENSE BLOCK *****
39 use CGI::Carp qw(fatalsToBrowser);
40 use CGI::Request;
41 use URLTimingDataSet;
42 use URLTimingGraph;
44 my $request = new CGI::Request;
46 my $id = $request->param('id'); #XXX need to check for valid parameter id
47 my $id2 = $request->param('id2') || undef; # possible comparison test
49 # set up the data for the first graph
50 my $rs = URLTimingDataSet->new($id);
51 my @data = ();
52 push @data, [ map($_->[1], @{$rs->{sorted}}) ]; # URL
53 push @data, [ map($_->[4], @{$rs->{sorted}}) ]; # median
54 # '7' is the first slot for individual test run data
55 for (my $idx = 7; $idx < (7+$rs->{count}); $idx++) {
56 push @data, [ map($_->[$idx], @{$rs->{sorted}}) ];
60 # set up the data for the second graph, if requested a second id
61 # need to sort according to the first chart's ordering
62 my $rs2;
63 if ($id2) {
64 $rs2 = URLTimingDataSet->new($id2);
65 my @order = map($_->[0], @{$rs->{sorted}}); # get the first chart's order
66 my @resort = ();
67 for my $i (@order) {
68 for (@{$rs2->{sorted}}) {
69 if ($i == $_->[0]) {
70 push @resort, $_;
71 last;
75 push @data, [ map($_->[4], @resort) ]; # median
76 for (my $idx = 7; $idx < (7+$rs2->{count}); $idx++) {
77 push @data, [ map($_->[$idx], @resort) ];
81 # and now convert 'NaN' to undef, if they exist in the data.
82 for (@data) { for (@$_) { $_ = undef if $_ eq "NaN"; } }
84 # set up the chart parameters
85 my $args = {};
86 $args->{cgimode} = 1;
87 $args->{title} = "id=$id";
89 # need to draw first visit as dotted with points
90 my $types = ['lines','lines']; for (1..$rs->{count}-1) { push @$types, undef; }
91 my $dclrs = []; for (0..$rs->{count}) { push @$dclrs, 'lred'; }
92 my $legend = [$id]; for (1..$rs->{count}) { push @$legend, undef; }
93 if ($id2) {
94 push @$types, 'lines'; for (1..$rs2->{count}) { push @$types, undef; }
95 for (0..$rs2->{count}) { push @$dclrs, 'lblue'; }
96 push @$legend, $id2; for (1..$rs2->{count}) { push @$legend, undef; }
98 $args->{types} = $types;
99 $args->{dclrs} = $dclrs;
100 $args->{legend} = $legend;
102 #XXX set min to zero, and round max to 1000
103 $args->{y_max_value} = maxDataOrCap();
104 ## nope $args->{y_min_value} = 1000;
105 $args->{width} = 800;
106 $args->{height} = 720;
108 my $g = URLTimingGraph->new(\@data, $args);
109 $g->plot();
111 exit;
114 sub maxDataOrCap {
115 my $max;
116 warn $rs->{maximum};
117 if ($rs2 && ($rs->{maximum} < $rs2->{maximum})) {
118 $max = $rs2->{maximum};
119 } else {
120 $max = $rs->{maximum};
122 warn $max;
123 #return $max > 10000 ? 10000 : 1000*int($max/1000)+1000;
124 # just return whatever, rounded to 1000
125 return 1000*int($max/1000)+1000;