Merge "Make update.php file executable"
[mediawiki.git] / maintenance / storage / storageTypeStats.php
blobe33057f6127150d80262da3018e3f61418d6fa66
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Maintenance ExternalStorage
22 require_once __DIR__ . '/../Maintenance.php';
24 class StorageTypeStats extends Maintenance {
25 function execute() {
26 $dbr = wfGetDB( DB_SLAVE );
28 $endId = $dbr->selectField( 'text', 'MAX(old_id)', false, __METHOD__ );
29 if ( !$endId ) {
30 echo "No text rows!\n";
31 exit( 1 );
34 $binSize = intval( pow( 10, floor( log10( $endId ) ) - 3 ) );
35 if ( $binSize < 100 ) {
36 $binSize = 100;
38 echo "Using bin size of $binSize\n";
40 $stats = array();
42 $classSql = <<<SQL
43 IF(old_flags LIKE '%external%',
44 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$',
45 'CGZ pointer',
46 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$',
47 'DHB pointer',
48 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$',
49 'simple pointer',
50 'UNKNOWN pointer'
54 IF(old_flags LIKE '%object%',
55 TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)),
56 '[none]'
59 SQL;
61 for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart += $binSize ) {
62 if ( $rangeStart / $binSize % 10 == 0 ) {
63 echo "$rangeStart\r";
65 $res = $dbr->select(
66 'text',
67 array(
68 'old_flags',
69 "$classSql AS class",
70 'COUNT(*) as count',
72 array(
73 'old_id >= ' . intval( $rangeStart ),
74 'old_id < ' . intval( $rangeStart + $binSize )
76 __METHOD__,
77 array( 'GROUP BY' => 'old_flags, class' )
80 foreach ( $res as $row ) {
81 $flags = $row->old_flags;
82 if ( $flags === '' ) {
83 $flags = '[none]';
85 $class = $row->class;
86 $count = $row->count;
87 if ( !isset( $stats[$flags][$class] ) ) {
88 $stats[$flags][$class] = array(
89 'count' => 0,
90 'first' => $rangeStart,
91 'last' => 0
94 $entry =& $stats[$flags][$class];
95 $entry['count'] += $count;
96 $entry['last'] = max( $entry['last'], $rangeStart + $binSize );
97 unset( $entry );
100 echo "\n\n";
102 $format = "%-29s %-39s %-19s %-29s\n";
103 printf( $format, "Flags", "Class", "Count", "old_id range" );
104 echo str_repeat( '-', 120 ) . "\n";
105 foreach ( $stats as $flags => $flagStats ) {
106 foreach ( $flagStats as $class => $entry ) {
107 printf( $format, $flags, $class, $entry['count'],
108 sprintf( "%-13d - %-13d", $entry['first'], $entry['last'] ) );
114 $maintClass = 'StorageTypeStats';
115 require_once RUN_MAINTENANCE_IF_MAIN;