Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
StorageTypeStats | |
0.00% |
0 / 48 |
|
0.00% |
0 / 1 |
110 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 48 |
|
0.00% |
0 / 1 |
110 |
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. |
7 | * |
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. |
12 | * |
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 |
17 | * |
18 | * @file |
19 | * @ingroup Maintenance ExternalStorage |
20 | */ |
21 | |
22 | require_once __DIR__ . '/../Maintenance.php'; |
23 | |
24 | class StorageTypeStats extends Maintenance { |
25 | public function execute() { |
26 | $dbr = $this->getReplicaDB(); |
27 | |
28 | $endId = $dbr->newSelectQueryBuilder() |
29 | ->select( 'MAX(old_id)' ) |
30 | ->from( 'text' ) |
31 | ->caller( __METHOD__ )->fetchField(); |
32 | if ( !$endId ) { |
33 | $this->fatalError( 'No text rows!' ); |
34 | } |
35 | |
36 | $binSize = intval( 10 ** ( floor( log10( $endId ) ) - 3 ) ); |
37 | if ( $binSize < 100 ) { |
38 | $binSize = 100; |
39 | } |
40 | echo "Using bin size of $binSize\n"; |
41 | |
42 | $stats = []; |
43 | |
44 | $classSql = <<<SQL |
45 | IF(old_flags LIKE '%external%', |
46 | IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$', |
47 | 'CGZ pointer', |
48 | IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$', |
49 | 'DHB pointer', |
50 | IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$', |
51 | 'simple pointer', |
52 | 'UNKNOWN pointer' |
53 | ) |
54 | ) |
55 | ), |
56 | IF(old_flags LIKE '%object%', |
57 | TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)), |
58 | '[none]' |
59 | ) |
60 | ) |
61 | SQL; |
62 | |
63 | for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart += $binSize ) { |
64 | if ( $rangeStart / $binSize % 10 == 0 ) { |
65 | echo "$rangeStart\r"; |
66 | } |
67 | $res = $dbr->newSelectQueryBuilder() |
68 | ->select( [ 'old_flags', 'class' => $classSql, 'count' => 'COUNT(*)' ] ) |
69 | ->from( 'text' ) |
70 | ->where( [ 'old_id >= ' . intval( $rangeStart ) ] ) |
71 | ->andWhere( [ 'old_id < ' . intval( $rangeStart + $binSize ) ] ) |
72 | ->groupBy( [ 'old_flags', 'class' ] ) |
73 | ->caller( __METHOD__ )->fetchResultSet(); |
74 | |
75 | foreach ( $res as $row ) { |
76 | $flags = $row->old_flags; |
77 | if ( $flags === '' ) { |
78 | $flags = '[none]'; |
79 | } |
80 | $class = $row->class; |
81 | $count = $row->count; |
82 | // @phan-suppress-next-line PhanImpossibleConditionInLoop,PhanPossiblyUndeclaredVariable False positive |
83 | if ( !isset( $stats[$flags][$class] ) ) { |
84 | $stats[$flags][$class] = [ |
85 | 'count' => 0, |
86 | 'first' => $rangeStart, |
87 | 'last' => 0 |
88 | ]; |
89 | } |
90 | $entry =& $stats[$flags][$class]; |
91 | $entry['count'] += $count; |
92 | $entry['last'] = max( $entry['last'], $rangeStart + $binSize ); |
93 | unset( $entry ); |
94 | } |
95 | } |
96 | echo "\n\n"; |
97 | |
98 | $format = "%-29s %-39s %-19s %-29s\n"; |
99 | printf( $format, "Flags", "Class", "Count", "old_id range" ); |
100 | echo str_repeat( '-', 120 ) . "\n"; |
101 | foreach ( $stats as $flags => $flagStats ) { |
102 | foreach ( $flagStats as $class => $entry ) { |
103 | printf( $format, $flags, $class, $entry['count'], |
104 | sprintf( "%-13d - %-13d", $entry['first'], $entry['last'] ) ); |
105 | } |
106 | } |
107 | } |
108 | } |
109 | |
110 | $maintClass = StorageTypeStats::class; |
111 | require_once RUN_MAINTENANCE_IF_MAIN; |