Merge "Add a class to interlanguage links"
[lhc/web/wiklou.git] / maintenance / showCacheStats.php
1 <?php
2 /**
3 * Show statistics from the cache.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24 require_once __DIR__ . '/Maintenance.php';
25
26 /**
27 * Maintenance script that shows statistics from the cache.
28 *
29 * @ingroup Maintenance
30 */
31 class ShowCacheStats extends Maintenance {
32
33 public function __construct() {
34 $this->mDescription = "Show statistics from the cache";
35 parent::__construct();
36 }
37
38 public function getDbType() {
39 return Maintenance::DB_NONE;
40 }
41
42 public function execute() {
43 global $wgMemc;
44
45 // Can't do stats if
46 if ( get_class( $wgMemc ) == 'EmptyBagOStuff' ) {
47 $this->error( "You are running EmptyBagOStuff, I can not provide any statistics.", true );
48 }
49 $session = intval( $wgMemc->get( wfMemcKey( 'stats', 'request_with_session' ) ) );
50 $noSession = intval( $wgMemc->get( wfMemcKey( 'stats', 'request_without_session' ) ) );
51 $total = $session + $noSession;
52 if ( $total == 0 ) {
53 $this->error( "You either have no stats or the cache isn't running. Aborting.", true );
54 }
55 $this->output( "Requests\n" );
56 $this->output( sprintf( "with session: %-10d %6.2f%%\n", $session, $session / $total * 100 ) );
57 $this->output( sprintf( "without session: %-10d %6.2f%%\n", $noSession, $noSession / $total * 100 ) );
58 $this->output( sprintf( "total: %-10d %6.2f%%\n", $total, 100 ) );
59
60 $this->output( "\nParser cache\n" );
61 $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_hit' ) ) );
62 $expired = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_expired' ) ) );
63 $absent = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_absent' ) ) );
64 $stub = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_stub' ) ) );
65 $total = $hits + $expired + $absent + $stub;
66 if ( $total ) {
67 $this->output( sprintf( "hits: %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
68 $this->output( sprintf( "expired: %-10d %6.2f%%\n", $expired, $expired / $total * 100 ) );
69 $this->output( sprintf( "absent: %-10d %6.2f%%\n", $absent, $absent / $total * 100 ) );
70 $this->output( sprintf( "stub threshold: %-10d %6.2f%%\n", $stub, $stub / $total * 100 ) );
71 $this->output( sprintf( "total: %-10d %6.2f%%\n", $total, 100 ) );
72 } else {
73 $this->output( "no statistics available\n" );
74 }
75
76 $this->output( "\nImage cache\n" );
77 $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_hit' ) ) );
78 $misses = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_miss' ) ) );
79 $updates = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_update' ) ) );
80 $total = $hits + $misses;
81 if ( $total ) {
82 $this->output( sprintf( "hits: %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
83 $this->output( sprintf( "misses: %-10d %6.2f%%\n", $misses, $misses / $total * 100 ) );
84 $this->output( sprintf( "updates: %-10d\n", $updates ) );
85 } else {
86 $this->output( "no statistics available\n" );
87 }
88
89 $this->output( "\nDiff cache\n" );
90 $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_cache_hit' ) ) );
91 $misses = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_cache_miss' ) ) );
92 $uncacheable = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_uncacheable' ) ) );
93 $total = $hits + $misses + $uncacheable;
94 if ( $total ) {
95 $this->output( sprintf( "hits: %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
96 $this->output( sprintf( "misses: %-10d %6.2f%%\n", $misses, $misses / $total * 100 ) );
97 $this->output( sprintf( "uncacheable: %-10d %6.2f%%\n", $uncacheable, $uncacheable / $total * 100 ) );
98 } else {
99 $this->output( "no statistics available\n" );
100 }
101 }
102 }
103
104 $maintClass = "ShowCacheStats";
105 require_once RUN_MAINTENANCE_IF_MAIN;