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