From 380b075756a15f82a158be5c3a4283188208c820 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 2 May 2014 11:13:26 -0700 Subject: [PATCH] Added a script to compare current parser output to cache * This works on a random set of pages in a namespace and can be used to compare different PHP interpreters. * This can, like any maintenance script, be used with --profiler. Change-Id: Ica69a3ef27df29af1c6e4dc4c8413b55a03df49e --- maintenance/compareParserCache.php | 101 +++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 maintenance/compareParserCache.php diff --git a/maintenance/compareParserCache.php b/maintenance/compareParserCache.php new file mode 100644 index 0000000000..97fd3ffcc9 --- /dev/null +++ b/maintenance/compareParserCache.php @@ -0,0 +1,101 @@ +mDescription = "Parse random pages and compare output to cache."; + $this->addOption( 'namespace', 'Page namespace number', true, true ); + $this->addOption( 'maxpages', 'Number of pages to try', true, true ); + } + + public function execute() { + $pages = $this->getOption( 'maxpages' ); + + $dbr = $this->getDB( DB_SLAVE ); + + $totalsec = 0.0; + $scanned = 0; + $withcache = 0; + while ( $pages-- > 0 ) { + $row = $dbr->selectRow( 'page', '*', + array( + 'page_namespace' => $this->getOption( 'namespace' ), + 'page_is_redirect' => 0, + 'page_random >= ' . wfRandom() + ), + __METHOD__, + array( + 'ORDER BY' => 'page_random', + ) + ); + + if ( !$row ) { + continue; + } + ++$scanned; + + $title = Title::newFromRow( $row ); + $page = WikiPage::factory( $title ); + $revision = $page->getRevision(); + $content = $revision->getContent( Revision::RAW ); + + $parserOptions = $page->makeParserOptions( 'canonical' ); + + $parserOutputOld = ParserCache::singleton()->get( $page, $parserOptions ); + + $t1 = microtime( true ); + $parserOutputNew = $content->getParserOutput( + $title, $revision->getId(), $parserOptions, false ); + $sec = microtime( true ) - $t1; + $totalsec += $sec; + + $this->output( "Parsed '{$title->getPrefixedText()}' in $sec seconds.\n" ); + + if ( $parserOutputOld ) { + $this->output( "Found cache entry found for '{$title->getPrefixedText()}'..." ); + $oldHtml = trim( preg_replace( '##Us', '', $parserOutputOld->getText() ) ); + $newHtml = trim( preg_replace( '##Us', '',$parserOutputNew->getText() ) ); + $diff = wfDiff( $oldHtml, $newHtml ); + if ( strlen( $diff ) ) { + $this->output( "differences found:\n\n$diff\n\n" ); + } else { + $this->output( "No differences found.\n" ); + } + ++$withcache; + } else { + $this->output( "No parser cache entry found for '{$title->getPrefixedText()}'.\n" ); + } + } + + $ave = $scanned ? $totalsec / $scanned : 0; + $this->output( "Checked $scanned pages; $withcache had prior cache entries.\n" ); + $this->output( "Average parse time: $ave sec\n" ); + } +} + +$maintClass = "CompareParserCache"; +require_once RUN_MAINTENANCE_IF_MAIN; -- 2.20.1