tools/page-loader/URLTimingGraph.pm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/page-loader/URLTimingGraph.pm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +# 
     1.5 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +package URLTimingGraph;
     1.9 +use strict;
    1.10 +use GD;
    1.11 +use GD::Graph::linespoints;
    1.12 +use GD::Graph::points;
    1.13 +use GD::Graph::lines;
    1.14 +use GD::Graph::mixed;
    1.15 +use GD::Graph::colour;
    1.16 +use GD::Graph::Data;
    1.17 +
    1.18 +sub new {
    1.19 +    my $proto = shift;
    1.20 +    my $class = ref($proto) || $proto;
    1.21 +    my $self  = {};
    1.22 +    bless ($self, $class);
    1.23 +    $self->{data} = shift || die "No data.";
    1.24 +    my $args  = shift || {};
    1.25 +    $self->{cgimode} = $args->{cgimode} || 0;
    1.26 +    $self->{title}   = $args->{title}   || ""; 
    1.27 +    $self->{types}   = $args->{types}   || ['lines', undef, undef, undef, undef, undef, undef]; 
    1.28 +    $self->{dclrs}   = $args->{dclrs}   || [qw(lred)];
    1.29 +    $self->{legend}  = $args->{legend}  || [qw(undef)];
    1.30 +    $self->{y_max_value} = $args->{y_max_value} || 10000;
    1.31 +    $self->{width}   = $args->{width}   || 800;
    1.32 +    $self->{height}  = $args->{height}  || 720;
    1.33 +    return $self;
    1.34 +}
    1.35 +
    1.36 +sub _set_standard_options {
    1.37 +    my $self = shift;
    1.38 +    $self->{graph}->set( 
    1.39 +                 x_label => '',
    1.40 +                 y_label => 'Page Load Time (msec)',
    1.41 +                 default_type => 'points',
    1.42 +                 x_labels_vertical => 1,
    1.43 +                 y_long_ticks => 1,
    1.44 +                 x_tick_length => 8,
    1.45 +                 x_long_ticks => 0,
    1.46 +                 line_width => 2,
    1.47 +                 marker_size => 3,
    1.48 +                 markers => [8],
    1.49 +                 show_values => 0,
    1.50 +                 transparent => 0,
    1.51 +                 interlaced => 1,
    1.52 +                 skip_undef => 1,
    1.53 +                 ) 
    1.54 +         || warn $self->{graph}->error;
    1.55 +    $self->{graph}->set_title_font(GD::Font->Giant);
    1.56 +    $self->{graph}->set_x_label_font(GD::Font->Large);
    1.57 +    $self->{graph}->set_y_label_font(GD::Font->Large);
    1.58 +    $self->{graph}->set_x_axis_font(GD::Font->Large);
    1.59 +    $self->{graph}->set_y_axis_font(GD::Font->Large);
    1.60 +    $self->{graph}->set_legend_font(GD::Font->Giant);
    1.61 +}
    1.62 +
    1.63 +sub plot {
    1.64 +    my $self = shift;
    1.65 +    $self->{graph} = new GD::Graph::mixed($self->{width}, 
    1.66 +                                          $self->{height});
    1.67 +    $self->_set_standard_options();
    1.68 +
    1.69 +    $self->{graph}->set(title => $self->{title},
    1.70 +                        types => $self->{types},
    1.71 +                        y_max_value => $self->{y_max_value},
    1.72 +                        dclrs => $self->{dclrs},
    1.73 +                        ) 
    1.74 +         || warn $self->{graph}->error;
    1.75 +
    1.76 +    $self->{graph}->set_legend( @{$self->{legend}} );
    1.77 +
    1.78 +    # draw the graph image
    1.79 +    $self->{graph}->plot($self->{data}) || 
    1.80 +         die $self->{graph}->error;
    1.81 +
    1.82 +    # send it back to stdout (or browser)
    1.83 +    print "Content-type: image/png\n\n" if $self->{cgimode};
    1.84 +    binmode STDOUT;
    1.85 +    print $self->{graph}->gd->png();
    1.86 +}
    1.87 +
    1.88 +
    1.89 +1; #return true

mercurial