allow localization of elements via data-msg-text and data-msg-html
[lhc/web/wiklou.git] / maintenance / fileOpPerfTest.php
1 <?php
2 /**
3 * Test for fileop performance.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24 $initialTime = microtime( true );
25 $wgProfiler = array( 'class' => 'ProfilerSimpleText' );
26 error_reporting( E_ALL );
27
28 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
29
30 /**
31 * Maintenance script to test fileop performance.
32 *
33 * @ingroup Maintenance
34 */
35 class TestFileOpPerformance extends Maintenance {
36 public function __construct() {
37 parent::__construct();
38 $this->mDescription = "Test fileop performance";
39 $this->addOption( 'b1', 'Backend 1', true, true );
40 $this->addOption( 'b2', 'Backend 2', false, true );
41 $this->addOption( 'srcdir', 'File source directory', true, true );
42 $this->addOption( 'maxfiles', 'Max files', false, true );
43 }
44
45 public function execute() {
46 $backend = FileBackendGroup::singleton()->get( $this->getOption( 'b1' ) );
47 $this->doPerfTest( $backend );
48
49 if ( $this->getOption( 'b2' ) ) {
50 $backend = FileBackendGroup::singleton()->get( $this->getOption( 'b2' ) );
51 $this->doPerfTest( $backend );
52 }
53
54 $profiler = Profiler::instance();
55 $profiler->setTemplated( true );
56 $profiler->logData(); // prints
57 }
58
59 protected function doPerfTest( FileBackend $backend ) {
60 $ops1 = array();
61 $ops2 = array();
62 $ops3 = array();
63 $ops4 = array();
64 $ops5 = array();
65
66 $baseDir = 'mwstore://' . $backend->getName() . '/testing-cont1';
67 $backend->prepare( array( 'dir' => $baseDir ) );
68
69 $dirname = $this->getOption( 'srcdir' );
70 $dir = opendir( $dirname );
71 if ( !$dir ) {
72 return;
73 }
74
75 while ( $dir && ( $file = readdir( $dir ) ) !== false ) {
76 if ( $file[0] != '.' ) {
77 $this->output( "Using '$dirname/$file' in operations.\n" );
78 $dst = $baseDir . '/' . wfBaseName( $file );
79 $ops1[] = array( 'op' => 'store', 'src' => "$dirname/$file", 'dst' => $dst, 'overwrite' => 1);
80 $ops2[] = array( 'op' => 'copy', 'src' => "$dst", 'dst' => "$dst-1", 'overwrite' => 1);
81 $ops3[] = array( 'op' => 'move', 'src' => $dst, 'dst' => "$dst-2", 'overwrite' => 1);
82 $ops4[] = array( 'op' => 'delete', 'src' => "$dst-1", 'overwrite' => 1 );
83 $ops5[] = array( 'op' => 'delete', 'src' => "$dst-2", 'overwrite' => 1 );
84 }
85 if ( count( $ops1 ) >= $this->getOption( 'maxfiles', 20 ) ) {
86 break; // enough
87 }
88 }
89 closedir( $dir );
90 $this->output( "\n" );
91
92 $start = microtime( true );
93 $status = $backend->doOperations( $ops1, array( 'force' => 1 ) );
94 $e = ( microtime( true ) - $start ) * 1000;
95 if ( $status->getErrorsArray() ) {
96 print_r( $status->getErrorsArray() );
97 exit(0);
98 }
99 $this->output( $backend->getName() . ": Stored " . count( $ops1 ) . " files in $e ms.\n" );
100
101 $start = microtime( true );
102 $backend->doOperations( $ops2, array( 'force' => 1 ) );
103 $e = ( microtime( true ) - $start ) * 1000;
104 if ( $status->getErrorsArray() ) {
105 print_r( $status->getErrorsArray() );
106 exit(0);
107 }
108 $this->output( $backend->getName() . ": Copied " . count( $ops2 ) . " files in $e ms.\n" );
109
110 $start = microtime( true );
111 $backend->doOperations( $ops3, array( 'force' => 1 ) );
112 $e = ( microtime( true ) - $start ) * 1000;
113 if ( $status->getErrorsArray() ) {
114 print_r( $status->getErrorsArray() );
115 exit(0);
116 }
117 $this->output( $backend->getName() . ": Moved " . count( $ops3 ) . " files in $e ms.\n" );
118
119 $start = microtime( true );
120 $backend->doOperations( $ops4, array( 'force' => 1 ) );
121 $e = ( microtime( true ) - $start ) * 1000;
122 if ( $status->getErrorsArray() ) {
123 print_r( $status->getErrorsArray() );
124 exit(0);
125 }
126 $this->output( $backend->getName() . ": Deleted " . count( $ops4 ) . " files in $e ms.\n" );
127
128 $start = microtime( true );
129 $backend->doOperations( $ops5, array( 'force' => 1 ) );
130 $e = ( microtime( true ) - $start ) * 1000;
131 if ( $status->getErrorsArray() ) {
132 print_r( $status->getErrorsArray() );
133 exit(0);
134 }
135 $this->output( $backend->getName() . ": Deleted " . count( $ops5 ) . " files in $e ms.\n" );
136 }
137 }
138
139 $maintClass = "TestFileOpPerformance";
140 require_once( RUN_MAINTENANCE_IF_MAIN );