MediaWiki
REL1_39
storageTypeStats.php
Go to the documentation of this file.
1
<?php
22
require_once __DIR__ .
'/../Maintenance.php'
;
23
24
class
StorageTypeStats
extends
Maintenance
{
25
public
function
execute
() {
26
$dbr
= $this->
getDB
(
DB_REPLICA
);
27
28
$endId =
$dbr
->selectField(
'text'
,
'MAX(old_id)'
,
''
, __METHOD__ );
29
if
( !$endId ) {
30
$this->
fatalError
(
'No text rows!'
);
31
}
32
33
$binSize = intval( 10 ** ( floor( log10( $endId ) ) - 3 ) );
34
if
( $binSize < 100 ) {
35
$binSize = 100;
36
}
37
echo
"Using bin size of $binSize\n"
;
38
39
$stats = [];
40
41
$classSql = <<<SQL
42
IF(old_flags LIKE
'%external%'
,
43
IF(old_text REGEXP
'^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$'
,
44
'CGZ pointer'
,
45
IF(old_text REGEXP
'^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$'
,
46
'DHB pointer'
,
47
IF(old_text REGEXP
'^DB://[[:alnum:]]+/[0-9]+$'
,
48
'simple pointer'
,
49
'UNKNOWN pointer'
50
)
51
)
52
),
53
IF(old_flags LIKE
'%object%'
,
54
TRIM(
'"'
FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text,
':'
, 3),
':'
, -1)),
55
'[none]'
56
)
57
)
58
SQL;
59
60
for
( $rangeStart = 0; $rangeStart < $endId; $rangeStart += $binSize ) {
61
if
( $rangeStart / $binSize % 10 == 0 ) {
62
echo
"$rangeStart\r"
;
63
}
64
$res
=
$dbr
->select(
65
'text'
,
66
[
67
'old_flags'
,
68
'class'
=> $classSql,
69
'count'
=>
'COUNT(*)'
,
70
],
71
[
72
'old_id >= '
. intval( $rangeStart ),
73
'old_id < '
. intval( $rangeStart + $binSize )
74
],
75
__METHOD__,
76
[
'GROUP BY'
=> [
'old_flags'
,
'class'
] ]
77
);
78
79
foreach
(
$res
as $row ) {
80
$flags = $row->old_flags;
81
if
( $flags ===
''
) {
82
$flags =
'[none]'
;
83
}
84
$class = $row->class;
85
$count = $row->count;
86
// @phan-suppress-next-line PhanImpossibleConditionInLoop,PhanPossiblyUndeclaredVariable False positive
87
if
( !isset( $stats[$flags][$class] ) ) {
88
$stats[$flags][$class] = [
89
'count'
=> 0,
90
'first'
=> $rangeStart,
91
'last'
=> 0
92
];
93
}
94
$entry =& $stats[$flags][$class];
95
$entry[
'count'
] += $count;
96
$entry[
'last'
] = max( $entry[
'last'
], $rangeStart + $binSize );
97
unset( $entry );
98
}
99
}
100
echo
"\n\n"
;
101
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'
] ) );
109
}
110
}
111
}
112
}
113
114
$maintClass
= StorageTypeStats::class;
115
require_once RUN_MAINTENANCE_IF_MAIN;
getDB
getDB()
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition
Maintenance.php:66
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition
Maintenance.php:497
StorageTypeStats
Definition
storageTypeStats.php:24
StorageTypeStats\execute
execute()
Do the actual work.
Definition
storageTypeStats.php:25
DB_REPLICA
const DB_REPLICA
Definition
defines.php:26
$maintClass
$maintClass
Definition
storageTypeStats.php:114
$res
$res
Definition
testCompression.php:57
$dbr
$dbr
Definition
testCompression.php:54
maintenance
storage
storageTypeStats.php
Generated on Tue Sep 10 2024 06:25:04 for MediaWiki by
1.10.0