From 691318d0eb414da282d14540cb074be22b91043b Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 3 May 2012 13:02:27 -0700 Subject: [PATCH] Only use per-template profiling for one-time profiling output. Change-Id: Ib89ce14310ccac529684f0ada71f60744319eb3e --- includes/parser/Parser.php | 15 +++++++++------ includes/profiler/Profiler.php | 14 ++++++++++++-- includes/profiler/ProfilerSimple.php | 5 +++++ includes/profiler/ProfilerSimpleTrace.php | 2 +- includes/profiler/ProfilerSimpleUDP.php | 4 ++++ includes/profiler/ProfilerStub.php | 3 +++ 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index d5868a71d0..bd5c202ebe 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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() diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index f2054b51fc..62be39e497 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -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 diff --git a/includes/profiler/ProfilerSimple.php b/includes/profiler/ProfilerSimple.php index 82197fd4df..d1d1c5d901 100644 --- a/includes/profiler/ProfilerSimple.php +++ b/includes/profiler/ProfilerSimple.php @@ -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; diff --git a/includes/profiler/ProfilerSimpleTrace.php b/includes/profiler/ProfilerSimpleTrace.php index f14139e560..822e9fe4fd 100644 --- a/includes/profiler/ProfilerSimpleTrace.php +++ b/includes/profiler/ProfilerSimpleTrace.php @@ -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(); diff --git a/includes/profiler/ProfilerSimpleUDP.php b/includes/profiler/ProfilerSimpleUDP.php index 0de3a85b7c..a95ccb0d2c 100644 --- a/includes/profiler/ProfilerSimpleUDP.php +++ b/includes/profiler/ProfilerSimpleUDP.php @@ -27,6 +27,10 @@ * @ingroup Profiler */ class ProfilerSimpleUDP extends ProfilerSimple { + public function isPersistent() { + return true; + } + public function logData() { global $wgUDPProfilerHost, $wgUDPProfilerPort; diff --git a/includes/profiler/ProfilerStub.php b/includes/profiler/ProfilerStub.php index a498860e2f..c0eb0fb440 100644 --- a/includes/profiler/ProfilerStub.php +++ b/includes/profiler/ProfilerStub.php @@ -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() {} -- 2.20.1