Fixed spacing in actions/cache/filebackend/filerepo/job folder
[mediawiki.git] / includes / profiler / ProfilerSimpleTrace.php
blobd44dfe1bcb6ad0991bc6d6a3c7dbaca5fd189868
1 <?php
2 /**
3 * Profiler showing execution trace.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Profiler
24 /**
25 * Execution trace
26 * @todo document methods (?)
27 * @ingroup Profiler
29 class ProfilerSimpleTrace extends ProfilerSimple {
30 var $trace = "Beginning trace: \n";
31 var $memory = 0;
33 function profileIn( $functionname ) {
34 parent::profileIn( $functionname );
35 $this->trace .= " " . sprintf( "%6.1f", $this->memoryDiff() ) .
36 str_repeat( " ", count( $this->mWorkStack ) ) . " > " . $functionname . "\n";
39 function profileOut( $functionname ) {
40 global $wgDebugFunctionEntry;
42 if ( $wgDebugFunctionEntry ) {
43 $this->debug( str_repeat( ' ', count( $this->mWorkStack ) - 1 ) . 'Exiting ' . $functionname . "\n" );
46 list( $ofname, /* $ocount */, $ortime ) = array_pop( $this->mWorkStack );
48 if ( !$ofname ) {
49 $this->trace .= "Profiling error: $functionname\n";
50 } else {
51 if ( $functionname == 'close' ) {
52 $message = "Profile section ended by close(): {$ofname}";
53 $functionname = $ofname;
54 $this->trace .= $message . "\n";
56 elseif ( $ofname != $functionname ) {
57 $this->trace .= "Profiling error: in({$ofname}), out($functionname)";
59 $elapsedreal = $this->getTime() - $ortime;
60 $this->trace .= sprintf( "%03.6f %6.1f", $elapsedreal, $this->memoryDiff() ) .
61 str_repeat( " ", count( $this->mWorkStack ) + 1 ) . " < " . $functionname . "\n";
65 function memoryDiff() {
66 $diff = memory_get_usage() - $this->memory;
67 $this->memory = memory_get_usage();
68 return $diff / 1024;
71 function logData() {
72 if ( PHP_SAPI === 'cli' ) {
73 print "<!-- \n {$this->trace} \n -->";
74 } elseif ( $this->getContentType() === 'text/html' ) {
75 print "<!-- \n {$this->trace} \n -->";
76 } elseif ( $this->getContentType() === 'text/javascript' ) {
77 print "\n/*\n {$this->trace}\n*/";
78 } elseif ( $this->getContentType() === 'text/css' ) {
79 print "\n/*\n {$this->trace}\n*/";