2006-01-07 13:09:30 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Profiler
|
|
|
|
|
*/
|
2006-01-03 10:31:13 +00:00
|
|
|
|
2007-03-28 14:16:43 +00:00
|
|
|
require_once(dirname(__FILE__).'/Profiler.php');
|
|
|
|
|
|
2007-04-04 05:22:37 +00:00
|
|
|
/**
|
|
|
|
|
* Simple profiler base class.
|
|
|
|
|
* @todo document methods (?)
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Profiler
|
2007-04-04 05:22:37 +00:00
|
|
|
*/
|
2005-12-24 13:41:05 +00:00
|
|
|
class ProfilerSimple extends Profiler {
|
2006-10-02 17:04:13 +00:00
|
|
|
var $mMinimumTime = 0;
|
2006-11-18 05:17:25 +00:00
|
|
|
var $mProfileID = false;
|
2006-10-02 17:04:13 +00:00
|
|
|
|
2007-01-20 13:34:31 +00:00
|
|
|
function __construct() {
|
2008-05-06 16:03:03 +00:00
|
|
|
global $wgRequestTime, $wgRUstart;
|
2008-01-26 01:49:17 +00:00
|
|
|
if (!empty($wgRequestTime) && !empty($wgRUstart)) {
|
|
|
|
|
$this->mWorkStack[] = array( '-total', 0, $wgRequestTime,$this->getCpuTime($wgRUstart));
|
2005-12-30 23:16:14 +00:00
|
|
|
|
2008-01-26 01:49:17 +00:00
|
|
|
$elapsedcpu = $this->getCpuTime() - $this->getCpuTime($wgRUstart);
|
2006-06-07 20:13:29 +00:00
|
|
|
$elapsedreal = microtime(true) - $wgRequestTime;
|
2005-12-30 23:16:14 +00:00
|
|
|
|
|
|
|
|
$entry =& $this->mCollated["-setup"];
|
2006-06-07 20:13:29 +00:00
|
|
|
if (!is_array($entry)) {
|
2008-01-26 01:49:17 +00:00
|
|
|
$entry = array('cpu'=> 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0);
|
2006-11-29 12:32:43 +00:00
|
|
|
$this->mCollated["-setup"] =& $entry;
|
2006-06-07 20:13:29 +00:00
|
|
|
}
|
2008-01-26 01:49:17 +00:00
|
|
|
$entry['cpu'] += $elapsedcpu;
|
|
|
|
|
$entry['cpu_sq'] += $elapsedcpu*$elapsedcpu;
|
2005-12-30 23:16:14 +00:00
|
|
|
$entry['real'] += $elapsedreal;
|
2008-01-26 01:49:17 +00:00
|
|
|
$entry['real_sq'] += $elapsedreal*$elapsedreal;
|
2005-12-30 23:16:14 +00:00
|
|
|
$entry['count']++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-02 17:04:13 +00:00
|
|
|
function setMinimum( $min ) {
|
|
|
|
|
$this->mMinimumTime = $min;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-18 05:17:25 +00:00
|
|
|
function setProfileID( $id ) {
|
|
|
|
|
$this->mProfileID = $id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getProfileID() {
|
|
|
|
|
if ( $this->mProfileID === false ) {
|
|
|
|
|
return wfWikiID();
|
|
|
|
|
} else {
|
|
|
|
|
return $this->mProfileID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-24 13:41:05 +00:00
|
|
|
function profileIn($functionname) {
|
|
|
|
|
global $wgDebugFunctionEntry;
|
2006-01-04 23:21:21 +00:00
|
|
|
if ($wgDebugFunctionEntry) {
|
|
|
|
|
$this->debug(str_repeat(' ', count($this->mWorkStack)).'Entering '.$functionname."\n");
|
2005-12-24 13:41:05 +00:00
|
|
|
}
|
2008-01-26 01:49:17 +00:00
|
|
|
$this->mWorkStack[] = array($functionname, count( $this->mWorkStack ), microtime(true), $this->getCpuTime());
|
2005-12-24 13:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function profileOut($functionname) {
|
|
|
|
|
global $wgDebugFunctionEntry;
|
|
|
|
|
|
2006-01-04 23:21:21 +00:00
|
|
|
if ($wgDebugFunctionEntry) {
|
|
|
|
|
$this->debug(str_repeat(' ', count($this->mWorkStack) - 1).'Exiting '.$functionname."\n");
|
2005-12-24 13:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-26 01:49:17 +00:00
|
|
|
list($ofname, /* $ocount */ ,$ortime,$octime) = array_pop($this->mWorkStack);
|
2005-12-24 13:41:05 +00:00
|
|
|
|
|
|
|
|
if (!$ofname) {
|
2006-01-04 23:21:21 +00:00
|
|
|
$this->debug("Profiling error: $functionname\n");
|
2005-12-24 13:41:05 +00:00
|
|
|
} else {
|
|
|
|
|
if ($functionname == 'close') {
|
|
|
|
|
$message = "Profile section ended by close(): {$ofname}";
|
2005-12-30 23:16:14 +00:00
|
|
|
$functionname = $ofname;
|
2006-01-04 23:21:21 +00:00
|
|
|
$this->debug( "$message\n" );
|
2008-01-12 17:51:21 +00:00
|
|
|
$this->mCollated[$message] = array(
|
|
|
|
|
'real' => 0.0, 'count' => 1);
|
2005-12-24 13:41:05 +00:00
|
|
|
}
|
|
|
|
|
elseif ($ofname != $functionname) {
|
|
|
|
|
$message = "Profiling error: in({$ofname}), out($functionname)";
|
2006-01-04 23:21:21 +00:00
|
|
|
$this->debug( "$message\n" );
|
2008-01-12 17:51:21 +00:00
|
|
|
$this->mCollated[$message] = array(
|
|
|
|
|
'real' => 0.0, 'count' => 1);
|
2005-12-24 13:41:05 +00:00
|
|
|
}
|
|
|
|
|
$entry =& $this->mCollated[$functionname];
|
2008-01-26 01:49:17 +00:00
|
|
|
$elapsedcpu = $this->getCpuTime() - $octime;
|
2006-06-07 20:13:29 +00:00
|
|
|
$elapsedreal = microtime(true) - $ortime;
|
|
|
|
|
if (!is_array($entry)) {
|
2008-01-26 01:49:17 +00:00
|
|
|
$entry = array('cpu'=> 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0);
|
2006-06-07 20:13:29 +00:00
|
|
|
$this->mCollated[$functionname] =& $entry;
|
|
|
|
|
}
|
2008-01-26 01:49:17 +00:00
|
|
|
$entry['cpu'] += $elapsedcpu;
|
|
|
|
|
$entry['cpu_sq'] += $elapsedcpu*$elapsedcpu;
|
2005-12-24 13:41:05 +00:00
|
|
|
$entry['real'] += $elapsedreal;
|
2008-01-26 01:49:17 +00:00
|
|
|
$entry['real_sq'] += $elapsedreal*$elapsedreal;
|
2005-12-24 13:41:05 +00:00
|
|
|
$entry['count']++;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-24 13:41:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-07 13:31:29 +00:00
|
|
|
function getFunctionReport() {
|
2005-12-24 13:41:05 +00:00
|
|
|
/* Implement in output subclasses */
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-26 01:49:17 +00:00
|
|
|
function getCpuTime($ru=null) {
|
|
|
|
|
if ( function_exists( 'getrusage' ) ) {
|
|
|
|
|
if ( $ru == null )
|
|
|
|
|
$ru = getrusage();
|
2008-04-14 07:45:50 +00:00
|
|
|
return ($ru['ru_utime.tv_sec'] + $ru['ru_stime.tv_sec'] + ($ru['ru_utime.tv_usec'] +
|
2008-01-26 01:49:17 +00:00
|
|
|
$ru['ru_stime.tv_usec']) * 1e-6);
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-07 20:13:29 +00:00
|
|
|
/* If argument is passed, it assumes that it is dual-format time string, returns proper float time value */
|
2005-12-30 23:16:14 +00:00
|
|
|
function getTime($time=null) {
|
|
|
|
|
if ($time==null)
|
2006-06-07 20:13:29 +00:00
|
|
|
return microtime(true);
|
2005-12-30 23:16:14 +00:00
|
|
|
list($a,$b)=explode(" ",$time);
|
2005-12-24 13:41:05 +00:00
|
|
|
return (float)($a+$b);
|
|
|
|
|
}
|
|
|
|
|
}
|