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