[MediaWiki-commits] [Gerrit] mediawiki...ConfirmEdit[master]: Add timing instrumentation

2017-02-10 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
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, 57 insertions(+), 14 deletions(-)

Approvals:
  Florianschmidtwelzow: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/GenerateFancyCaptchas.php 
b/maintenance/GenerateFancyCaptchas.php
index beade3d..4811692 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 );
+

[MediaWiki-commits] [Gerrit] mediawiki...ConfirmEdit[master]: Add timing instrumentation

2017-02-09 Thread Reedy (Code Review)
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" );
+
+