00001 <?php
00002
00023 require_once( dirname(__FILE__) . '/../Maintenance.php' );
00024
00025 class OrphanStats extends Maintenance {
00026 public function __construct() {
00027 parent::__construct();
00028 $this->mDescription = "how some statistics on the blob_orphans table, created with trackBlobs.php";
00029 }
00030
00031 private function getDB( $cluster ) {
00032 $lb = wfGetLBFactory()->getExternalLB( $cluster );
00033 return $lb->getConnection( DB_SLAVE );
00034 }
00035
00036 public function execute() {
00037 $extDBs = array();
00038 $dbr = wfGetDB( DB_SLAVE );
00039 if( !$dbr->tableExists( 'blob_orphans' ) ) {
00040 $this->error( "blob_orphans doesn't seem to exist, need to run trackBlobs.php first", true );
00041 }
00042 $res = $dbr->select( 'blob_orphans', '*', false, __METHOD__ );
00043
00044 $num = 0;
00045 $totalSize = 0;
00046 $hashes = array();
00047 $maxSize = 0;
00048
00049 foreach ( $res as $boRow ) {
00050 $extDB = $this->getDB( $boRow->bo_cluster );
00051 $blobRow = $extDB->selectRow( 'blobs', '*', array( 'blob_id' => $boRow->bo_blob_id ), __METHOD__ );
00052
00053 $num++;
00054 $size = strlen( $blobRow->blob_text );
00055 $totalSize += $size;
00056 $hashes[ sha1( $blobRow->blob_text ) ] = true;
00057 $maxSize = max( $size, $maxSize );
00058 }
00059 unset( $res );
00060
00061 $this->output( "Number of orphans: $num\n" );
00062 if ( $num > 0 ) {
00063 $this->output( "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" .
00064 "Max size: $maxSize\n" .
00065 "Number of unique texts: " . count( $hashes ) . "\n" );
00066 }
00067 }
00068 }
00069
00070 $maintClass = "OrphanStats";
00071 require_once( DO_MAINTENANCE );