WikimediaDebug
WikimediaDebug is a set of tools for debugging and profiling MediaWiki web requests in a production environment.
You can use WikimediaDebug through the accompanying browser extension, or from the command-line using the X-Wikimedia-Debug
header.
The following options exist to configure the backend request:
- Backend selection: force Varnish to pass your request to a specific backend application server.
- Caching behavior: requests that bear an X-Wikimedia-Debug header are always handled as a Varnish cache miss.
- Request profiling: record a trace of request-processing code for performance analysis.
- Verbose logs: enable MediaWiki's verbose debug log group.
- Read-only mode: request a page with MediaWiki set to read-only mode.
Browser usage
Install the extension on supported browsers: Firefox or Chromium/Chrome. It should add a button with a grayscale version of the Wikimedia icon, usually near the upper right corner of the browser window.
To make a web request to one of the debug servers, click the icon, select the right server (if you’re not deploying a change yourself, the deployer should have told you which server to select), then toggle the on/off switch. When the extension is enabled, the button should show an “ON” badge. (See also the screenshot above.)
Command-line usage
Force Varnish to skip the cache and pass request to mwdebug1001.eqiad.wmnet:
$ curl -H 'X-Wikimedia-Debug: backend=mwdebug1001.eqiad.wmnet' https://meta.wikimedia.org/wiki/Main_Page
Same as above, but profile request using Tideways XHProf and log profile to XHGui:
$ curl -H 'X-Wikimedia-Debug: backend=mwdebug1001.eqiad.wmnet; profile' https://meta.wikimedia.org/wiki/Main_Page
Request a page with MediaWiki configured for read-only mode:
$ curl -H 'X-Wikimedia-Debug: backend=mwdebug1001.eqiad.wmnet; readonly' https://meta.wikimedia.org/wiki/Main_Page
Staging changes
This section will walk you through a common X-Wikimedia-Debug debugging workflow.
It worked on your machine. It worked on the Beta Cluster. And the unit tests pass. But will it work in production? You can reduce the risk of unexpected breakage by deploying your change to a debugging server in production and using the X-Wikimedia-Debug header to verify its behavior.
Follow the instructions on How to deploy code, but stop after you have completed step 2 ("Get the code on the deployment host"). Now sync your change to one of the debug backends in a new tap by SSHing into it and running scap pull
:
you@laptop:~$ ssh mwdebug1001.eqiad.wmnet
you@mwdebug1001:~$ scap pull
Now use the X-Wikimedia-Debug extension to enable header injection, selecting the same backend you just synced your code to. Your requests will be routed to the backend on which you staged your changes, allowing you to verify that is working correctly.
Request profiling
Setting the profile
attribute in the X-Wikimedia-Debug header will use XHProf to capture a profile and send it to XHGui. If you are using the browser extension, there will be a link in the page footer with the label Profiling Data. Clicking or tapping on it will take you directly to a list of profiles matching your Request ID. Then click on the method (e.g. "GET") or timestamp link to show the recorded profile.
The Firefox add-on adds a menu item named X-Wikimedia-Debug profile
to the context menu, shown when you right-click on the page body.
XHGui feature:
- Overview dashboard (e.g. listing functions that used the most time and/or most memory).
- Complete call tree with timing, counts, sub/parent for each function.
- Callgraph visualisation.
- and more...
To get an idea of what XHGui provides, view this example profile.
Plaintext request profile
In addition to obtaining a profiler via XHGui (see above), it is also possible to get a plaintext-format profile directly from the web server.
Enable X-Wikimedia-Debug with the forceprofile
attribute ("Inline profile" option). On any MediaWiki web request (including index.php, api.php, and load.php), this will result in a plain text profile being appended to the web response.
With an X-Wikimedia-Debug header present, view this example request. Toward the end of the response is a call-graph summary, that should look roughly like this:
/* 100.00% 1437.125 1 - main() 87.21% 1253.268 1 - ResourceLoader::respond 79.31% 1139.756 1509 - ResourceLoaderModule::getVersionHash 77.88% 1119.292 3 - ResourceLoader::getCombinedVersion ..
Example using cURL:
# Production $ curl -H 'X-Wikimedia-Debug: 1; forceprofile' 'https://test.wikipedia.org/w/load.php?modules=startup&only=scripts&raw=1' # Beta Cluster $ curl -H 'X-Wikimedia-Debug: 1; forceprofile' 'https://en.wikipedia.beta.wmflabs.org/w/load.php?modules=startup&only=scripts&raw=1'
For maintenance scripts, this can be triggered using the --profiler=text
option. For both web requests profiling and CLI profiling, the debug tools are only installed on mwdebug servers, so be sure to run mwscript from an mwdebug server (in Beta Cluster, any MW server will do).
mwdebug:~$ mwscript showJobs.php --wiki testwiki --profiler text 0 <!-- 100.00% 282.967 1 - main() 89.56% 253.419 1 - section.Setup.php 57.12% 161.627 139 - AutoLoader::autoload 49.59% 140.324 1 - ExtensionRegistry::loadFromQueue ..
Debug logging
![]() | This feature requires a WMF or Volunteer NDA Wikimedia developer account. |
Setting the log
attribute in the X-Wikimedia-Debug header will cause MediaWiki to be maximally verbose, recording all log messages on all channels (regardless of whether or not they are otherwise enabled in wmf-config).
These messages will end up in Logstash at https://logstash.wikimedia.org/app/kibana#/dashboard/mwdebug and in /srv/mw-log/XWikimediaDebug.log
on mwlog1001. See Logs#mw-log for more information.
To view the logs of a specific web request only, the browser extension adds a "Debug Logs" link in the footer on any wiki as well, which opens goes to Logstash with a filter for the request ID of the current page view. You can also construct this URL manually, by typing the following code into your browser's JavaScript console:
'https://logstash.wikimedia.org/#/dashboard/elasticsearch/request-id?id=' + mw.config.get('wgRequestId');
Available backends
The following application servers are reserved for X-Wikimedia-Debug use:
- mwdebug1001.eqiad.wmnet
- mwdebug1002.eqiad.wmnet
- mwdebug2001.codfw.wmnet
- mwdebug2002.codfw.wmnet
Browser extensions
Limitations
X-Wikimedia-Debug does not currently work on the Wikitech wiki, which is served by servers separated from the rest of the Wikimedia Foundation production cluster. Try it on Wikipedia instead!
See also
- Source code
- Issue tracker (Phabricator)
- WikimediaDebug v2 blogpost
- Debugging in production: Info on how to push code to a debug backend and for testing non-HTTP code (e.g. maintenance scripts)
- XHGui: a few notes on XHGui as set up at Wikimedia
- Pywikibot extra_headers option