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