In Wikimedia production, we profile MediaWiki in two ways:
#### Request profiling: XHProf
* <https://pecl.php.net/package/xhprof> / <https://github.com/phacility/xhprof>
* Originally facebook/xhprof, now phacility/xhprof. Not much activity, but maybe it's just stable. ([issue](https://github.com/phacility/xhprof/issues/81))
* Supports PHP 5.x only, but there's an experimental branch for PHP 7 support.
* HHVM also includes a port of XHProf, which is what we currently use in production.
We use XHProf mainly to get a complete profile (call graph) of a single request. It is opt-in only for ad-hoc requests to the mwdebug pool of servers. See also <https://wikitech.wikimedia.org/wiki/X-Wikimedia-Debug> for details.
Instrumentation code: [wmf-config/profiler.php](https://github.com/wikimedia/operations-mediawiki-config/blob/7ebd5b15a1ec690100eb1f2d3106acf4bf6ffa7d/wmf-config/profiler.php#L87-L153). (Basically, just xhprof_enable/disable.)
The collected data is either appended to the web response (in JS/CSS/HTML comment), or sent to XHGui at <https://performance.wikimedia.org/>.
Before we can switch from HHVM to PHP 7, we need to decide which extension to use for PHP debug profiling.
Options:
* phacility/xhprof:experimental (see [https://github.com/phacility/xhprof/tree/experimental](https://github.com/phacility/xhprof/tree/dab44f76da5c8a0d4f1339f7d2ea2bc42408e8e9)).
* tideways/tideways_xhprof (see <https://github.com/tideways/php-xhprof-extension>).
* ...
#### Sampling profiler: Xenon
* <https://github.com/facebook/hhvm/wiki/Profiling#xenon>
* <https://github.com/brendangregg/FlameGraph>
* <https://performance.wikimedia.org/xenon/>
This is collected from all production servers/requests via the internal HHVM sampling factor and periodically collected from HHVM's parent process.
Instrumentation code: [wmf-config/profiler.php](https://github.com/wikimedia/operations-mediawiki-config/blob/7ebd5b15a1ec690100eb1f2d3106acf4bf6ffa7d/wmf-config/profiler.php#L175-L236).
The Xenon sampling profiler is enabled by default for us in production for all requests. There is no run-time toggle. During request shutdown, we ask HHVM for data. The data is internally buffered by HHVM which means it usually doesn't return anything yet, and then at certain intervals it yields a nice buffer that we then process and send to a Redis queue from which we then produce aggregate log files and flame graphs at <https://performance.wikimedia.org/.
This is HHVM-only, and we'd need an alternate solution for this use case.