Index: trunk/phase3/maintenance/storage/storageTypeStats.php |
— | — | @@ -0,0 +1,98 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once( dirname(__FILE__).'/../Maintenance.php' ); |
| 5 | + |
| 6 | +class StorageTypeStats extends Maintenance { |
| 7 | + function execute() { |
| 8 | + $dbr = wfGetDB( DB_SLAVE ); |
| 9 | + |
| 10 | + $endId = $dbr->selectField( 'text', 'MAX(old_id)', false, __METHOD__ ); |
| 11 | + if ( !$endId ) { |
| 12 | + echo "No text rows!\n"; |
| 13 | + exit( 1 ); |
| 14 | + } |
| 15 | + |
| 16 | + $rangeStart = 0; |
| 17 | + $binSize = pow( 10, floor( log10( $endId ) ) - 3 ); |
| 18 | + if ( $binSize < 100 ) { |
| 19 | + $binSize = 100; |
| 20 | + } |
| 21 | + echo "Using bin size of $binSize\n"; |
| 22 | + |
| 23 | + $stats = array(); |
| 24 | + |
| 25 | + $classSql = <<<SQL |
| 26 | + IF(old_flags LIKE '%external%', |
| 27 | + IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$', |
| 28 | + 'CGZ pointer', |
| 29 | + IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$', |
| 30 | + 'DHB pointer', |
| 31 | + IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$', |
| 32 | + 'simple pointer', |
| 33 | + 'UNKNOWN pointer' |
| 34 | + ) |
| 35 | + ) |
| 36 | + ), |
| 37 | + IF(old_flags = 'object', |
| 38 | + TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)), |
| 39 | + '[none]' |
| 40 | + ) |
| 41 | + ) |
| 42 | +SQL; |
| 43 | + |
| 44 | + for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart += $binSize ) { |
| 45 | + if ( $rangeStart / $binSize % 10 == 0 ) { |
| 46 | + echo "$rangeStart\r"; |
| 47 | + } |
| 48 | + $res = $dbr->select( |
| 49 | + 'text', |
| 50 | + array( |
| 51 | + 'old_flags', |
| 52 | + "$classSql AS class", |
| 53 | + 'COUNT(*) as count', |
| 54 | + ), |
| 55 | + array( |
| 56 | + 'old_id >= ' . $dbr->addQuotes( $rangeStart ), |
| 57 | + 'old_id < ' . $dbr->addQuotes( $rangeStart + $binSize ) |
| 58 | + ), |
| 59 | + __METHOD__, |
| 60 | + array( 'GROUP BY' => 'old_flags, class' ) |
| 61 | + ); |
| 62 | + |
| 63 | + foreach ( $res as $row ) { |
| 64 | + $flags = $row->old_flags; |
| 65 | + if ( $flags === '' ) { |
| 66 | + $flags = '[none]'; |
| 67 | + } |
| 68 | + $class = $row->class; |
| 69 | + $count = $row->count; |
| 70 | + if ( !isset( $stats[$flags][$class] ) ) { |
| 71 | + $stats[$flags][$class] = array( |
| 72 | + 'count' => 0, |
| 73 | + 'first' => $rangeStart, |
| 74 | + 'last' => 0 |
| 75 | + ); |
| 76 | + } |
| 77 | + $entry =& $stats[$flags][$class]; |
| 78 | + $entry['count'] += $count; |
| 79 | + $entry['last'] = max( $entry['last'], $rangeStart + $binSize ); |
| 80 | + unset( $entry ); |
| 81 | + } |
| 82 | + } |
| 83 | + echo "\n\n"; |
| 84 | + |
| 85 | + $format = "%-29s %-39s %-19s %-29s\n"; |
| 86 | + printf( $format, "Flags", "Class", "Count", "old_id range" ); |
| 87 | + echo str_repeat( '-', 120 ) . "\n"; |
| 88 | + foreach ( $stats as $flags => $flagStats ) { |
| 89 | + foreach ( $flagStats as $class => $entry ) { |
| 90 | + printf( $format, $flags, $class, $entry['count'], |
| 91 | + sprintf( "%-13d - %-13d", $entry['first'], $entry['last'] ) ); |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +$maintClass = 'StorageTypeStats'; |
| 98 | +require_once( DO_MAINTENANCE ); |
| 99 | + |
Property changes on: trunk/phase3/maintenance/storage/storageTypeStats.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 100 | + native |