| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package HTTPD::Bench::ApacheBench::Run; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 15 | use strict; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 101 |  | 
| 4 | 3 |  |  | 3 |  | 15 | use vars qw($VERSION @ISA); | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 140 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 3 |  |  | 3 |  | 44 | use HTTPD::Bench::ApacheBench; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 69 |  | 
| 7 | 3 |  |  | 3 |  | 16 | use HTTPD::Bench::ApacheBench::Regression; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 3734 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | $HTTPD::Bench::ApacheBench::Run::VERSION = $HTTPD::Bench::ApacheBench::VERSION; | 
| 10 |  |  |  |  |  |  | @HTTPD::Bench::ApacheBench::Run::ISA = | 
| 11 |  |  |  |  |  |  | qw(HTTPD::Bench::ApacheBench::Regression); | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub new { | 
| 14 | 4 |  |  | 4 | 0 | 950 | my ($this, $self) = @_; | 
| 15 | 4 |  | 33 |  |  | 18 | my $class = ref($this) || $this; | 
| 16 | 4 | 50 |  |  |  | 13 | if (ref($self) ne "HASH") {	$self = {} } | 
|  | 0 |  |  |  |  | 0 |  | 
| 17 | 4 |  |  |  |  | 10 | bless $self, $class; | 
| 18 | 4 |  |  |  |  | 11 | $self->initialize; | 
| 19 | 4 |  |  |  |  | 10 | return $self; | 
| 20 |  |  |  |  |  |  | } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub initialize { | 
| 23 | 4 |  |  | 4 | 0 | 7 | my ($self) = @_; | 
| 24 | 4 | 50 |  |  |  | 25 | $self->{order} = "breadth_first" unless $self->{order}; | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | ##################################################### | 
| 29 |  |  |  |  |  |  | ## sanity check on run object variables:           ## | 
| 30 |  |  |  |  |  |  | ##  this method is intended to hopefully catch     ## | 
| 31 |  |  |  |  |  |  | ##  errors that cause a segmentation fault in ab() ## | 
| 32 |  |  |  |  |  |  | ##################################################### | 
| 33 |  |  |  |  |  |  | sub ready_to_execute { | 
| 34 | 0 |  |  | 0 | 0 | 0 | my ($self) = @_; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 0 |  |  |  |  | 0 | foreach (qw(urls cookies postdata head_requests | 
| 37 |  |  |  |  |  |  | content_types request_headers keepalive timelimits)) { | 
| 38 | 0 | 0 |  |  |  | 0 | return 0 unless ref $self->{$_} eq "ARRAY"; | 
| 39 |  |  |  |  |  |  | } | 
| 40 | 0 | 0 |  |  |  | 0 | return 0 if grep { ref($_) || m/\s$/ } @{$self->{urls}}; | 
|  | 0 | 0 |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 0 |  |  |  |  | 0 | return 1; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | ##################################################### | 
| 46 |  |  |  |  |  |  | ## do a pre-execute fixup of run object            ## | 
| 47 |  |  |  |  |  |  | ##################################################### | 
| 48 |  |  |  |  |  |  | sub prepare_for_execute { | 
| 49 | 0 |  |  | 0 | 0 | 0 | my ($self) = @_; | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | # without 'urls' list, execute cannot continue | 
| 52 | 0 | 0 |  |  |  | 0 | return 0 unless ref $self->{urls} eq "ARRAY"; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | # if 'urls' list is not a list of scalars, will segfault; die here instead | 
| 55 | 0 |  |  |  |  | 0 | die "Improper configuration: run urls must be a list of scalars" | 
| 56 | 0 | 0 |  |  |  | 0 | if grep { ref $_ } @{$self->{urls}}; | 
|  | 0 |  |  |  |  | 0 |  | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | # whitespace at the end of urls will cause trouble | 
| 59 | 0 |  |  |  |  | 0 | map { chomp $_ } @{$self->{urls}}; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | # set 'cookies' to undef if not specified | 
| 62 | 0 | 0 |  |  |  | 0 | $self->{cookies} = [undef] unless ref $self->{cookies} eq "ARRAY"; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | # set 'postdata', 'content_types', and 'request_headers' to undef | 
| 65 |  |  |  |  |  |  | #  if not specified in run | 
| 66 | 0 |  |  |  |  | 0 | foreach my $param (qw(postdata head_requests content_types | 
| 67 |  |  |  |  |  |  | request_headers keepalive timelimits)) { | 
| 68 | 0 | 0 |  |  |  | 0 | $self->{$param} = [ map {undef} @{$self->{urls}} ] | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 69 |  |  |  |  |  |  | if ref $self->{$param} ne "ARRAY"; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 0 |  |  |  |  | 0 | return 1; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub pre_execute_warnings { | 
| 76 | 0 |  |  | 0 | 0 | 0 | my ($self) = @_; | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 0 |  |  |  |  | 0 | warn "WARNING: Running with memory level < 3 and using CODE refs in postdata!  This will not give your desired results." | 
| 79 | 0 | 0 | 0 |  |  | 0 | if $self->{memory} < 3 && grep { ref $_ eq 'CODE' } @{$self->{postdata}}; | 
|  | 0 |  |  |  |  | 0 |  | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | sub repeat { | 
| 84 | 2 |  |  | 2 | 0 | 4 | my ($self, $arg) = @_; | 
| 85 | 2 | 50 |  |  |  | 7 | $self->{repeat} = $arg if $arg; | 
| 86 | 2 |  |  |  |  | 8 | return $self->{repeat}; | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | sub order { | 
| 90 | 2 |  |  | 2 | 0 | 4 | my ($self, $arg) = @_; | 
| 91 | 2 | 50 |  |  |  | 6 | $self->{order} = $arg if $arg; | 
| 92 | 2 |  |  |  |  | 8 | return $self->{order}; | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | sub memory { | 
| 96 | 0 |  |  | 0 | 0 | 0 | my ($self, $arg) = @_; | 
| 97 | 0 | 0 |  |  |  | 0 | $self->{memory} = $arg if defined $arg; | 
| 98 | 0 |  |  |  |  | 0 | return $self->{memory}; | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | sub buffersize { | 
| 102 | 0 |  |  | 0 | 0 | 0 | my ($self, $arg) = @_; | 
| 103 | 0 | 0 |  |  |  | 0 | $self->{buffersize} = $arg if $arg; | 
| 104 | 0 |  |  |  |  | 0 | return $self->{buffersize}; | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | sub use_auto_cookies { | 
| 108 | 0 |  |  | 0 | 0 | 0 | my ($self, $arg) = @_; | 
| 109 | 0 | 0 |  |  |  | 0 | $self->{use_auto_cookies} = $arg if defined $arg; | 
| 110 | 0 |  |  |  |  | 0 | return $self->{use_auto_cookies}; | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | sub cookies { | 
| 114 | 2 |  |  | 2 | 0 | 4 | my ($self, $arg) = @_; | 
| 115 | 2 | 100 |  |  |  | 7 | $self->{cookies} = $arg if $arg; | 
| 116 | 2 |  |  |  |  | 8 | return $self->{cookies}; | 
| 117 |  |  |  |  |  |  | } | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | sub request_headers { | 
| 120 | 4 |  |  | 4 | 0 | 12 | my ($self, $arg) = @_; | 
| 121 | 4 | 100 |  |  |  | 13 | $self->{request_headers} = $arg if $arg; | 
| 122 | 4 |  |  |  |  | 14 | return $self->{request_headers}; | 
| 123 |  |  |  |  |  |  | } | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | sub urls { | 
| 126 | 4 |  |  | 4 | 0 | 7 | my ($self, $arg) = @_; | 
| 127 | 4 | 50 |  |  |  | 10 | $self->{urls} = $arg if $arg; | 
| 128 | 4 |  |  |  |  | 563 | return $self->{urls}; | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | sub postdata { | 
| 132 | 4 |  |  | 4 | 0 | 13 | my ($self, $arg) = @_; | 
| 133 | 4 | 100 |  |  |  | 11 | $self->{postdata} = $arg if $arg; | 
| 134 | 4 |  |  |  |  | 11 | return $self->{postdata}; | 
| 135 |  |  |  |  |  |  | } | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | sub head_requests { | 
| 138 | 1 |  |  | 1 | 0 | 14 | my ($self, $arg) = @_; | 
| 139 | 1 | 50 |  |  |  | 4 | $self->{head_requests} = $arg if $arg; | 
| 140 | 1 |  |  |  |  | 2 | return $self->{head_requests}; | 
| 141 |  |  |  |  |  |  | } | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | sub content_types { | 
| 144 | 5 |  |  | 5 | 0 | 15 | my ($self, $arg) = @_; | 
| 145 | 5 | 100 |  |  |  | 15 | $self->{content_types} = $arg if $arg; | 
| 146 | 5 |  |  |  |  | 16 | return $self->{content_types}; | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | sub keepalive { | 
| 150 | 1 |  |  | 1 | 0 | 6 | my ($self, $arg) = @_; | 
| 151 | 1 | 50 |  |  |  | 4 | $self->{keepalive} = $arg if $arg; | 
| 152 | 1 |  |  |  |  | 2 | return $self->{keepalive}; | 
| 153 |  |  |  |  |  |  | } | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | sub timelimits { | 
| 156 | 0 |  |  | 0 | 0 |  | my ($self, $arg) = @_; | 
| 157 | 0 | 0 |  |  |  |  | $self->{timelimits} = $arg if $arg; | 
| 158 | 0 |  |  |  |  |  | return $self->{timelimits}; | 
| 159 |  |  |  |  |  |  | } | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | sub append { | 
| 162 | 0 |  |  | 0 | 0 |  | my ($self, $opt) = @_; | 
| 163 | 0 |  |  |  |  |  | my @postdata; | 
| 164 | 0 | 0 |  |  |  |  | if (ref $opt->{postdata} eq "ARRAY") { | 
| 165 | 0 |  |  |  |  |  | @postdata = @{$opt->{postdata}}; | 
|  | 0 |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | } else { | 
| 167 | 0 |  |  |  |  |  | @postdata = map {undef} @{$opt->{urls}}; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | } | 
| 169 | 0 |  |  |  |  |  | push(@{$self->{urls}}, @{$opt->{urls}}); | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 170 | 0 |  |  |  |  |  | push(@{$self->{postdata}}, @postdata); | 
|  | 0 |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | } | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | sub total_requests { | 
| 174 | 0 |  |  | 0 | 0 |  | my ($self) = @_; | 
| 175 | 0 | 0 | 0 |  |  |  | return 0 unless (ref $self eq "HTTPD::Bench::ApacheBench::Run" and | 
|  |  |  | 0 |  |  |  |  | 
| 176 |  |  |  |  |  |  | ref $self->{urls} eq "ARRAY" and $self->{repeat}); | 
| 177 | 0 |  |  |  |  |  | return ($#{$self->{urls}} + 1) * $self->{repeat}; | 
|  | 0 |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | } | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | sub iteration { | 
| 181 | 0 |  |  | 0 | 0 |  | my ($self, $iter_no) = @_; | 
| 182 | 0 | 0 |  |  |  |  | $iter_no = 0 unless defined $iter_no; | 
| 183 | 0 |  |  |  |  |  | return HTTPD::Bench::ApacheBench::Regression->new | 
| 184 |  |  |  |  |  |  | ({ 'regression'  => $self->{'regression'}, | 
| 185 |  |  |  |  |  |  | 'run_no'      => $self->{'run_no'}, | 
| 186 |  |  |  |  |  |  | 'iter_no'     => $iter_no }); | 
| 187 |  |  |  |  |  |  | } | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | 1; |