Reedy has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/336914 )

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
---
M maintenance/GenerateFancyCaptchas.php
1 file changed, 53 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit 
refs/changes/14/336914/1

diff --git a/maintenance/GenerateFancyCaptchas.php 
b/maintenance/GenerateFancyCaptchas.php
index beade3d..589272b 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,19 @@
                                ) {
                                        $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 );
+                       $flags = FilesystemIterator::SKIP_DOTS;
+                       $iter = new RecursiveIteratorIterator(
+                               new RecursiveDirectoryIterator( $tmpDir, $flags 
),
+                               RecursiveIteratorIterator::CHILD_FIRST // 
include dirs
+                       );
+
+                       $captchasGenerated = iterator_count( $iter );
                        foreach ( $iter as $fileInfo ) {
                                if ( !$fileInfo->isFile() ) {
                                        continue;
@@ -149,15 +164,33 @@
                                        $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 );
@@ -167,6 +200,14 @@
                $this->output( "Removing temporary files...\n" );
                wfRecursiveRemoveDir( $tmpDir );
                $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/336914
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: master
Gerrit-Owner: Reedy <re...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to