MediaWiki  1.23.2
ProfilerSimple.php
Go to the documentation of this file.
1 <?php
29 class ProfilerSimple extends Profiler {
30  var $mMinimumTime = 0;
31 
33 
34  public function getZeroEntry() {
35  return array(
36  'cpu' => 0.0,
37  'cpu_sq' => 0.0,
38  'real' => 0.0,
39  'real_sq' => 0.0,
40  'count' => 0
41  );
42  }
43 
44  public function getErrorEntry() {
45  $entry = $this->getZeroEntry();
46  $entry['count'] = 1;
47  return $entry;
48  }
49 
50  public function updateEntry( $name, $elapsedCpu, $elapsedReal ) {
51  $entry =& $this->mCollated[$name];
52  if ( !is_array( $entry ) ) {
53  $entry = $this->getZeroEntry();
54  $this->mCollated[$name] =& $entry;
55  }
56  $entry['cpu'] += $elapsedCpu;
57  $entry['cpu_sq'] += $elapsedCpu * $elapsedCpu;
58  $entry['real'] += $elapsedReal;
59  $entry['real_sq'] += $elapsedReal * $elapsedReal;
60  $entry['count']++;
61  }
62 
63  public function isPersistent() {
64  /* Implement in output subclasses */
65  return false;
66  }
67 
68  protected function addInitialStack() {
69  $this->errorEntry = $this->getErrorEntry();
70 
71  $initialTime = $this->getInitialTime();
72  $initialCpu = $this->getInitialTime( 'cpu' );
73  if ( $initialTime !== null && $initialCpu !== null ) {
74  $this->mWorkStack[] = array( '-total', 0, $initialTime, $initialCpu );
75  $this->mWorkStack[] = array( '-setup', 1, $initialTime, $initialCpu );
76 
77  $this->profileOut( '-setup' );
78  } else {
79  $this->profileIn( '-total' );
80  }
81  }
82 
83  function setMinimum( $min ) {
84  $this->mMinimumTime = $min;
85  }
86 
87  function profileIn( $functionname ) {
88  global $wgDebugFunctionEntry;
89  if ( $wgDebugFunctionEntry ) {
90  $this->debug( str_repeat( ' ', count( $this->mWorkStack ) ) . 'Entering ' . $functionname . "\n" );
91  }
92  $this->mWorkStack[] = array( $functionname, count( $this->mWorkStack ), $this->getTime(), $this->getTime( 'cpu' ) );
93  }
94 
95  function profileOut( $functionname ) {
96  global $wgDebugFunctionEntry;
97 
98  if ( $wgDebugFunctionEntry ) {
99  $this->debug( str_repeat( ' ', count( $this->mWorkStack ) - 1 ) . 'Exiting ' . $functionname . "\n" );
100  }
101 
102  list( $ofname, /* $ocount */, $ortime, $octime ) = array_pop( $this->mWorkStack );
103 
104  if ( !$ofname ) {
105  $this->debugGroup( 'profileerror', "Profiling error: $functionname" );
106  } else {
107  if ( $functionname == 'close' ) {
108  if ( $ofname != '-total' ) {
109  $message = "Profile section ended by close(): {$ofname}";
110  $this->debugGroup( 'profileerror', $message );
111  $this->mCollated[$message] = $this->errorEntry;
112  }
113  $functionname = $ofname;
114  } elseif ( $ofname != $functionname ) {
115  $message = "Profiling error: in({$ofname}), out($functionname)";
116  $this->debugGroup( 'profileerror', $message );
117  $this->mCollated[$message] = $this->errorEntry;
118  }
119  $elapsedcpu = $this->getTime( 'cpu' ) - $octime;
120  $elapsedreal = $this->getTime() - $ortime;
121  $this->updateEntry( $functionname, $elapsedcpu, $elapsedreal );
122  $this->updateTrxProfiling( $functionname, $elapsedreal );
123  }
124  }
125 
126  public function getRawData() {
127  // Calling the method of the parent class results in fatal error.
128  // @todo Implement this correctly.
129  return array();
130  }
131 
132  public function getFunctionReport() {
133  /* Implement in output subclasses */
134  return '';
135  }
136 
137  public function logData() {
138  /* Implement in subclasses */
139  }
140 }
ProfilerSimple\updateEntry
updateEntry( $name, $elapsedCpu, $elapsedReal)
Definition: ProfilerSimple.php:50
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ProfilerSimple\getZeroEntry
getZeroEntry()
Definition: ProfilerSimple.php:34
Profiler\getInitialTime
getInitialTime( $metric=false)
Get the initial time of the request, based either on $wgRequestTime or $wgRUstart.
Definition: Profiler.php:471
ProfilerSimple\getErrorEntry
getErrorEntry()
Definition: ProfilerSimple.php:44
ProfilerSimple\addInitialStack
addInitialStack()
Add the inital item in the stack.
Definition: ProfilerSimple.php:68
ProfilerSimple\$mMinimumTime
$mMinimumTime
Definition: ProfilerSimple.php:30
Profiler\debug
debug( $s)
Add an entry in the debug log file.
Definition: Profiler.php:752
ProfilerSimple\profileIn
profileIn( $functionname)
Called by wfProfieIn()
Definition: ProfilerSimple.php:87
Profiler
Definition: Profiler.php:97
Profiler\getTime
getTime( $metric=false)
Get the initial time of the request, based either on $wgRequestTime or $wgRUstart.
Definition: Profiler.php:438
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ProfilerSimple\isPersistent
isPersistent()
Return whether this profiler stores data.
Definition: ProfilerSimple.php:63
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
ProfilerSimple\getFunctionReport
getFunctionReport()
Returns a list of profiled functions.
Definition: ProfilerSimple.php:132
ProfilerSimple\setMinimum
setMinimum( $min)
Definition: ProfilerSimple.php:83
ProfilerSimple\getRawData
getRawData()
Definition: ProfilerSimple.php:126
ProfilerSimple\profileOut
profileOut( $functionname)
Called by wfProfieOut()
Definition: ProfilerSimple.php:95
Profiler\updateTrxProfiling
updateTrxProfiling( $method, $realtime)
Register the name and time of a method for slow DB trx detection.
Definition: Profiler.php:283
Profiler\debugGroup
debugGroup( $group, $s)
Add an entry in the debug log group.
Definition: Profiler.php:764
ProfilerSimple
Simple profiler base class.
Definition: ProfilerSimple.php:29
ProfilerSimple\logData
logData()
Log the whole profiling data into the database.
Definition: ProfilerSimple.php:137
ProfilerSimple\$errorEntry
$errorEntry
Definition: ProfilerSimple.php:32