mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-23 23:25:02 +00:00
Add profiling
Change-Id: I9066f6b2606044412a9b91ca395e841550d7e787
This commit is contained in:
parent
ba36f4a462
commit
4d68c31de1
|
@ -46,6 +46,7 @@ class MathHooks {
|
|||
if ( trim( $content ) === "" ) { // bug 8372
|
||||
return "";
|
||||
}
|
||||
wfProfileIn( __METHOD__ );
|
||||
$mode = $parser->getOptions()->getMath();
|
||||
$renderer = MathRenderer::getRenderer(
|
||||
$content, $attributes, $mode
|
||||
|
@ -55,7 +56,9 @@ class MathHooks {
|
|||
$parser->getOutput()->addModules( array( 'ext.math.mathjax.enabler' ) );
|
||||
}
|
||||
$renderer->writeCache();
|
||||
return $wgContLang->armourMath( $renderedMath );
|
||||
$result = $wgContLang->armourMath( $renderedMath );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,16 +63,20 @@ class MathLaTeXML extends MathRenderer {
|
|||
* @see MathRenderer::render()
|
||||
*/
|
||||
public function render( $forceReRendering = false ) {
|
||||
wfProfileIn( __METHOD__ );
|
||||
if ( $forceReRendering ) {
|
||||
$this->setPurge( true );
|
||||
}
|
||||
if ( $this->renderingRequired() ) {
|
||||
$res = $this->doRender( );
|
||||
if ( ! $res ) {
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $this->getLastError();
|
||||
}
|
||||
}
|
||||
return $this->getMathMLTag();
|
||||
$result = $this->getMathMLTag();
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,6 +119,8 @@ class MathLaTeXML extends MathRenderer {
|
|||
*/
|
||||
public function makeRequest( $host, $post, &$res, &$error = '', $httpRequestClass = 'MWHttpRequest' ) {
|
||||
global $wgLaTeXMLTimeout;
|
||||
|
||||
wfProfileIn( __METHOD__ );
|
||||
$error = '';
|
||||
$res = null;
|
||||
$options = array( 'method' => 'POST', 'postData' => $post, 'timeout' => $wgLaTeXMLTimeout );
|
||||
|
@ -122,6 +128,7 @@ class MathLaTeXML extends MathRenderer {
|
|||
$status = $req->execute();
|
||||
if ( $status->isGood() ) {
|
||||
$res = $req->getContent();
|
||||
wfProfileOut( __METHOD__ );
|
||||
return true;
|
||||
} else {
|
||||
if ( $status->hasMessage( 'http-timed-out' ) ) {
|
||||
|
@ -138,6 +145,7 @@ class MathLaTeXML extends MathRenderer {
|
|||
. var_export( array( 'post' => $post, 'host' => $host
|
||||
, 'errormsg' => $errormsg ), true ) . "\n\n" );
|
||||
}
|
||||
wfProfileOut( __METHOD__ );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -183,6 +191,7 @@ class MathLaTeXML extends MathRenderer {
|
|||
* @return boolean
|
||||
*/
|
||||
private function doRender( ) {
|
||||
wfProfileIn( __METHOD__ );
|
||||
$host = self::pickHost();
|
||||
$post = $this->getPostData();
|
||||
$this->lastError = '';
|
||||
|
@ -191,6 +200,7 @@ class MathLaTeXML extends MathRenderer {
|
|||
if ( json_last_error() === JSON_ERROR_NONE ) {
|
||||
if ( self::isValidMathML( $result->result ) ) {
|
||||
$this->setMathml( $result->result );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return true;
|
||||
} else {
|
||||
// Do not print bad mathml. It's probably too verbose and might
|
||||
|
@ -199,6 +209,7 @@ class MathLaTeXML extends MathRenderer {
|
|||
wfDebugLog( "Math", "\nLaTeXML InvalidMathML:"
|
||||
. var_export( array( 'post' => $post, 'host' => $host
|
||||
, 'result' => $result ), true ) . "\n\n" );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@ -206,10 +217,12 @@ class MathLaTeXML extends MathRenderer {
|
|||
wfDebugLog( "Math", "\nLaTeXML InvalidJSON:"
|
||||
. var_export( array( 'post' => $post, 'host' => $host
|
||||
, 'res' => $res ), true ) . "\n\n" );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Error message has already been set.
|
||||
wfProfileOut( __METHOD__ );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,6 +140,7 @@ abstract class MathRenderer {
|
|||
* @return boolean true if read successfully, false otherwise
|
||||
*/
|
||||
public function readFromDatabase() {
|
||||
wfProfileIn( __METHOD__ );
|
||||
$dbr = wfGetDB( DB_SLAVE );
|
||||
$rpage = $dbr->selectRow( 'math', $this->dbInArray(),
|
||||
array( 'math_inputhash' => $this->getInputHash() ), __METHOD__ );
|
||||
|
@ -151,15 +152,18 @@ abstract class MathRenderer {
|
|||
wfDebugLog( 'Math', $msg );
|
||||
// If we can not check if mathml output is valid, we skip the test and assume that it is valid.
|
||||
$this->recall = true;
|
||||
wfProfileOut( __METHOD__ );
|
||||
return true;
|
||||
} elseif ( StringUtils::isUtf8( $this->mathml ) ) {
|
||||
$this->recall = true;
|
||||
wfProfileOut( __METHOD__ );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
# Missing from the database and/or the render cache
|
||||
$this->recall = false;
|
||||
wfProfileOut( __METHOD__ );
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -127,9 +127,12 @@ class MathTexvc extends MathRenderer {
|
|||
*/
|
||||
public function callTexvc() {
|
||||
global $wgTexvc, $wgTexvcBackgroundColor, $wgUseSquid, $wgMathCheckFiles;
|
||||
|
||||
wfProfileIn( __METHOD__ );
|
||||
$tmpDir = wfTempDir();
|
||||
if ( !is_executable( $wgTexvc ) ) {
|
||||
wfDebugLog( 'texvc', "$wgTexvc does not exist or is not executable." );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $this->getError( 'math_notexvc' );
|
||||
}
|
||||
|
||||
|
@ -155,9 +158,11 @@ class MathTexvc extends MathRenderer {
|
|||
if ( strlen( $contents ) == 0 ) {
|
||||
if ( !file_exists( $tmpDir ) || !is_writable( $tmpDir ) ) {
|
||||
wfDebugLog( 'texvc', "TeX output directory $tmpDir is missing or not writable" );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $this->getError( 'math_bad_tmpdir' );
|
||||
} else {
|
||||
wfDebugLog( 'texvc', "TeX command '$cmd' returned no output and status code $retval." );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $this->getError( 'math_unknown_error' );
|
||||
}
|
||||
}
|
||||
|
@ -210,12 +215,16 @@ class MathTexvc extends MathRenderer {
|
|||
wfRunHooks( 'MathAfterTexvc', array( &$this, &$errmsg ) );
|
||||
|
||||
if ( $errmsg ) {
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $errmsg;
|
||||
} elseif ( !preg_match( "/^[a-f0-9]{32}$/", $this->getHash() ) ) {
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $this->getError( 'math_unknown_error' );
|
||||
} elseif ( !file_exists( "$tmpDir/{$this->getHash()}.png" ) ) {
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $this->getError( 'math_image_error' );
|
||||
} elseif ( filesize( "$tmpDir/{$this->getHash()}.png" ) == 0 ) {
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $this->getError( 'math_image_error' );
|
||||
}
|
||||
|
||||
|
@ -224,6 +233,7 @@ class MathTexvc extends MathRenderer {
|
|||
$backend = $this->getBackend();
|
||||
# Create any containers/directories as needed...
|
||||
if ( !$backend->prepare( array( 'dir' => $hashpath ) )->isOK() ) {
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $this->getError( 'math_output_error' );
|
||||
}
|
||||
// Store the file at the final storage path...
|
||||
|
@ -231,8 +241,10 @@ class MathTexvc extends MathRenderer {
|
|||
'src' => "$tmpDir/{$this->getHash()}.png", 'dst' => "$hashpath/{$this->getHash()}.png"
|
||||
) )->isOK()
|
||||
) {
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $this->getError( 'math_output_error' );
|
||||
}
|
||||
wfProfileOut( __METHOD__ );
|
||||
return self::MW_TEXVC_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -293,8 +305,11 @@ class MathTexvc extends MathRenderer {
|
|||
*/
|
||||
public function writeCache() {
|
||||
global $wgUseSquid;
|
||||
|
||||
wfProfileIn( __METHOD__ );
|
||||
// If cache hit, don't write anything.
|
||||
if ( $this->isRecall() ) {
|
||||
wfProfileOut( __METHOD__ );
|
||||
return;
|
||||
}
|
||||
$this->writeToDatabase();
|
||||
|
@ -304,6 +319,7 @@ class MathTexvc extends MathRenderer {
|
|||
$u = new SquidUpdate( $urls );
|
||||
$u->doUpdate();
|
||||
}
|
||||
wfProfileOut( __METHOD__ );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -313,9 +329,12 @@ class MathTexvc extends MathRenderer {
|
|||
*/
|
||||
public function readCache() {
|
||||
global $wgMathCheckFiles;
|
||||
|
||||
wfProfileIn( __METHOD__ );
|
||||
if ( $this->readFromDatabase() ) {
|
||||
if ( !$wgMathCheckFiles ) {
|
||||
// Short-circuit the file existence & migration checks
|
||||
wfProfileOut( __METHOD__ );
|
||||
return true;
|
||||
}
|
||||
$filename = $this->getHashPath() . "/{$this->getHash()}.png"; // final storage path
|
||||
|
@ -325,12 +344,13 @@ class MathTexvc extends MathRenderer {
|
|||
// Some horrible error corrupted stuff :(
|
||||
$backend->quickDelete( array( 'src' => $filename ) );
|
||||
} else {
|
||||
wfProfileOut( __METHOD__ );
|
||||
return true; // cache hit
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
wfProfileOut( __METHOD__ );
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue