MediaWiki  1.34.0
langmemusage.php
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/../Maintenance.php';
26 require_once __DIR__ . '/languages.inc';
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  $langtool = new Languages();
47  $memlast = $memstart = memory_get_usage();
48 
49  $this->output( "Base memory usage: $memstart\n" );
50 
51  foreach ( $langtool->getLanguages() as $langcode ) {
52  Language::factory( $langcode );
53  $memstep = memory_get_usage();
54  $this->output( sprintf( "%12s: %d\n", $langcode, ( $memstep - $memlast ) ) );
55  $memlast = $memstep;
56  }
57 
58  $memend = memory_get_usage();
59 
60  $this->output( ' Total Usage: ' . ( $memend - $memstart ) . "\n" );
61  }
62 }
63 
64 $maintClass = LangMemUsage::class;
65 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:504
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
$maintClass
$maintClass
Definition: langmemusage.php:64
LangMemUsage
This is a command line script.
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:453
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:217
LangMemUsage\__construct
__construct()
Default constructor.
Definition: langmemusage.php:35