*
* - Parser::parse()
* produces HTML output
- * - Parser::preSaveTransform().
- * produces altered wiki markup.
+ * - Parser::preSaveTransform()
+ * produces altered wiki markup
* - Parser::preprocess()
* removes HTML comments and expands templates
* - Parser::cleanSig() and Parser::cleanSigInSig()
- * Cleans a signature before saving it to preferences
+ * cleans a signature before saving it to preferences
* - Parser::getSection()
- * Return the content of a section from an article for section editing
+ * return the content of a section from an article for section editing
* - Parser::replaceSection()
- * Replaces a section by number inside an article
+ * replaces a section by number inside an article
* - Parser::getPreloadText()
- * Removes <noinclude> sections, and <includeonly> tags.
+ * removes <noinclude> sections and <includeonly> tags
*
* Globals used:
* object: $wgContLang
*/
public $mInParse = false;
+ /** @var SectionProfiler */
+ protected $mProfiler;
+
/**
* @param array $conf
*/
$this->mPreprocessor = null;
}
+ $this->mProfiler = new SectionProfiler();
+
wfRunHooks( 'ParserClearState', array( &$this ) );
wfProfileOut( __METHOD__ );
}
$limitReport = str_replace( array( '-', '&' ), array( '‐', '&' ), $limitReport );
$text .= "\n<!-- \n$limitReport-->\n";
+ // Add on template profiling data
+ $dataByFunc = $this->mProfiler->getFunctionStats();
+ uasort( $dataByFunc, function( $a, $b ) {
+ return $a['elapsed'] < $b['elapsed']; // descending order
+ } );
+ $profileReport = "Top template expansion time report (%,ms,calls,template)\n";
+ foreach ( array_slice( $dataByFunc, 0, 10 ) as $item ) {
+ $profileReport .= sprintf( "%6.2f%% %3.6f %6d - %s\n",
+ $item['percent'], $item['elapsed'], $item['calls'],
+ htmlspecialchars($item['name'] ) );
+ }
+ $text .= "\n<!-- \n$profileReport-->\n";
+
if ( $this->mGeneratedPPNodeCount > $this->mOptions->getMaxGeneratedPPNodeCount() / 10 ) {
wfDebugLog( 'generated-pp-node-count', $this->mGeneratedPPNodeCount . ' ' .
$this->mTitle->getPrefixedDBkey() );
$args = ( null == $piece['parts'] ) ? array() : $piece['parts'];
wfProfileOut( __METHOD__ . '-setup' );
- $titleProfileIn = null; // profile templates
+ $profileSection = null; // profile templates
# SUBST
wfProfileIn( __METHOD__ . '-modifiers' );
# Load from database
if ( !$found && $title ) {
- if ( !Profiler::instance()->isPersistent() ) {
- # Too many unique items can kill profiling DBs/collectors
- $titleProfileIn = __METHOD__ . "-title-" . $title->getPrefixedDBkey();
- wfProfileIn( $titleProfileIn ); // template in
- }
+ $profileSection = $this->mProfiler->scopedProfileIn( $title->getPrefixedDBkey() );
wfProfileIn( __METHOD__ . '-loadtpl' );
if ( !$title->isExternal() ) {
if ( $title->isSpecialPage()
# Recover the source wikitext and return it
if ( !$found ) {
$text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args );
- if ( $titleProfileIn ) {
- wfProfileOut( $titleProfileIn ); // template out
+ if ( $profileSection ) {
+ $this->mProfiler->scopedProfileOut( $profileSection );
}
wfProfileOut( __METHOD__ );
return array( 'object' => $text );
$isLocalObj = false;
}
- if ( $titleProfileIn ) {
- wfProfileOut( $titleProfileIn ); // template out
+ if ( $profileSection ) {
+ $this->mProfiler->scopedProfileOut( $profileSection );
}
# Replace raw HTML by a placeholder
/**
* Transform wiki markup when saving a page by doing "\r\n" -> "\n"
- * conversion, substitting signatures, {{subst:}} templates, etc.
+ * conversion, substituting signatures, {{subst:}} templates, etc.
*
* @param string $text The text to transform
* @param Title $title The Title object for the current article
*
* @param string $text
* @param int $options
- *
- * @return array Array of link CSS classes, indexed by PDBK.
*/
public function replaceLinkHolders( &$text, $options = 0 ) {
- return $this->mLinkHolders->replace( $text );
+ $this->mLinkHolders->replace( $text );
}
/**