00001 <?php
00002
00003 require_once( dirname(__FILE__).'/../Maintenance.php' );
00004
00005 class StorageTypeStats extends Maintenance {
00006 function execute() {
00007 $dbr = wfGetDB( DB_SLAVE );
00008
00009 $endId = $dbr->selectField( 'text', 'MAX(old_id)', false, __METHOD__ );
00010 if ( !$endId ) {
00011 echo "No text rows!\n";
00012 exit( 1 );
00013 }
00014
00015 $rangeStart = 0;
00016 $binSize = intval( pow( 10, floor( log10( $endId ) ) - 3 ) );
00017 if ( $binSize < 100 ) {
00018 $binSize = 100;
00019 }
00020 echo "Using bin size of $binSize\n";
00021
00022 $stats = array();
00023
00024 $classSql = <<<SQL
00025 IF(old_flags LIKE '%external%',
00026 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$',
00027 'CGZ pointer',
00028 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$',
00029 'DHB pointer',
00030 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$',
00031 'simple pointer',
00032 'UNKNOWN pointer'
00033 )
00034 )
00035 ),
00036 IF(old_flags LIKE '%object%',
00037 TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)),
00038 '[none]'
00039 )
00040 )
00041 SQL;
00042
00043 for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart += $binSize ) {
00044 if ( $rangeStart / $binSize % 10 == 0 ) {
00045 echo "$rangeStart\r";
00046 }
00047 $res = $dbr->select(
00048 'text',
00049 array(
00050 'old_flags',
00051 "$classSql AS class",
00052 'COUNT(*) as count',
00053 ),
00054 array(
00055 'old_id >= ' . intval( $rangeStart ),
00056 'old_id < ' . intval( $rangeStart + $binSize )
00057 ),
00058 __METHOD__,
00059 array( 'GROUP BY' => 'old_flags, class' )
00060 );
00061
00062 foreach ( $res as $row ) {
00063 $flags = $row->old_flags;
00064 if ( $flags === '' ) {
00065 $flags = '[none]';
00066 }
00067 $class = $row->class;
00068 $count = $row->count;
00069 if ( !isset( $stats[$flags][$class] ) ) {
00070 $stats[$flags][$class] = array(
00071 'count' => 0,
00072 'first' => $rangeStart,
00073 'last' => 0
00074 );
00075 }
00076 $entry =& $stats[$flags][$class];
00077 $entry['count'] += $count;
00078 $entry['last'] = max( $entry['last'], $rangeStart + $binSize );
00079 unset( $entry );
00080 }
00081 }
00082 echo "\n\n";
00083
00084 $format = "%-29s %-39s %-19s %-29s\n";
00085 printf( $format, "Flags", "Class", "Count", "old_id range" );
00086 echo str_repeat( '-', 120 ) . "\n";
00087 foreach ( $stats as $flags => $flagStats ) {
00088 foreach ( $flagStats as $class => $entry ) {
00089 printf( $format, $flags, $class, $entry['count'],
00090 sprintf( "%-13d - %-13d", $entry['first'], $entry['last'] ) );
00091 }
00092 }
00093 }
00094 }
00095
00096 $maintClass = 'StorageTypeStats';
00097 require_once( DO_MAINTENANCE );
00098