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