diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2012-05-03 13:01:35 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2012-05-03 13:01:35 +0200 |
commit | d9022f63880ce039446fba8364f68e656b7bf4cb (patch) | |
tree | 16b40fbf17bf7c9ee6f4ead25b16dd192378050a /includes/profiler | |
parent | 27cf83d177256813e2e802241085fce5dd0f3fb9 (diff) |
Update to MediaWiki 1.19.0
Diffstat (limited to 'includes/profiler')
-rw-r--r-- | includes/profiler/Profiler.php | 67 | ||||
-rw-r--r-- | includes/profiler/ProfilerSimple.php | 9 | ||||
-rw-r--r-- | includes/profiler/ProfilerSimpleText.php | 1 | ||||
-rw-r--r-- | includes/profiler/ProfilerSimpleTrace.php | 3 | ||||
-rw-r--r-- | includes/profiler/ProfilerSimpleUDP.php | 38 | ||||
-rw-r--r-- | includes/profiler/ProfilerStub.php | 2 |
6 files changed, 76 insertions, 44 deletions
diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 93b03f59..0fe18c25 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -34,26 +34,28 @@ function wfProfileOut( $functionname = 'missing' ) { * @todo document */ class Profiler { - var $mStack = array (), $mWorkStack = array (), $mCollated = array (); - var $mCalls = array (), $mTotals = array (); - var $mTemplated = false; - var $mTimeMetric = 'wall'; - private $mCollateDone = false; - protected $mProfileID = false; + protected $mStack = array(), $mWorkStack = array (), $mCollated = array (), + $mCalls = array (), $mTotals = array (); + protected $mTimeMetric = 'wall'; + protected $mProfileID = false, $mCollateDone = false, $mTemplated = false; private static $__instance = null; function __construct( $params ) { + if ( isset( $params['timeMetric'] ) ) { + $this->mTimeMetric = $params['timeMetric']; + } + if ( isset( $params['profileID'] ) ) { + $this->mProfileID = $params['profileID']; + } + // Push an entry for the pre-profile setup time onto the stack - global $wgRequestTime; - if ( !empty( $wgRequestTime ) ) { - $this->mWorkStack[] = array( '-total', 0, $wgRequestTime, 0 ); - $this->mStack[] = array( '-setup', 1, $wgRequestTime, 0, microtime(true), 0 ); + $initial = $this->getInitialTime(); + if ( $initial !== null ) { + $this->mWorkStack[] = array( '-total', 0, $initial, 0 ); + $this->mStack[] = array( '-setup', 1, $initial, 0, $this->getTime(), 0 ); } else { $this->profileIn( '-total' ); } - if ( isset( $params['timeMetric'] ) ) { - $this->mTimeMetric = $params['timeMetric']; - } } /** @@ -64,11 +66,19 @@ class Profiler { if( is_null( self::$__instance ) ) { global $wgProfiler; if( is_array( $wgProfiler ) ) { - $class = isset( $wgProfiler['class'] ) ? $wgProfiler['class'] : 'ProfilerStub'; + if( !isset( $wgProfiler['class'] ) ) { + wfDebug( __METHOD__ . " called without \$wgProfiler['class']" + . " set, falling back to ProfilerStub for safety\n" ); + $class = 'ProfilerStub'; + } else { + $class = $wgProfiler['class']; + } self::$__instance = new $class( $wgProfiler ); } elseif( $wgProfiler instanceof Profiler ) { self::$__instance = $wgProfiler; // back-compat } else { + wfDebug( __METHOD__ . ' called with bogus $wgProfiler setting,' + . " falling back to ProfilerStub for safety\n" ); self::$__instance = new ProfilerStub( $wgProfiler ); } } @@ -141,12 +151,12 @@ class Profiler { if( $functionname == 'close' ){ $message = "Profile section ended by close(): {$bit[0]}"; $this->debug( "$message\n" ); - $this->mStack[] = array( $message, 0, '0 0', 0, '0 0', 0 ); + $this->mStack[] = array( $message, 0, 0.0, 0, 0.0, 0 ); } elseif( $bit[0] != $functionname ){ $message = "Profiling error: in({$bit[0]}), out($functionname)"; $this->debug( "$message\n" ); - $this->mStack[] = array( $message, 0, '0 0', 0, '0 0', 0 ); + $this->mStack[] = array( $message, 0, 0.0, 0, 0.0, 0 ); } //} $bit[] = $time; @@ -256,13 +266,31 @@ class Profiler { if ( $this->mTimeMetric === 'user' ) { return $this->getUserTime(); } else { - return microtime(true); + return microtime( true ); } } function getUserTime() { $ru = getrusage(); - return $ru['ru_utime.tv_sec'].' '.$ru['ru_utime.tv_usec'] / 1e6; + return $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6; + } + + private function getInitialTime() { + global $wgRequestTime, $wgRUstart; + + if ( $this->mTimeMetric === 'user' ) { + if ( count( $wgRUstart ) ) { + return $wgRUstart['ru_utime.tv_sec'] + $wgRUstart['ru_utime.tv_usec'] / 1e6; + } else { + return null; + } + } else { + if ( empty( $wgRequestTime ) ) { + return null; + } else { + return $wgRequestTime; + } + } } protected function collateData() { @@ -344,7 +372,8 @@ class Profiler { /** * Returns a list of profiled functions. - * Also log it into the database if $wgProfileToDatabase is set to true. + * + * @return string */ function getFunctionReport() { $this->collateData(); diff --git a/includes/profiler/ProfilerSimple.php b/includes/profiler/ProfilerSimple.php index bbdbec8e..055a0ea0 100644 --- a/includes/profiler/ProfilerSimple.php +++ b/includes/profiler/ProfilerSimple.php @@ -115,13 +115,4 @@ class ProfilerSimple extends Profiler { return 0; } } - - /* If argument is passed, it assumes that it is dual-format time string, returns proper float time value */ - function getTime($time=null) { - if ($time==null) { - return microtime(true); - } - list($a,$b)=explode(" ",$time); - return (float)($a+$b); - } } diff --git a/includes/profiler/ProfilerSimpleText.php b/includes/profiler/ProfilerSimpleText.php index ef9049fa..3621a41f 100644 --- a/includes/profiler/ProfilerSimpleText.php +++ b/includes/profiler/ProfilerSimpleText.php @@ -41,7 +41,6 @@ class ProfilerSimpleText extends ProfilerSimple { } } - /* dense is good */ static function sort( $a, $b ) { return $a['real'] < $b['real']; /* sort descending by time elapsed */ } diff --git a/includes/profiler/ProfilerSimpleTrace.php b/includes/profiler/ProfilerSimpleTrace.php index ba41babc..784609f5 100644 --- a/includes/profiler/ProfilerSimpleTrace.php +++ b/includes/profiler/ProfilerSimpleTrace.php @@ -10,7 +10,6 @@ * @ingroup Profiler */ class ProfilerSimpleTrace extends ProfilerSimple { - var $mMinimumTime = 0; var $trace = ""; var $memory = 0; @@ -36,7 +35,7 @@ class ProfilerSimpleTrace extends ProfilerSimple { $this->debug(str_repeat(' ', count($this->mWorkStack) - 1).'Exiting '.$functionname."\n"); } - list( $ofname, /* $ocount */ , $ortime, $octime ) = array_pop( $this->mWorkStack ); + list( $ofname, /* $ocount */ , $ortime ) = array_pop( $this->mWorkStack ); if ( !$ofname ) { $this->trace .= "Profiling error: $functionname\n"; diff --git a/includes/profiler/ProfilerSimpleUDP.php b/includes/profiler/ProfilerSimpleUDP.php index ed49d5a2..ae607aa6 100644 --- a/includes/profiler/ProfilerSimpleUDP.php +++ b/includes/profiler/ProfilerSimpleUDP.php @@ -20,22 +20,34 @@ class ProfilerSimpleUDP extends ProfilerSimple { return; } + if ( !MWInit::functionExists( 'socket_create' ) ) { + # Sockets are not enabled + return; + } + $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); - $plength=0; - $packet=""; - foreach ($this->mCollated as $entry=>$pfdata) { - $pfline=sprintf ("%s %s %d %f %f %f %f %s\n", $this->getProfileID(),"-",$pfdata['count'], - $pfdata['cpu'],$pfdata['cpu_sq'],$pfdata['real'],$pfdata['real_sq'],$entry); - $length=strlen($pfline); + $plength = 0; + $packet = ""; + foreach ( $this->mCollated as $entry => $pfdata ) { + if( !isset($pfdata['count']) + || !isset( $pfdata['cpu'] ) + || !isset( $pfdata['cpu_sq'] ) + || !isset( $pfdata['real'] ) + || !isset( $pfdata['real_sq'] ) ) { + continue; + } + $pfline = sprintf( "%s %s %d %f %f %f %f %s\n", $this->getProfileID(), "-", $pfdata['count'], + $pfdata['cpu'], $pfdata['cpu_sq'], $pfdata['real'], $pfdata['real_sq'], $entry); + $length = strlen( $pfline ); /* printf("<!-- $pfline -->"); */ - if ($length+$plength>1400) { - socket_sendto($sock,$packet,$plength,0,$wgUDPProfilerHost,$wgUDPProfilerPort); - $packet=""; - $plength=0; + if ( $length + $plength > 1400 ) { + socket_sendto( $sock, $packet, $plength, 0, $wgUDPProfilerHost, $wgUDPProfilerPort ); + $packet = ""; + $plength = 0; } - $packet.=$pfline; - $plength+=$length; + $packet .= $pfline; + $plength += $length; } - socket_sendto($sock,$packet,$plength,0x100,$wgUDPProfilerHost,$wgUDPProfilerPort); + socket_sendto( $sock, $packet, $plength, 0x100, $wgUDPProfilerHost, $wgUDPProfilerPort ); } } diff --git a/includes/profiler/ProfilerStub.php b/includes/profiler/ProfilerStub.php index 58c1975c..1a0933c4 100644 --- a/includes/profiler/ProfilerStub.php +++ b/includes/profiler/ProfilerStub.php @@ -12,4 +12,6 @@ class ProfilerStub extends Profiler { public function profileOut( $fn ) {} public function getOutput() {} public function close() {} + public function logData() {} + public function getCurrentSection() { return ''; } } |