]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/stats.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / maintenance / stats.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  * @ingroup Maintenance
21  */
22
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
24
25 class CacheStats extends Maintenance {
26
27         public function __construct() {
28                 $this->mDescription = "Show statistics from the cache";
29                 parent::__construct();
30         }
31
32         public function getDbType() {
33                 return Maintenance::DB_NONE;
34         }
35
36         public function execute() {
37                 global $wgMemc;
38
39                 // Can't do stats if
40                 if ( get_class( $wgMemc ) == 'FakeMemCachedClient' ) {
41                         $this->error( "You are running FakeMemCachedClient, I can not provide any statistics.", true );
42                 }
43                 $session = intval( $wgMemc->get( wfMemcKey( 'stats', 'request_with_session' ) ) );
44                 $noSession = intval( $wgMemc->get( wfMemcKey( 'stats', 'request_without_session' ) ) );
45                 $total = $session + $noSession;
46                 if ( $total == 0 ) {
47                         $this->error( "You either have no stats or the cache isn't running. Aborting.", true );
48                 }
49                 $this->output( "Requests\n" );
50                 $this->output( sprintf( "with session:      %-10d %6.2f%%\n", $session, $session / $total * 100 ) );
51                 $this->output( sprintf( "without session:   %-10d %6.2f%%\n", $noSession, $noSession / $total * 100 ) );
52                 $this->output( sprintf( "total:             %-10d %6.2f%%\n", $total, 100 ) );
53
54
55                 $this->output( "\nParser cache\n" );
56                 $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_hit' ) ) );
57                 $invalid = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_invalid' ) ) );
58                 $expired = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_expired' ) ) );
59                 $absent = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_absent' ) ) );
60                 $stub = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_stub' ) ) );
61                 $total = $hits + $invalid + $expired + $absent + $stub;
62                 $this->output( sprintf( "hits:              %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
63                 $this->output( sprintf( "invalid:           %-10d %6.2f%%\n", $invalid, $invalid / $total * 100 ) );
64                 $this->output( sprintf( "expired:           %-10d %6.2f%%\n", $expired, $expired / $total * 100 ) );
65                 $this->output( sprintf( "absent:            %-10d %6.2f%%\n", $absent, $absent / $total * 100 ) );
66                 $this->output( sprintf( "stub threshold:    %-10d %6.2f%%\n", $stub, $stub / $total * 100 ) );
67                 $this->output( sprintf( "total:             %-10d %6.2f%%\n", $total, 100 ) );
68
69                 $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_hit' ) ) );
70                 $misses = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_miss' ) ) );
71                 $updates = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_update' ) ) );
72                 $total = $hits + $misses;
73                 $this->output( "\nImage cache\n" );
74                 $this->output( sprintf( "hits:              %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
75                 $this->output( sprintf( "misses:            %-10d %6.2f%%\n", $misses, $misses / $total * 100 ) );
76                 $this->output( sprintf( "updates:           %-10d\n", $updates ) );
77
78                 $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_cache_hit' ) ) );
79                 $misses = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_cache_miss' ) ) );
80                 $uncacheable = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_uncacheable' ) ) );
81                 $total = $hits + $misses + $uncacheable;
82                 $this->output( "\nDiff cache\n" );
83                 $this->output( sprintf( "hits:              %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
84                 $this->output( sprintf( "misses:            %-10d %6.2f%%\n", $misses, $misses / $total * 100 ) );
85                 $this->output( sprintf( "uncacheable:       %-10d %6.2f%%\n", $uncacheable, $uncacheable / $total * 100 ) );
86         }
87 }
88
89 $maintClass = "CacheStats";
90 require_once( RUN_MAINTENANCE_IF_MAIN );