Scripts and data used for generating ZhConversion.php
[lhc/web/wiklou.git] / includes / Profiling.php
index a07adac..cf0cc42 100755 (executable)
@@ -1,13 +1,21 @@
 <?php
-# This file is only included if profiling is enabled
-function wfProfileIn( $functionname )
-{
+/**
+ * This file is only included if profiling is enabled
+ * @package MediaWiki
+ */
+
+/**
+ * @param $functioname name of the function we will profile
+ */
+function wfProfileIn( $functionname ) {
        global $wgProfiler;
        $wgProfiler->profileIn( $functionname );
 }
 
-function wfProfileOut( $functionname = 'missing' ) 
-{
+/**
+ * @param $functioname name of the function we have profiled
+ */
+function wfProfileOut( $functionname = 'missing' ) {
        global $wgProfiler;
        $wgProfiler->profileOut( $functionname );
 }
@@ -17,8 +25,7 @@ function wfGetProfilingOutput( $start, $elapsed ) {
        return $wgProfiler->getOutput( $start, $elapsed );
 }
 
-function wfProfileClose()
-{
+function wfProfileClose() {
        global $wgProfiler;
        $wgProfiler->close();
 }
@@ -30,6 +37,10 @@ if( !function_exists( 'memory_get_usage' ) ) {
        }
 }
 
+/**
+ * @todo document
+ * @package MediaWiki
+ */
 class Profiler
 {
        var $mStack = array(), $mWorkStack = array(), $mCollated = array();
@@ -43,8 +54,7 @@ class Profiler
        }
        */
        
-       function profileIn( $functionname )
-       {
+       function profileIn( $functionname ) {
                global $wgDebugFunctionEntry;
                if ( $wgDebugFunctionEntry && function_exists( 'wfDebug' ) ) {
                        wfDebug( str_repeat( ' ', count( $this->mWorkStack ) ) . 'Entering '.$functionname."\n" );
@@ -52,13 +62,12 @@ class Profiler
                array_push( $this->mWorkStack, array($functionname, count( $this->mWorkStack ), microtime(), memory_get_usage() ) );
        }
 
-       function profileOut( $functionname )
-       {
+       function profileOut( $functionname ) {
                $memory = memory_get_usage();
                global $wgDebugProfiling, $wgDebugFunctionEntry;
 
                if ( $wgDebugFunctionEntry && function_exists( 'wfDebug' ) ) {
-                       wfDebug( str_repeat( ' ', count( $this->mWorkStack ) - 1 ) . 'Exiting '.$functionname."\n" );
+                       wfDebug( str_repeat( ' ', count( $this->mWorkStack ) ) . 'Exiting '.$functionname."\n" );
                }
                
                $bit = array_pop( $this->mWorkStack );
@@ -79,15 +88,13 @@ class Profiler
                }
        }
        
-       function close() 
-       {
+       function close() {
                while ( count( $this->mWorkStack ) ) {
                        $this->profileOut( 'close' );
                }
        }
 
-       function getOutput()
-       {
+       function getOutput() {
                global $wgDebugFunctionEntry;
                $wgDebugFunctionEntry = false;
 
@@ -165,23 +172,28 @@ class Profiler
        }
 
 
-       /* static */ function logToDB($name, $timeSum, $eventCount) 
-       {
+       /**
+        * @static
+        */
+       function logToDB($name, $timeSum, $eventCount) {
                $dbw =& wfGetDB( DB_MASTER );
                $profiling = $dbw->tableName( 'profiling' );
 
-               $name = $dbw->strencode( $name );
+               $name = substr($name,0,255);
+               $encname = $dbw->strencode($name);
                $sql = "UPDATE $profiling ".
                        "SET pf_count=pf_count+{$eventCount}, ".
                        "pf_time=pf_time + {$timeSum} ".
-                       "WHERE pf_name='{$name}'";
+                       "WHERE pf_name='{$encname}'";
                $dbw->query($sql);
 
                $rc = $dbw->affectedRows();     
                if( $rc == 0) {
-                       $sql = "INSERT IGNORE INTO $profiling (pf_name,pf_count,pf_time) ".
-                               "VALUES ('{$name}', {$eventCount}, {$timeSum}) ";
-                       $dbw->query($sql , DB_MASTER);
+                       $dbw->insertArray($profiling,array(
+                               'pf_name'=>$name,
+                               'pf_count'=>$eventCount,
+                               'pf_time'=>$timeSum),
+                               $fname,array('IGNORE'));
                }
                // When we upgrade to mysql 4.1, the insert+update
                // can be merged into just a insert with this construct added: