MediaWiki  master
langmemusage.php
Go to the documentation of this file.
1 <?php
25 
26 require_once __DIR__ . '/../Maintenance.php';
27 
33 class LangMemUsage extends Maintenance {
34 
35  public function __construct() {
36  parent::__construct();
37  $this->addDescription( "Dumb program that tries to get the memory usage\n" .
38  "for each language file" );
39  }
40 
41  public function execute() {
42  if ( !function_exists( 'memory_get_usage' ) ) {
43  $this->fatalError( "You must compile PHP with --enable-memory-limit" );
44  }
45 
46  $memlast = $memstart = memory_get_usage();
47 
48  $this->output( "Base memory usage: $memstart\n" );
49 
50  $languages = array_keys(
51  MediaWikiServices::getInstance()
52  ->getLanguageNameUtils()
53  ->getLanguageNames( null, 'mwfile' )
54  );
55  sort( $languages );
56 
57  foreach ( $languages as $langcode ) {
58  MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $langcode );
59  $memstep = memory_get_usage();
60  $this->output( sprintf( "%12s: %d\n", $langcode, ( $memstep - $memlast ) ) );
61  $memlast = $memstep;
62  }
63 
64  $memend = memory_get_usage();
65 
66  $this->output( ' Total Usage: ' . ( $memend - $memstart ) . "\n" );
67  }
68 }
69 
70 $maintClass = LangMemUsage::class;
71 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:38
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:152
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:480
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:323
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:53
$maintClass
$maintClass
Definition: langmemusage.php:70
LangMemUsage
Maintenance script that tries to get the memory usage for each language file.
Definition: langmemusage.php:33
LangMemUsage\execute
execute()
Do the actual work.
Definition: langmemusage.php:41
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:429
LangMemUsage\__construct
__construct()
Default constructor.
Definition: langmemusage.php:35