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