Manual:How to debug

This page gives a basic introduction to debugging MediaWiki software.

One of the first things you will notice is that "echo" generally does not work; this is part of the general design. As this is one of the easiest (and arguably best) tools for debugging, there must be another way.

Setting up Debugging
The first thing you need to do is copy the global variable $wgDebugLogFile from the DefaultSettings.php file, to the "LocalSettings.php" file, and name a text file where you want to debug trace output to be put, e.g.:

There are many debug values set in DefaultSettings.php that you can override in LocalSettings.php, e.g.:

In order to profile, you need to copy profiling/debugging constants to the LocalSettings.php file, e.g.:

Setting $wgProfiling will give you basic page timing in $wgDebugLogFile. For more advanced intra-page profiling, you must modify StartProfiler.php.

Note: In MediaWiki 1.8.2, $wgProfilerType is not used at all. You will have to change StartProfiler.php to enable desired profiler. Look in that file for more details.

Tracing execution
Once you've set up your variables as above, you can call the global function wfDebug from wherever in the code you like. The function is found in the "includes/GlobalFunctions.php" file

e.g. Then in the log file you would see:

This is just testing the debug tracing stuff

Profiling
Modify StartProfiler.php to load a more advanced profiler.

Then, wrap any function that you want to investigate as a bottleneck in the following code:

At beginning:

At end:

In the log file you will see profiling info. Change $wgProfileCallTreein LocalSettings.php to true or false for different display formats.

Logging to Database
To log profiling to a database, first you'll have to create a profiling table in your MediaWiki database using the command in the file maintenance/archives/patch-profiling.sql , and set $wgProfileToDatabase = true; in LocalSettings.php

Now go visit some pages (or let your users do so).

Viewing Profile Info
The page profileinfo.php in the MediaWiki root prints profile info from the profiling table. To run it, set $wgEnableProfileInfo = true; in AdminSettings.php. Then, after gathering enough data, visit profileinfo.php to see how much time your profiled code is using and how many times it's being called.