MediaWiki  1.23.8
profileinfo.php
Go to the documentation of this file.
1 <?php
28 ini_set( 'zlib.output_compression', 'off' );
29 
30 $wgEnableProfileInfo = $wgProfileToDatabase = false;
31 require __DIR__ . '/includes/WebStart.php';
32 
33 header( 'Content-Type: text/html; charset=utf-8' );
34 
35 ?>
36 <!DOCTYPE html>
37 <html>
38 <head>
39  <meta charset="UTF-8">
40  <title>Profiling data</title>
41  <style>
42  /* noc.wikimedia.org/base.css */
43 
44  * {
45  margin: 0;
46  padding: 0;
47  }
48 
49  body {
50  padding: 0.5em 1em;
51  background: #fff;
52  font: 14px/1.6 sans-serif;
53  color: #333;
54  }
55 
56  p, ul, ol, table {
57  margin: 0.5em 0;
58  }
59 
60  a {
61  color: #0645AD;
62  text-decoration: none;
63  }
64 
65  a:hover {
66  text-decoration: underline;
67  }
68 
79  table {
80  max-width: 100%;
81  background-color: transparent;
82  border-collapse: collapse;
83  border-spacing: 0;
84  }
85 
86  .table {
87  width: 100%;
88  margin-bottom: 20px;
89  }
90 
91  .table th,
92  .table td {
93  padding: 0.1em;
94  text-align: left;
95  vertical-align: top;
96  border-top: 1px solid #ddd;
97  }
98 
99  .table th {
100  font-weight: bold;
101  }
102 
103  .table thead th {
104  vertical-align: bottom;
105  }
106 
107  .table thead:first-child tr:first-child th,
108  .table thead:first-child tr:first-child td {
109  border-top: 0;
110  }
111 
112  .table tbody + tbody {
113  border-top: 2px solid #ddd;
114  }
115 
116  .table-condensed th,
117  .table-condensed td {
118  padding: 4px 5px;
119  }
120 
121  .table-striped tbody tr:nth-child(odd) td,
122  .table-striped tbody tr:nth-child(odd) th {
123  background-color: #f9f9f9;
124  }
125 
126  .table-hover tbody tr:hover td,
127  .table-hover tbody tr:hover th {
128  background-color: #f5f5f5;
129  }
130 
131  hr {
132  margin: 20px 0;
133  border: 0;
134  border-top: 1px solid #eee;
135  border-bottom: 1px solid #fff;
136  }
137  </style>
138 </head>
139 <body>
140 <?php
141 
142 if ( !$wgEnableProfileInfo ) {
143  echo '<p>Disabled</p>'
144  . '</body></html>';
145  exit( 1 );
146 }
147 
149 
150 if ( !$dbr->tableExists( 'profiling' ) ) {
151  echo '<p>No <code>profiling</code> table exists, so we can\'t show you anything.</p>'
152  . '<p>If you want to log profiling data, enable <code>$wgProfileToDatabase</code>'
153  . ' in your LocalSettings.php and run <code>maintenance/update.php</code> to'
154  . ' create the profiling table.'
155  . '</body></html>';
156  exit( 1 );
157 }
158 
160 if ( isset( $_REQUEST['expand'] ) ) {
161  foreach ( explode( ',', $_REQUEST['expand'] ) as $f ) {
162  $expand[$f] = true;
163  }
164 }
165 
167  var $name;
168  var $count;
169  var $time;
171 
173 
174  function __construct( $name, $count, $time, $memory ) {
175  $this->name = $name;
176  $this->count = $count;
177  $this->time = $time;
178  $this->memory = $memory;
179  $this->children = array();
180  }
181 
182  function add_child( $child ) {
183  $this->children[] = $child;
184  }
185 
186  function display( $expand, $indent = 0.0 ) {
187  usort( $this->children, 'compare_point' );
188 
189  $ex = isset( $expand[$this->name()] );
190 
191  $anchor = str_replace( '"', '', $this->name() );
192 
193  if ( !$ex ) {
194  if ( count( $this->children ) ) {
195  $url = getEscapedProfileUrl( false, false, $expand + array( $this->name() => true ) );
196  $extet = " <a id=\"{$anchor}\" href=\"{$url}#{$anchor}\">[+]</a>";
197  } else {
198  $extet = '';
199  }
200  } else {
201  $e = array();
202  foreach ( $expand as $name => $ep ) {
203  if ( $name != $this->name() ) {
204  $e += array( $name => $ep );
205  }
206  }
207  $url = getEscapedProfileUrl( false, false, $e );
208  $extet = " <a id=\"{$anchor}\" href=\"{$url}#{$anchor}\">[–]</a>";
209  }
210  ?>
211  <tr>
212  <th>
213  <div style="margin-left: <?php echo (int)$indent; ?>em;">
214  <?php echo htmlspecialchars( str_replace( ',', ', ', $this->name() ) ) . $extet ?>
215  </div>
216  </th>
217  <td class="mw-profileinfo-timep"><?php echo @wfPercent( $this->time() / self::$totaltime * 100 ); ?></td>
218  <td class="mw-profileinfo-memoryp"><?php echo @wfPercent( $this->memory() / self::$totalmemory * 100 ); ?></td>
219  <td class="mw-profileinfo-count"><?php echo $this->count(); ?></td>
220  <td class="mw-profileinfo-cpr"><?php echo round( sprintf( '%.2f', $this->callsPerRequest() ), 2 ); ?></td>
221  <td class="mw-profileinfo-tpc"><?php echo round( sprintf( '%.2f', $this->timePerCall() ), 2 ); ?></td>
222  <td class="mw-profileinfo-mpc"><?php echo round( sprintf( '%.2f', $this->memoryPerCall() / 1024 ), 2 ); ?></td>
223  <td class="mw-profileinfo-tpr"><?php echo @round( sprintf( '%.2f', $this->time() / self::$totalcount ), 2 ); ?></td>
224  <td class="mw-profileinfo-mpr"><?php echo @round( sprintf( '%.2f', $this->memory() / self::$totalcount / 1024 ), 2 ); ?></td>
225  </tr>
226  <?php
227  if ( $ex ) {
228  foreach ( $this->children as $child ) {
229  $child->display( $expand, $indent + 2 );
230  }
231  }
232  }
233 
234  function name() {
235  return $this->name;
236  }
237 
238  function count() {
239  return $this->count;
240  }
241 
242  function time() {
243  return $this->time;
244  }
245 
246  function memory() {
247  return $this->memory;
248  }
249 
250  function timePerCall() {
251  return @( $this->time / $this->count );
252  }
253 
254  function memoryPerCall() {
255  return @( $this->memory / $this->count );
256  }
257 
258  function callsPerRequest() {
259  return @( $this->count / self::$totalcount );
260  }
261 
262  function timePerRequest() {
263  return @( $this->time / self::$totalcount );
264  }
265 
266  function memoryPerRequest() {
267  return @( $this->memory / self::$totalcount );
268  }
269 
270  function fmttime() {
271  return sprintf( '%5.02f', $this->time );
272  }
273 };
274 
276  global $sort;
277  switch ( $sort ) {
278  case 'name':
279  return strcmp( $a->name(), $b->name() );
280  case 'time':
281  return $a->time() > $b->time() ? -1 : 1;
282  case 'memory':
283  return $a->memory() > $b->memory() ? -1 : 1;
284  case 'count':
285  return $a->count() > $b->count() ? -1 : 1;
286  case 'time_per_call':
287  return $a->timePerCall() > $b->timePerCall() ? -1 : 1;
288  case 'memory_per_call':
289  return $a->memoryPerCall() > $b->memoryPerCall() ? -1 : 1;
290  case 'calls_per_req':
291  return $a->callsPerRequest() > $b->callsPerRequest() ? -1 : 1;
292  case 'time_per_req':
293  return $a->timePerRequest() > $b->timePerRequest() ? -1 : 1;
294  case 'memory_per_req':
295  return $a->memoryPerRequest() > $b->memoryPerRequest() ? -1 : 1;
296  }
297 }
298 
299 $sorts = array( 'time', 'memory', 'count', 'calls_per_req', 'name',
300  'time_per_call', 'memory_per_call', 'time_per_req', 'memory_per_req' );
301 $sort = 'time';
302 if ( isset( $_REQUEST['sort'] ) && in_array( $_REQUEST['sort'], $sorts ) ) {
303  $sort = $_REQUEST['sort'];
304 }
305 
306 $res = $dbr->select( 'profiling', '*', array(), 'profileinfo.php', array( 'ORDER BY' => 'pf_name ASC' ) );
307 
308 if ( isset( $_REQUEST['filter'] ) ) {
309  $filter = $_REQUEST['filter'];
310 } else {
311  $filter = '';
312 }
313 
314 ?>
315 <form method="get" action="profileinfo.php">
316  <p>
317  <input type="text" name="filter" value="<?php echo htmlspecialchars( $filter ); ?>">
318  <input type="hidden" name="sort" value="<?php echo htmlspecialchars( $sort ); ?>">
319  <input type="hidden" name="expand" value="<?php echo htmlspecialchars( implode( ",", array_keys( $expand ) ) ); ?>">
320  <input type="submit" value="Filter">
321  </p>
322 </form>
323 
324 <table class="mw-profileinfo-table table table-striped table-hover">
325  <thead>
326  <tr>
327  <th><a href="<?php echo getEscapedProfileUrl( false, 'name' ); ?>">Name</a></th>
328  <th><a href="<?php echo getEscapedProfileUrl( false, 'time' ); ?>">Time (%)</a></th>
329  <th><a href="<?php echo getEscapedProfileUrl( false, 'memory' ); ?>">Memory (%)</a></th>
330  <th><a href="<?php echo getEscapedProfileUrl( false, 'count' ); ?>">Count</a></th>
331  <th><a href="<?php echo getEscapedProfileUrl( false, 'calls_per_req' ); ?>">Calls/req</a></th>
332  <th><a href="<?php echo getEscapedProfileUrl( false, 'time_per_call' ); ?>">ms/call</a></th>
333  <th><a href="<?php echo getEscapedProfileUrl( false, 'memory_per_call' ); ?>">kb/call</a></th>
334  <th><a href="<?php echo getEscapedProfileUrl( false, 'time_per_req' ); ?>">ms/req</a></th>
335  <th><a href="<?php echo getEscapedProfileUrl( false, 'memory_per_req' ); ?>">kb/req</a></th>
336  </tr>
337  </thead>
338  <tbody>
339  <?php
343 
344  function getEscapedProfileUrl( $_filter = false, $_sort = false, $_expand = false ) {
345  global $filter, $sort, $expand;
346 
347  if ( $_expand === false ) {
348  $_expand = $expand;
349  }
350 
351  return htmlspecialchars(
352  '?' .
354  'filter' => $_filter ? $_filter : $filter,
355  'sort' => $_sort ? $_sort : $sort,
356  'expand' => implode( ',', array_keys( $_expand ) )
357  ) )
358  );
359  }
360 
363  $sqltotal = 0.0;
364 
365  $last = false;
366  foreach ( $res as $o ) {
367  $next = new profile_point( $o->pf_name, $o->pf_count, $o->pf_time, $o->pf_memory );
368  if ( $next->name() == '-total' ) {
369  profile_point::$totaltime = $next->time();
370  profile_point::$totalcount = $next->count();
371  profile_point::$totalmemory = $next->memory();
372  }
373  if ( $last !== false ) {
374  if ( preg_match( '/^' . preg_quote( $last->name(), '/' ) . '/', $next->name() ) ) {
375  $last->add_child( $next );
376  continue;
377  }
378  }
379  $last = $next;
380  if ( preg_match( '/^query: /', $next->name() ) || preg_match( '/^query-m: /', $next->name() ) ) {
381  $sqltotal += $next->time();
382  $queries[] = $next;
383  } else {
384  $points[] = $next;
385  }
386  }
387 
388  $s = new profile_point( 'SQL Queries', 0, $sqltotal, 0, 0 );
389  foreach ( $queries as $q ) {
390  $s->add_child( $q );
391  }
392  $points[] = $s;
393 
394  usort( $points, 'compare_point' );
395 
396  foreach ( $points as $point ) {
397  if ( strlen( $filter ) && !strstr( $point->name(), $filter ) ) {
398  continue;
399  }
400 
401  $point->display( $expand );
402  }
403  ?>
404  </tbody>
405 </table>
406 <hr>
407 <p>Total time: <code><?php printf( '%5.02f', profile_point::$totaltime ); ?></code></p>
408 
409 <p>Total memory: <code><?php printf( '%5.02f', profile_point::$totalmemory / 1024 ); ?></code></p>
410 <hr />
411 </body>
412 </html>
wfPercent
wfPercent( $nr, $acc=2, $round=true)
Definition: GlobalFunctions.php:2657
profile_point\callsPerRequest
callsPerRequest()
Definition: profileinfo.php:258
data
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of data
Definition: hooks.txt:6
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
profile_point\$name
$name
Definition: profileinfo.php:167
compare_point
compare_point(profile_point $a, profile_point $b)
Definition: profileinfo.php:275
$last
$last
Definition: profileinfo.php:365
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
$sqltotal
$sqltotal
Definition: profileinfo.php:363
$f
$f
Definition: UtfNormalTest2.php:38
profile_point\__construct
__construct( $name, $count, $time, $memory)
Definition: profileinfo.php:174
profile_point\timePerRequest
timePerRequest()
Definition: profileinfo.php:262
profile_point\$totalmemory
static $totalmemory
Definition: profileinfo.php:172
profile_point\$time
$time
Definition: profileinfo.php:169
$wgEnableProfileInfo
$wgEnableProfileInfo
Definition: profileinfo.php:30
$dbr
if(! $wgEnableProfileInfo) $dbr
Definition: profileinfo.php:148
profile_point\$count
$count
Definition: profileinfo.php:168
$s
foreach( $res as $o) $s
Definition: profileinfo.php:388
profile_point\$children
$children
Definition: profileinfo.php:170
memory
MediaWiki has optional support for a high distributed memory object caching system For general information on but for a larger site with heavy like it should help lighten the load on the database servers by caching data and objects in memory
Definition: memcached.txt:10
profile_point\$totaltime
static $totaltime
Definition: profileinfo.php:172
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
profile_point\memoryPerCall
memoryPerCall()
Definition: profileinfo.php:254
$expand
if(! $dbr->tableExists( 'profiling')) $expand
Definition: profileinfo.php:159
profile_point\display
display( $expand, $indent=0.0)
Definition: profileinfo.php:186
table
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs table
Definition: deferred.txt:11
$sorts
$sorts
Definition: profileinfo.php:299
$points
$points
Definition: profileinfo.php:361
getEscapedProfileUrl
getEscapedProfileUrl( $_filter=false, $_sort=false, $_expand=false)
Definition: profileinfo.php:344
profile_point\memory
memory()
Definition: profileinfo.php:246
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
form
null means default in associative array form
Definition: hooks.txt:1530
profile_point\$totalcount
static $totalcount
Definition: profileinfo.php:172
bold
published in in Madrid In the first edition of the Vocabolario for was published In in Rotterdam was the Dictionnaire Universel ! html< p > The first monolingual dictionary written in a Romance language was< i > Sebastián Covarrubias</i >< i > Tesoro de la lengua castellana o published in in Madrid In the first edition of the< i > Vocabolario dell< a href="/index.php?title=Accademia_della_Crusca&amp;action=edit&amp;redlink=1" class="new" title="Accademia della Crusca (page does not exist)"> Accademia della Crusca</a ></i > for was published In in Rotterdam was the< i > Dictionnaire Universel</i ></p > ! end ! test Italics and bold
Definition: parserTests.txt:396
$sort
$sort
Definition: profileinfo.php:301
$res
if(isset( $_REQUEST['sort']) &&in_array( $_REQUEST['sort'], $sorts)) $res
Definition: profileinfo.php:306
profile_point
Definition: profileinfo.php:166
action
action
Definition: parserTests.txt:378
profile_point\timePerCall
timePerCall()
Definition: profileinfo.php:250
profile_point\memoryPerRequest
memoryPerRequest()
Definition: profileinfo.php:266
profile_point\fmttime
fmttime()
Definition: profileinfo.php:270
profile_point\name
if( $ex) name()
Definition: profileinfo.php:234
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
profile_point\count
count()
Definition: profileinfo.php:238
type
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition: postgres.txt:22
color
in the sidebar</td >< td > font color
Definition: All_system_messages.txt:425
profile_point\time
time()
Definition: profileinfo.php:242
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
name
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
Definition: design.txt:12
profile_point\add_child
add_child( $child)
Definition: profileinfo.php:182
code
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of or an object and a method hook function The function part of a third party developers and administrators to define code that will be run at certain points in the mainline code
Definition: hooks.txt:23
$e
if( $useReadline) $e
Definition: eval.php:66
href
shown</td >< td > a href
Definition: All_system_messages.txt:2674
$queries
$queries
Definition: profileinfo.php:362
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes two arrays as input, and returns a CGI-style string, e.g.
Definition: GlobalFunctions.php:367