Only use per-template profiling for one-time profiling output.
authorAaron <aschulz@wikimedia.org>
Thu, 3 May 2012 20:02:27 +0000 (13:02 -0700)
committerReedy <reedy@wikimedia.org>
Fri, 4 May 2012 23:34:50 +0000 (00:34 +0100)
Change-Id: Ib89ce14310ccac529684f0ada71f60744319eb3e

includes/parser/Parser.php
includes/profiler/Profiler.php
includes/profiler/ProfilerSimple.php
includes/profiler/ProfilerSimpleTrace.php
includes/profiler/ProfilerSimpleUDP.php
includes/profiler/ProfilerStub.php

index d5868a7..bd5c202 100644 (file)
@@ -724,8 +724,8 @@ class Parser {
        }
 
        /**
-        * Get the target language for the content being parsed. This is usually the 
-        * language that the content is in. 
+        * Get the target language for the content being parsed. This is usually the
+        * language that the content is in.
         */
        function getTargetLanguage() {
                $target = $this->mOptions->getTargetLanguage();
@@ -1271,7 +1271,7 @@ class Parser {
                $text = $this->maybeMakeExternalImage( $url );
                if ( $text === false ) {
                        # Not an image, make a link
-                       $text = Linker::makeExternalLink( $url, 
+                       $text = Linker::makeExternalLink( $url,
                                $this->getConverterLanguage()->markNoConversion($url), true, 'free',
                                $this->getExternalLinkAttribs( $url ) );
                        # Register it in the output object...
@@ -1752,7 +1752,7 @@ class Parser {
                }
 
                if ( $this->getConverterLanguage()->hasVariants() ) {
-                       $selflink = $this->getConverterLanguage()->autoConvertToAllVariants( 
+                       $selflink = $this->getConverterLanguage()->autoConvertToAllVariants(
                                $this->mTitle->getPrefixedText() );
                } else {
                        $selflink = array( $this->mTitle->getPrefixedText() );
@@ -3266,8 +3266,11 @@ class Parser {
 
                # Load from database
                if ( !$found && $title ) {
-                       $titleProfileIn = __METHOD__ . "-title-" . $title->getDBKey();
-                       wfProfileIn( $titleProfileIn ); // template in
+                       if ( !Profiler::instance()->isPersistent() ) {
+                               # Too many unique items can kill profiling DBs/collectors
+                               $titleProfileIn = __METHOD__ . "-title-" . $title->getDBKey();
+                               wfProfileIn( $titleProfileIn ); // template in
+                       }
                        wfProfileIn( __METHOD__ . '-loadtpl' );
                        if ( !$title->isExternal() ) {
                                if ( $title->isSpecialPage()
index f2054b5..62be39e 100644 (file)
@@ -114,6 +114,16 @@ class Profiler {
                return false;
        }
 
+       /**
+        * Return whether this profiler stores data
+        *
+        * @see Profiler::logData()
+        * @return Boolean
+        */
+       public function isPersistent() {
+               return true;
+       }
+
        public function setProfileID( $id ) {
                $this->mProfileID = $id;
        }
@@ -479,7 +489,7 @@ class Profiler {
                }
                wfProfileOut( '-overhead-total' );
        }
-       
+
        /**
         * Counts the number of profiled function calls sitting under
         * the given point in the call graph. Not the most efficient algo.
@@ -549,7 +559,7 @@ class Profiler {
                        $rc = $dbw->affectedRows();
                        if ( $rc == 0 ) {
                                $dbw->insert('profiling', array ('pf_name' => $name, 'pf_count' => $eventCount,
-                                       'pf_time' => $timeSum, 'pf_memory' => $memorySum, 'pf_server' => $pfhost ), 
+                                       'pf_time' => $timeSum, 'pf_memory' => $memorySum, 'pf_server' => $pfhost ),
                                        __METHOD__, array ('IGNORE'));
                        }
                        // When we upgrade to mysql 4.1, the insert+update
index 82197fd..d1d1c5d 100644 (file)
@@ -32,6 +32,11 @@ class ProfilerSimple extends Profiler {
        var $zeroEntry = array('cpu'=> 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0);
        var $errorEntry;
 
+       public function isPersistent() {
+               /* Implement in output subclasses */
+               return false;
+       }
+
        protected function addInitialStack() {
                $this->errorEntry = $this->zeroEntry;
                $this->errorEntry['count'] = 1;
index f14139e..822e9fe 100644 (file)
@@ -61,7 +61,7 @@ class ProfilerSimpleTrace extends ProfilerSimple {
                                        str_repeat(" ", count( $this->mWorkStack ) + 1 ) . " < " . $functionname . "\n";
                }
        }
-       
+
        function memoryDiff() {
                $diff = memory_get_usage() - $this->memory;
                $this->memory = memory_get_usage();
index 0de3a85..a95ccb0 100644 (file)
  * @ingroup Profiler
  */
 class ProfilerSimpleUDP extends ProfilerSimple {
+       public function isPersistent() {
+               return true;
+       }
+
        public function logData() {
                global $wgUDPProfilerHost, $wgUDPProfilerPort;
 
index a498860..c0eb0fb 100644 (file)
@@ -30,6 +30,9 @@ class ProfilerStub extends Profiler {
        public function isStub() {
                return true;
        }
+       public function isPersistent() {
+               return false;
+       }
        public function profileIn( $fn ) {}
        public function profileOut( $fn ) {}
        public function getOutput() {}