Manual:Profiling

Profiling tracks code execution during a page action and reports back the percentage of total code execution that was spent in any specific function.

Profiling is an advanced task intended for developers and system administrators to track sources of slowness in MediaWiki that should be optimized.

PHP profiling
You can use XHProf, which is available for both HHVM and Zend PHP 5, and provides tracing and profiling. That's how the rest of the PHP world does it.

Starting with MediaWiki 1.29, you can also use tideways, which additionally supports PHP 7.

Tideways also advertises a seemingly proprietary UI to visualize results, but if you follow the [https://github.com/tideways/php-profiler-extension#usage-without-tidewaysio-ui instructions for without the UI], it should be fine.

Installing the   Debian/Ubuntu package also just includes the PHP extension.

Installing XHProf
Use the  command to install XHProf. First, try  , which may give you the following message:

Failed to download pecl/XHProf within preferred state "stable", latest release is version 0.9.4, stability "beta", use "channel://pecl.php.net/XHProf-0.9.4" to install install failed

In that case, use the following command:

The final output may have the following lines:

configuration option "php_ini" is not set to php.ini location You should add "extension=xhprof.so" to php.ini

In that case, add   to your php.ini to enable it.

In OpenSuSE (PHP 5.6.1) the current version causes apache to segfault.

A possible fix is, instead of using the pecl to install the extension, download the source, apply [https://github.com/phacility/xhprof/pull/90/files this patch], [https://secure.php.net/install.peclize.php compile and install] it.

Be sure to restart apache after installing XHProf.

MediaWiki custom profiler
MediaWiki profiling is configured in StartProfiler.php in the root of your wiki.

There's a StartProfiler.sample file there to get you started as well.

In MediaWiki 1.25 profiling was completely rewritten and many settings previous relating to profiling were removed in favor of consolidating them as parameters to $wgProfiler.

Notably, output has been separated from class types.

For documentation about profiling prior to 1.25, see an 1>Special:Permalink/1281616</>|older version of this page.

Here is a typical StartProfiler.php:

Each of these parameters (and more) are described in detail:
 * class
 * 'ProfilerXhprof'. ProfilerXhprof is new in MediaWiki 1.25 and provides an Xhprof-backed profiler that captures profiling data for all functions as well as sub-functional units. Old values such as ProfilerStandard, ProfilerUDP, ProfilerDB, etc do not work. Even if you are using Tideways, still specify the ProfilerXhprof class.


 * output
 * One or more of 'udp', 'text', 'db', 'dump' . Text outputs the information in either HTML comments or after the skin. DB requires the profiling table to be created and stores data on individual profiling runs. UDP is a format send to a udpprofile daemon. Dump produces a dump of the profiling info for use with xhprof GUI (xhprofgui role on Vagrant setup). The output classes available to you by default are ProfilerOutputDb, ProfilerOutputDump, ProfilerOutputStats, ProfilerOutputText, and ProfilerOutputUdp. How that works together with the values 'udp', 'text', 'db', 'dump' is unclear!


 * outputDir
 * Only applies to 'dump' format. Required to specify where the dump files will be stored.


 * perHost
 * Only applies to 'db' format. Whether to store host information with profiling runs.


 * udphost
 * Only applies to 'udp' format. Host/IP to send data to.


 * udpport
 * Only applies to 'udp' format. Port to send data to.


 * udpformat
 * Only applies to 'udp' format. Format string to use. Can usually be left alone.


 * visible
 * Only applies to 'text' format. Whether text is shown after the skin or in an HTML comment.