Reedy has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/337194 )
Change subject: Add timing instrumentation
......................................................................
Add timing instrumentation
Move some code closer to relevant usage
Tweak some output of newlines
Bug: T157737
Change-Id: I3a4d9c74a3a93fe0474e78c9c0913dd85dec4bb6
(cherry picked from commit cff6e0f3596e3257a8d4dd0a4a5e69bfe5226c5e)
---
M maintenance/GenerateFancyCaptchas.php
1 file changed, 57 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit
refs/changes/94/337194/1
diff --git a/maintenance/GenerateFancyCaptchas.php
b/maintenance/GenerateFancyCaptchas.php
index 0a02bd5..26a8715 100644
--- a/maintenance/GenerateFancyCaptchas.php
+++ b/maintenance/GenerateFancyCaptchas.php
@@ -51,11 +51,14 @@
);
$this->addOption( "delete", "Delete the old captches" );
$this->mDescription = "Generate new captchas and move them into
storage";
+
$this->requireExtension( "FancyCaptcha" );
}
public function execute() {
global $wgCaptchaSecret, $wgCaptchaDirectoryLevels;
+
+ $totalTime = -microtime( true );
$instance = ConfirmEditHooks::getInstance();
if ( !( $instance instanceof FancyCaptcha ) ) {
@@ -84,7 +87,6 @@
$e = null; // exception
try {
-
$captchaScript = 'captcha.py';
if ( $this->hasOption( 'oldcaptcha' ) ) {
@@ -104,25 +106,29 @@
}
}
- $this->output( "Generating $countGen new captchas...\n"
);
+ $this->output( "Generating $countGen new captchas.." );
$retVal = 1;
+ $captchaTime = -microtime( true );
wfShellExec( $cmd, $retVal, [], [ 'time' => 0 ] );
if ( $retVal != 0 ) {
wfRecursiveRemoveDir( $tmpDir );
$this->error( "Could not run generation
script.\n", 1 );
}
- $flags = FilesystemIterator::SKIP_DOTS;
- $iter = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator( $tmpDir, $flags
),
- RecursiveIteratorIterator::CHILD_FIRST //
include dirs
- );
+ $captchaTime += microtime( true );
+ $this->output( " Done.\n" );
- $this->output( "Done.\n" );
+ $this->output(
+ sprintf(
+ "\nGenerated %d captchas in %.1f
seconds\n",
+ $countGen,
+ $captchaTime
+ )
+ );
$originalFiles = [];
if ( $deleteOldCaptchas ) {
- $this->output( "Getting a list of old
captchas...\n" );
+ $this->output( "Getting a list of old
captchas..." );
foreach (
$backend->getFileList(
[ 'dir' =>
$backend->getRootStoragePath() . '/captcha-render' ]
@@ -130,10 +136,21 @@
) {
$originalFiles[] = $file;
}
- $this->output( "Done.\n" );
+ $this->output( " Done.\n" );
}
- $this->output( "Copying the new captchas to
storage...\n" );
+ $this->output( "Copying the new captchas to storage..."
);
+
+ $storeTime = -microtime( true );
+ $iter = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator(
+ $tmpDir,
+ FilesystemIterator::SKIP_DOTS
+ ),
+ RecursiveIteratorIterator::CHILD_FIRST //
include dirs
+ );
+
+ $captchasGenerated = iterator_count( $iter );
foreach ( $iter as $fileInfo ) {
if ( !$fileInfo->isFile() ) {
continue;
@@ -149,24 +166,50 @@
$this->error( "Could not save file
'{$fileInfo->getPathname()}'.\n" );
}
}
- $this->output( "Done.\n" );
+ $storeTime += microtime( true );
+ $this->output( " Done.\n" );
+
+ $this->output(
+ sprintf(
+ "\nCopied %d captchas to storage in
%.1f seconds\n",
+ $captchasGenerated,
+ $storeTime
+ )
+ );
if ( $deleteOldCaptchas ) {
$numOriginalFiles = count( $originalFiles );
$this->output( "Deleting {$numOriginalFiles}
old captchas...\n" );
+ $deleteTime = -microtime( true );
foreach ( $originalFiles as $file ) {
$backend->quickDelete( [ 'src' => $file
] );
}
+ $deleteTime += microtime( true );
$this->output( "Done.\n" );
+ $this->output(
+ sprintf(
+ "\nDeleted %d old captchas in
%.1f seconds\n",
+ count( $originalFiles ),
+ $deleteTime
+ )
+ );
}
} catch ( Exception $e ) {
wfRecursiveRemoveDir( $tmpDir );
throw $e;
}
- $this->output( "Removing temporary files...\n" );
+ $this->output( "Removing temporary files..." );
wfRecursiveRemoveDir( $tmpDir );
- $this->output( "Done.\n" );
+ $this->output( " Done.\n" );
+
+ $totalTime += microtime( true );
+ $this->output(
+ sprintf(
+ "\nWhole captchas generation process took %.1f
seconds\n",
+ $totalTime
+ )
+ );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/337194
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a4d9c74a3a93fe0474e78c9c0913dd85dec4bb6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: wmf/1.29.0-wmf.11
Gerrit-Owner: Reedy <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits