[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/ -> showCacheStats.php (source)

   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  
  50          $this->output( "\nParser cache\n" );
  51          $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_hit' ) ) );
  52          $expired = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_expired' ) ) );
  53          $absent = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_absent' ) ) );
  54          $stub = intval( $wgMemc->get( wfMemcKey( 'stats', 'pcache_miss_stub' ) ) );
  55          $total = $hits + $expired + $absent + $stub;
  56          if ( $total ) {
  57              $this->output( sprintf( "hits:              %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
  58              $this->output( sprintf(
  59                  "expired:           %-10d %6.2f%%\n",
  60                  $expired,
  61                  $expired / $total * 100
  62              ) );
  63              $this->output( sprintf(
  64                  "absent:            %-10d %6.2f%%\n",
  65                  $absent,
  66                  $absent / $total * 100
  67              ) );
  68              $this->output( sprintf( "stub threshold:    %-10d %6.2f%%\n", $stub, $stub / $total * 100 ) );
  69              $this->output( sprintf( "total:             %-10d %6.2f%%\n", $total, 100 ) );
  70          } else {
  71              $this->output( "no statistics available\n" );
  72          }
  73  
  74          $this->output( "\nImage cache\n" );
  75          $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_hit' ) ) );
  76          $misses = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_miss' ) ) );
  77          $updates = intval( $wgMemc->get( wfMemcKey( 'stats', 'image_cache_update' ) ) );
  78          $total = $hits + $misses;
  79          if ( $total ) {
  80              $this->output( sprintf( "hits:              %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
  81              $this->output( sprintf(
  82                  "misses:            %-10d %6.2f%%\n",
  83                  $misses,
  84                  $misses / $total * 100
  85              ) );
  86              $this->output( sprintf( "updates:           %-10d\n", $updates ) );
  87          } else {
  88              $this->output( "no statistics available\n" );
  89          }
  90  
  91          $this->output( "\nDiff cache\n" );
  92          $hits = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_cache_hit' ) ) );
  93          $misses = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_cache_miss' ) ) );
  94          $uncacheable = intval( $wgMemc->get( wfMemcKey( 'stats', 'diff_uncacheable' ) ) );
  95          $total = $hits + $misses + $uncacheable;
  96          if ( $total ) {
  97              $this->output( sprintf( "hits:              %-10d %6.2f%%\n", $hits, $hits / $total * 100 ) );
  98              $this->output( sprintf(
  99                  "misses:            %-10d %6.2f%%\n",
 100                  $misses,
 101                  $misses / $total * 100
 102              ) );
 103              $this->output( sprintf(
 104                  "uncacheable:       %-10d %6.2f%%\n",
 105                  $uncacheable,
 106                  $uncacheable / $total * 100
 107              ) );
 108          } else {
 109              $this->output( "no statistics available\n" );
 110          }
 111      }
 112  }
 113  
 114  $maintClass = "ShowCacheStats";
 115  require_once RUN_MAINTENANCE_IF_MAIN;


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1