MediaWiki  REL1_22
showCacheStats.php
Go to the documentation of this file.
00001 <?php
00024 require_once __DIR__ . '/Maintenance.php';
00025 
00031 class ShowCacheStats extends Maintenance {
00032 
00033     public function __construct() {
00034         $this->mDescription = "Show statistics from the cache";
00035         parent::__construct();
00036     }
00037 
00038     public function getDbType() {
00039         return Maintenance::DB_NONE;
00040     }
00041 
00042     public function execute() {
00043         global $wgMemc;
00044 
00045         // Can't do stats if
00046         if ( get_class( $wgMemc ) == 'EmptyBagOStuff' ) {
00047             $this->error( "You are running EmptyBagOStuff, I can not provide any statistics.", true );
00048         }
00049         $session = intval( $wgMemc->get( wfMemcKey( 'stats', 'request_with_session' ) ) );
00050         $noSession = intval( $wgMemc->get( wfMemcKey( 'stats', 'request_without_session' ) ) );
00051         $total = $session + $noSession;
00052         if ( $total == 0 ) {
00053             $this->error( "You either have no stats or the cache isn't running. Aborting.", true );
00054         }
00055         $this->output( "Requests\n" );
00056         $this->output( sprintf( "with session:      %-10d %6.2f%%\n", $session, $session / $total * 100 ) );
00057         $this->output( sprintf( "without session:   %-10d %6.2f%%\n", $noSession, $noSession / $total * 100 ) );
00058         $this->output( sprintf( "total:             %-10d %6.2f%%\n", $total, 100 ) );
00059 
00060 
00061         $this->output( "\nParser cache\n" );
00062         $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_hit' ) ) );
00063         $expired = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_expired' ) ) );
00064         $absent = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_absent' ) ) );
00065         $stub = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_stub' ) ) );
00066         $total = $hits + $expired + $absent + $stub;
00067         if ( $total ) {
00068             $this->output( sprintf( "hits:              %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
00069             $this->output( sprintf( "expired:           %-10d %6.2f%%\n", $expired, $expired / $total * 100 ) );
00070             $this->output( sprintf( "absent:            %-10d %6.2f%%\n", $absent, $absent / $total * 100 ) );
00071             $this->output( sprintf( "stub threshold:    %-10d %6.2f%%\n", $stub, $stub / $total * 100 ) );
00072             $this->output( sprintf( "total:             %-10d %6.2f%%\n", $total, 100 ) );
00073         } else {
00074             $this->output( "no statistics available\n" );
00075         }
00076 
00077         $this->output( "\nImage cache\n" );
00078         $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_hit' ) ) );
00079         $misses = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_miss' ) ) );
00080         $updates = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_update' ) ) );
00081         $total = $hits + $misses;
00082         if ( $total ) {
00083             $this->output( sprintf( "hits:              %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
00084             $this->output( sprintf( "misses:            %-10d %6.2f%%\n", $misses, $misses / $total * 100 ) );
00085             $this->output( sprintf( "updates:           %-10d\n", $updates ) );
00086         } else {
00087             $this->output( "no statistics available\n" );
00088         }
00089 
00090         $this->output( "\nDiff cache\n" );
00091         $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_cache_hit' ) ) );
00092         $misses = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_cache_miss' ) ) );
00093         $uncacheable = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_uncacheable' ) ) );
00094         $total = $hits + $misses + $uncacheable;
00095         if ( $total ) {
00096             $this->output( sprintf( "hits:              %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
00097             $this->output( sprintf( "misses:            %-10d %6.2f%%\n", $misses, $misses / $total * 100 ) );
00098             $this->output( sprintf( "uncacheable:       %-10d %6.2f%%\n", $uncacheable, $uncacheable / $total * 100 ) );
00099         } else {
00100             $this->output( "no statistics available\n" );
00101         }
00102     }
00103 }
00104 
00105 $maintClass = "ShowCacheStats";
00106 require_once RUN_MAINTENANCE_IF_MAIN;