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
19 * @ingroup Maintenance ExternalStorage
22 require_once __DIR__
. '/../Maintenance.php';
24 class StorageTypeStats
extends Maintenance
{
26 $dbr = $this->getDB( DB_SLAVE
);
28 $endId = $dbr->selectField( 'text', 'MAX(old_id)', false, __METHOD__
);
30 echo "No text rows!\n";
34 $binSize = intval( pow( 10, floor( log10( $endId ) ) - 3 ) );
35 if ( $binSize < 100 ) {
38 echo "Using bin size of $binSize\n";
43 IF(old_flags LIKE '%external%',
44 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$',
46 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$',
48 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$',
54 IF(old_flags LIKE '%object%',
55 TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)),
61 for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart +
= $binSize ) {
62 if ( $rangeStart / $binSize %
10 == 0 ) {
73 'old_id >= ' . intval( $rangeStart ),
74 'old_id < ' . intval( $rangeStart +
$binSize )
77 [ 'GROUP BY' => 'old_flags, class' ]
80 foreach ( $res as $row ) {
81 $flags = $row->old_flags
;
82 if ( $flags === '' ) {
87 if ( !isset( $stats[$flags][$class] ) ) {
88 $stats[$flags][$class] = [
90 'first' => $rangeStart,
94 $entry =& $stats[$flags][$class];
95 $entry['count'] +
= $count;
96 $entry['last'] = max( $entry['last'], $rangeStart +
$binSize );
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
;