← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:27:03 2011

Filename/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine/CGI.pm
StatementsExecuted 111 statements in 3.76ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1113.90ms15.4msFoswiki::Engine::CGI::::BEGIN@22Foswiki::Engine::CGI::BEGIN@22
1112.89ms3.02msFoswiki::Engine::CGI::::BEGIN@24Foswiki::Engine::CGI::BEGIN@24
1112.45ms3.01msFoswiki::Engine::CGI::::BEGIN@18Foswiki::Engine::CGI::BEGIN@18
111637µs781µsFoswiki::Engine::CGI::::BEGIN@23Foswiki::Engine::CGI::BEGIN@23
221451µs451µsFoswiki::Engine::CGI::::CORE:printFoswiki::Engine::CGI::CORE:print (opcode)
111308µs919µsFoswiki::Engine::CGI::::prepareHeadersFoswiki::Engine::CGI::prepareHeaders
111107µs195µsFoswiki::Engine::CGI::::preparePathFoswiki::Engine::CGI::preparePath
111103µs265sFoswiki::Engine::CGI::::runFoswiki::Engine::CGI::run
11196µs122µsFoswiki::Engine::CGI::::prepareConnectionFoswiki::Engine::CGI::prepareConnection
11167µs1.70msFoswiki::Engine::CGI::::finalizeHeadersFoswiki::Engine::CGI::finalizeHeaders
311166µs66µsFoswiki::Engine::CGI::::CORE:matchFoswiki::Engine::CGI::CORE:match (opcode)
103149µs49µsFoswiki::Engine::CGI::::CORE:substFoswiki::Engine::CGI::CORE:subst (opcode)
11135µs72µsFoswiki::Engine::CGI::::writeFoswiki::Engine::CGI::write
11133µs42µsFoswiki::Engine::CGI::::finalizeUploadsFoswiki::Engine::CGI::finalizeUploads
11129µs38µsFoswiki::Engine::CGI::::BEGIN@15Foswiki::Engine::CGI::BEGIN@15
11124µs24µsFoswiki::Engine::CGI::::CORE:regcompFoswiki::Engine::CGI::CORE:regcomp (opcode)
11122µs45µsFoswiki::Engine::CGI::::BEGIN@16Foswiki::Engine::CGI::BEGIN@16
11118µs57µsFoswiki::Engine::CGI::::BEGIN@21Foswiki::Engine::CGI::BEGIN@21
1118µs8µsFoswiki::Engine::CGI::::prepareBodyFoswiki::Engine::CGI::prepareBody
1118µs8µsFoswiki::Engine::CGI::::prepareQueryParametersFoswiki::Engine::CGI::prepareQueryParameters
1117µs7µsFoswiki::Engine::CGI::::prepareBodyParametersFoswiki::Engine::CGI::prepareBodyParameters
1117µs7µsFoswiki::Engine::CGI::::prepareUploadsFoswiki::Engine::CGI::prepareUploads
2117µs7µsFoswiki::Engine::CGI::::CORE:substcontFoswiki::Engine::CGI::CORE:substcont (opcode)
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2
3=begin TML
4
5---+!! package Foswiki::Engine::CGI
6
7Class that implements default CGI behavior.
8
9Refer to Foswiki::Engine documentation for explanation about methods below.
10
11=cut
12
13package Foswiki::Engine::CGI;
14
15250µs246µs
# spent 38µs (29+9) within Foswiki::Engine::CGI::BEGIN@15 which was called: # once (29µs+9µs) by Foswiki::BEGIN@1 at line 15
use strict;
# spent 38µs making 1 call to Foswiki::Engine::CGI::BEGIN@15 # spent 9µs making 1 call to strict::import
16248µs269µs
# spent 45µs (22+23) within Foswiki::Engine::CGI::BEGIN@16 which was called: # once (22µs+23µs) by Foswiki::BEGIN@1 at line 16
use warnings;
# spent 45µs making 1 call to Foswiki::Engine::CGI::BEGIN@16 # spent 23µs making 1 call to warnings::import
17
182188µs13.01ms
# spent 3.01ms (2.45+557µs) within Foswiki::Engine::CGI::BEGIN@18 which was called: # once (2.45ms+557µs) by Foswiki::BEGIN@1 at line 18
use Foswiki::Engine ();
# spent 3.01ms making 1 call to Foswiki::Engine::CGI::BEGIN@18
19112µsour @ISA = ('Foswiki::Engine');
20
21245µs296µs
# spent 57µs (18+39) within Foswiki::Engine::CGI::BEGIN@21 which was called: # once (18µs+39µs) by Foswiki::BEGIN@1 at line 21
use Assert;
# spent 57µs making 1 call to Foswiki::Engine::CGI::BEGIN@21 # spent 39µs making 1 call to Assert::import
222152µs115.4ms
# spent 15.4ms (3.90+11.5) within Foswiki::Engine::CGI::BEGIN@22 which was called: # once (3.90ms+11.5ms) by Foswiki::BEGIN@1 at line 22
use Foswiki::Request ();
# spent 15.4ms making 1 call to Foswiki::Engine::CGI::BEGIN@22
232146µs1781µs
# spent 781µs (637+144) within Foswiki::Engine::CGI::BEGIN@23 which was called: # once (637µs+144µs) by Foswiki::BEGIN@1 at line 23
use Foswiki::Request::Upload ();
# spent 781µs making 1 call to Foswiki::Engine::CGI::BEGIN@23
2421.79ms13.02ms
# spent 3.02ms (2.89+128µs) within Foswiki::Engine::CGI::BEGIN@24 which was called: # once (2.89ms+128µs) by Foswiki::BEGIN@1 at line 24
use Foswiki::Response ();
# spent 3.02ms making 1 call to Foswiki::Engine::CGI::BEGIN@24
25
26
# spent 265s (103µs+265) within Foswiki::Engine::CGI::run which was called: # once (103µs+265s) by main::RUNTIME at line 29 of view
sub run {
2713µs my $this = shift;
2813µs unless ( $Foswiki::cfg{isVALID} ) {
29 print STDOUT "Content-type: text/html\n\n";
30 print STDOUT '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
31 . "\n "
32 . '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n";
33 print STDOUT
34"<html><head></head><body><h1>Foswiki Configuration Error</h1><br>Please run <code>configure</code> to create a valid configuration<br />\n";
35 print STDOUT
36"If you've already done this, then your <code>lib/LocalSite.cfg</code> is most likely damaged\n</body></html>";
37 exit 1;
38 }
39112µs16.28ms my $req = $this->prepare;
# spent 6.28ms making 1 call to Foswiki::Engine::prepare
40126µs14µs if ( UNIVERSAL::isa( $req, 'Foswiki::Request' ) ) {
# spent 4µs making 1 call to UNIVERSAL::isa
4117µs1265s my $res = Foswiki::UI::handleRequest($req);
# spent 265s making 1 call to Foswiki::UI::handleRequest
42156µs12.00ms $this->finalize( $res, $req );
# spent 2.00ms making 1 call to Foswiki::Engine::finalize
43 }
44}
45
46
# spent 122µs (96+26) within Foswiki::Engine::CGI::prepareConnection which was called: # once (96µs+26µs) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 94 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub prepareConnection {
4712µs my ( $this, $req ) = @_;
48
4916µs18µs $req->remoteAddress( $ENV{REMOTE_ADDR} );
# spent 8µs making 1 call to Foswiki::Request::remoteAddress
5019µs110µs $req->method( $ENV{REQUEST_METHOD} );
# spent 10µs making 1 call to Foswiki::Request::method
51
5212µs if ( $ENV{HTTPS} && uc( $ENV{HTTPS} ) eq 'ON' ) {
53 $req->secure(1);
54 }
55
5616µs if ( $ENV{SERVER_PORT} && $ENV{SERVER_PORT} == 443 ) {
57 $req->secure(1);
58 }
59114µs17µs $req->serverPort( $ENV{SERVER_PORT} );
# spent 7µs making 1 call to Foswiki::Request::serverPort
60}
61
62
# spent 8µs within Foswiki::Engine::CGI::prepareQueryParameters which was called: # once (8µs+0s) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 95 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub prepareQueryParameters {
6312µs my ( $this, $req ) = @_;
6419µs $this->SUPER::prepareQueryParameters( $req, $ENV{QUERY_STRING} )
65 if $ENV{QUERY_STRING};
66}
67
68
# spent 919µs (308+611) within Foswiki::Engine::CGI::prepareHeaders which was called: # once (308µs+611µs) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 96 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub prepareHeaders {
6912µs my ( $this, $req ) = @_;
70145µs foreach my $header ( keys %ENV ) {
7131202µs3166µs next unless $header =~ /^(?:HTTP|CONTENT|COOKIE)/i;
# spent 66µs making 31 calls to Foswiki::Engine::CGI::CORE:match, avg 2µs/call
72871µs828µs ( my $field = $header ) =~ s/^HTTPS?_//;
# spent 28µs making 8 calls to Foswiki::Engine::CGI::CORE:subst, avg 4µs/call
73860µs8509µs $req->header( $field => $ENV{$header} );
# spent 509µs making 8 calls to Foswiki::Request::header, avg 64µs/call
74 }
75114µs17µs $req->remoteUser( $ENV{REMOTE_USER} );
# spent 7µs making 1 call to Foswiki::Request::remoteUser
76}
77
78
# spent 195µs (107+88) within Foswiki::Engine::CGI::preparePath which was called: # once (107µs+88µs) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 98 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub preparePath {
7912µs my ( $this, $req ) = @_;
80
81 # SMELL: "The Microsoft Internet Information Server is broken with
82 # respect to additional path information. If you use the Perl DLL
83 # library, the IIS server will attempt to execute the additional
84 # path information as a Perl script. If you use the ordinary file
85 # associations mapping, the path information will be present in the
86 # environment, but incorrect. The best thing to do is to avoid using
87 # additional path information."
88
89 # Clean up PATH_INFO problems, e.g. Support.CobaltRaqInstall. A valid
90 # PATH_INFO is '/Main/WebHome', i.e. the text after the script name;
91 # invalid PATH_INFO is often a full path starting with '/cgi-bin/...'.
9214µs my $pathInfo = $ENV{PATH_INFO} || '';
9312µs unless ( defined $ENV{SCRIPT_NAME} ) {
94
95 # CGI/1.1 (rfc3875) states that the server MUST set
96 # SCRIPT_NAME, so if it doens't we have a broken server
97 my $reason = 'SCRIPT_NAME environment variable not defined';
98 my $res = new Foswiki::Response();
99 $res->header( -type => 'text/html', -status => 500 );
100 my $html = CGI::start_html('500 - Internal Server Error');
101 $html .= CGI::h1( {}, 'Internal Server Error' );
102 $html .= CGI::p( {}, $reason );
103 $html .= CGI::end_html();
104 $res->print($html);
105 throw Foswiki::EngineException( 500, $reason, $res );
106 }
10712µs my $cgiScriptPath = $ENV{SCRIPT_NAME};
108145µs226µs $pathInfo =~ s{^$cgiScriptPath(?:/+|$)}{/};
# spent 24µs making 1 call to Foswiki::Engine::CGI::CORE:regcomp # spent 2µs making 1 call to Foswiki::Engine::CGI::CORE:subst
10912µs my $cgiScriptName = $cgiScriptPath;
110142µs325µs $cgiScriptName =~ s/.*?(\w+)(\.\w+)?$/$1/;
# spent 19µs making 1 call to Foswiki::Engine::CGI::CORE:subst # spent 7µs making 2 calls to Foswiki::Engine::CGI::CORE:substcont, avg 3µs/call
111
11211µs my $action;
11313µs if ( exists $ENV{FOSWIKI_ACTION} ) {
114
115 # This handles scripts that have set $FOSWIKI_ACTION
11613µs $action = $ENV{FOSWIKI_ACTION};
117 }
118 elsif ( exists $Foswiki::cfg{SwitchBoard}{$cgiScriptName} ) {
119
120 # This handles other named CGI scripts that have a switchboard entry
121 # but haven't set $FOSWIKI_ACTION (old-style run scripts)
122 $action = $cgiScriptName;
123 }
124 elsif ( length $pathInfo > 1 ) {
125
126 # This handles twiki_cgi; use the first path el after the script
127 # name as the function
128 $pathInfo =~ m{^/([^/]+)(.*)};
129 my $first = $1; # implicit untaint OK; checked below
130 if ( exists $Foswiki::cfg{SwitchBoard}{$first} ) {
131
132 # The path is of the form script/function/...
133 $action = $first;
134 $pathInfo = $2 || '';
135 }
136 }
13711µs $action ||= 'view';
138112µs15µs ASSERT( defined $pathInfo ) if DEBUG;
# spent 5µs making 1 call to Assert::ASSERTS_OFF
13917µs117µs $req->action($action);
# spent 17µs making 1 call to Foswiki::Request::action
14016µs18µs $req->pathInfo($pathInfo);
# spent 8µs making 1 call to Foswiki::Request::pathInfo
141117µs18µs $req->uri( $ENV{REQUEST_URI}
# spent 8µs making 1 call to Foswiki::Request::uri
142 || $req->url( -absolute => 1, -path => 1, -query => 1 ) );
143}
144
145
# spent 8µs within Foswiki::Engine::CGI::prepareBody which was called: # once (8µs+0s) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 99 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub prepareBody {
14612µs my ( $this, $req ) = @_;
147
14819µs return unless $ENV{CONTENT_LENGTH};
149 my $cgi = new CGI();
150 my $err = $cgi->cgi_error;
151 throw Foswiki::EngineException( $1, $2 )
152 if defined $err && $err =~ /\s*(\d{3})\s*(.*)/;
153 $this->{cgi} = $cgi;
154}
155
156
# spent 7µs within Foswiki::Engine::CGI::prepareBodyParameters which was called: # once (7µs+0s) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 100 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub prepareBodyParameters {
15712µs my ( $this, $req ) = @_;
158
15918µs return unless $ENV{CONTENT_LENGTH};
160 my @plist = $this->{cgi}->param();
161 foreach my $pname (@plist) {
162 my @values = map { "$_" } $this->{cgi}->param($pname);
163 $req->bodyParam( -name => $pname, -value => \@values );
164 $this->{uploads}{$pname} = 1 if scalar $this->{cgi}->upload($pname);
165 }
166}
167
168
# spent 7µs within Foswiki::Engine::CGI::prepareUploads which was called: # once (7µs+0s) by Foswiki::Engine::__ANON__[/usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm:102] at line 101 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub prepareUploads {
16912µs my ( $this, $req ) = @_;
170
17118µs return unless $ENV{CONTENT_LENGTH};
172 my %uploads;
173 foreach my $key ( keys %{ $this->{uploads} } ) {
174 my $fname = $this->{cgi}->param($key);
175 $uploads{"$fname"} = new Foswiki::Request::Upload(
176 headers => $this->{cgi}->uploadInfo($fname),
177 tmpname => $this->{cgi}->tmpFileName($fname),
178 );
179 }
180 delete $this->{uploads};
181 $req->uploads( \%uploads );
182}
183
184
# spent 42µs (33+9) within Foswiki::Engine::CGI::finalizeUploads which was called: # once (33µs+9µs) by Foswiki::Engine::finalize at line 299 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub finalizeUploads {
18512µs my ( $this, $res, $req ) = @_;
186
187216µs19µs $req->delete($_) foreach keys %{ $req->uploads };
# spent 9µs making 1 call to Foswiki::Request::uploads
188113µs undef $this->{cgi};
189}
190
191
# spent 1.70ms (67µs+1.63) within Foswiki::Engine::CGI::finalizeHeaders which was called: # once (67µs+1.63ms) by Foswiki::Engine::finalize at line 300 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub finalizeHeaders {
19212µs my ( $this, $res, $req ) = @_;
193132µs1820µs $this->SUPER::finalizeHeaders( $res, $req );
# spent 820µs making 1 call to Foswiki::Engine::finalizeHeaders
194
195110µs1397µs my $hdr = $res->printHeaders;
# spent 397µs making 1 call to Foswiki::Response::printHeaders
1961438µs1414µs print $hdr;
# spent 414µs making 1 call to Foswiki::Engine::CGI::CORE:print
197}
198
199
# spent 72µs (35+37) within Foswiki::Engine::CGI::write which was called: # once (35µs+37µs) by Foswiki::Engine::finalizeBody at line 409 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Engine.pm
sub write {
200122µs my ( $this, $buffer ) = @_;
201153µs137µs print $buffer;
# spent 37µs making 1 call to Foswiki::Engine::CGI::CORE:print
202}
203
20416µs1;
205__END__
 
