tools/page-loader/URLTimingGraph.pm
author Gregory Szorc <gps@mozilla.com>
Wed, 08 Jan 2014 11:19:21 -0800
changeset 162964 faafb9526e32b28f3b4647845442a3d3971183ec
parent 94475 f4157e8c410708d76703f19e4dfb61859bfe32d8
permissions -rw-r--r--
Bug 957721 - Switch mach's shebang to look for python2.7; r=glandium OpenBSD doesn't have "python" on $PATH by default. "python" may also come from a non-2.7 Python. Switching the shebang will help ensure the user invokes mach with Python 2.7. There is a risk this may break mach for some people. If the masses complain, we may roll back.

# 
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package URLTimingGraph;
use strict;
use GD;
use GD::Graph::linespoints;
use GD::Graph::points;
use GD::Graph::lines;
use GD::Graph::mixed;
use GD::Graph::colour;
use GD::Graph::Data;

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self  = {};
    bless ($self, $class);
    $self->{data} = shift || die "No data.";
    my $args  = shift || {};
    $self->{cgimode} = $args->{cgimode} || 0;
    $self->{title}   = $args->{title}   || ""; 
    $self->{types}   = $args->{types}   || ['lines', undef, undef, undef, undef, undef, undef]; 
    $self->{dclrs}   = $args->{dclrs}   || [qw(lred)];
    $self->{legend}  = $args->{legend}  || [qw(undef)];
    $self->{y_max_value} = $args->{y_max_value} || 10000;
    $self->{width}   = $args->{width}   || 800;
    $self->{height}  = $args->{height}  || 720;
    return $self;
}

sub _set_standard_options {
    my $self = shift;
    $self->{graph}->set( 
                 x_label => '',
                 y_label => 'Page Load Time (msec)',
                 default_type => 'points',
                 x_labels_vertical => 1,
                 y_long_ticks => 1,
                 x_tick_length => 8,
                 x_long_ticks => 0,
                 line_width => 2,
                 marker_size => 3,
                 markers => [8],
                 show_values => 0,
                 transparent => 0,
                 interlaced => 1,
                 skip_undef => 1,
                 ) 
         || warn $self->{graph}->error;
    $self->{graph}->set_title_font(GD::Font->Giant);
    $self->{graph}->set_x_label_font(GD::Font->Large);
    $self->{graph}->set_y_label_font(GD::Font->Large);
    $self->{graph}->set_x_axis_font(GD::Font->Large);
    $self->{graph}->set_y_axis_font(GD::Font->Large);
    $self->{graph}->set_legend_font(GD::Font->Giant);
}

sub plot {
    my $self = shift;
    $self->{graph} = new GD::Graph::mixed($self->{width}, 
                                          $self->{height});
    $self->_set_standard_options();

    $self->{graph}->set(title => $self->{title},
                        types => $self->{types},
                        y_max_value => $self->{y_max_value},
                        dclrs => $self->{dclrs},
                        ) 
         || warn $self->{graph}->error;

    $self->{graph}->set_legend( @{$self->{legend}} );

    # draw the graph image
    $self->{graph}->plot($self->{data}) || 
         die $self->{graph}->error;

    # send it back to stdout (or browser)
    print "Content-type: image/png\n\n" if $self->{cgimode};
    binmode STDOUT;
    print $self->{graph}->gd->png();
}


1; #return true