# spent 66µs within Foswiki::Engine::CGI::CORE:match which was called 31 times, avg 2µs/call: # 31 times (66µs+0s) by Foswiki::Engine::CGI::prepareHeaders at line 71, avg 2µs/call
sub Foswiki::Engine::CGI::CORE:match; # opcode
# spent 451µs within Foswiki::Engine::CGI::CORE:print which was called 2 times, avg 226µs/call: # once (414µs+0s) by Foswiki::Engine::CGI::finalizeHeaders at line 196 # once (37µs+0s) by Foswiki::Engine::CGI::write at line 201
sub Foswiki::Engine::CGI::CORE:print; # opcode
# spent 24µs within Foswiki::Engine::CGI::CORE:regcomp which was called: # once (24µs+0s) by Foswiki::Engine::CGI::preparePath at line 108
sub Foswiki::Engine::CGI::CORE:regcomp; # opcode
# spent 49µs within Foswiki::Engine::CGI::CORE:subst which was called 10 times, avg 5µs/call: # 8 times (28µs+0s) by Foswiki::Engine::CGI::prepareHeaders at line 72, avg 4µs/call # once (19µs+0s) by Foswiki::Engine::CGI::preparePath at line 110 # once (2µs+0s) by Foswiki::Engine::CGI::preparePath at line 108
sub Foswiki::Engine::CGI::CORE:subst; # opcode
# spent 7µs within Foswiki::Engine::CGI::CORE:substcont which was called 2 times, avg 3µs/call: # 2 times (7µs+0s) by Foswiki::Engine::CGI::preparePath at line 110, avg 3µs/call
sub Foswiki::Engine::CGI::CORE:substcont; # opcode