Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit da46cb4

Browse files
committed
IW-4127 | Add ondemand profiling configuration
1 parent 4b5e793 commit da46cb4

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

LocalSettings.php

+3
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@
291291
*/
292292
require_once "$IP/../config/$wgWikiaEnvironment.php";
293293

294+
/** Load ondemand profiler configuration */
295+
require_once "$IP/includes/wikia/Profiler.php";
296+
294297
/**
295298
* Example read-only settings.
296299
* @see $wgLBFactoryConf

includes/wikia/Profiler.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/**
4+
* Configuration for reporting ondemand profiler data to XHGui
5+
*/
6+
7+
// Disable profiling if no URL was given
8+
if ( !$wgXhguiProfilerUrl ) {
9+
return;
10+
}
11+
12+
function wfStartXhProf(): void {
13+
// Keep it in scope until the end of the request
14+
static $profiler;
15+
16+
global $wgXhguiProfilerUrl, $wgWikiaEnvironment, $wgXhguiUploadTokenDev, $wgXhguiUploadTokenProd;
17+
18+
$config = [
19+
'profiler' => \Xhgui\Profiler\Profiler::PROFILER_TIDEWAYS_XHPROF,
20+
21+
'profiler.flags' => [
22+
\Xhgui\Profiler\ProfilingFlags::CPU,
23+
\Xhgui\Profiler\ProfilingFlags::MEMORY,
24+
\Xhgui\Profiler\ProfilingFlags::NO_BUILTINS,
25+
\Xhgui\Profiler\ProfilingFlags::NO_SPANS,
26+
],
27+
28+
'save.handler' => \Xhgui\Profiler\Profiler::SAVER_UPLOAD,
29+
30+
'save.handler.upload' => [
31+
'uri' => $wgXhguiProfilerUrl,
32+
// The timeout option is in seconds and defaults to 3 if unspecified.
33+
'timeout' => 15,
34+
// the token must match 'upload.token' config in XHGui
35+
'token' => $wgWikiaEnvironment === WIKIA_ENV_DEV ? $wgXhguiUploadTokenDev : $wgXhguiUploadTokenProd,
36+
],
37+
38+
/**
39+
* Determine whether profiler should run.
40+
* @return bool
41+
*/
42+
'profiler.enable' => function (): bool {
43+
return isset( $_GET['forceprofile'] );
44+
},
45+
46+
/**
47+
* Creates a simplified URL given a standard URL.
48+
* Does the following transformations:
49+
*
50+
* - Remove numeric values after =.
51+
*
52+
* @param string $url
53+
* @return string
54+
*/
55+
'profile.simple_url' => function ( $url ) {
56+
return preg_replace( '/=\d+/', '', $url );
57+
},
58+
];
59+
60+
$profiler = new \Xhgui\Profiler\Profiler( $config );
61+
$profiler->start();
62+
}
63+
64+
wfStartXhProf();

includes/wikia/VariablesBase.php

+7
Original file line numberDiff line numberDiff line change
@@ -9422,6 +9422,13 @@
94229422
*/
94239423
$wgEnablePostForumMigrationMessage = false;
94249424

9425+
/**
9426+
* The URL of the XHGUI instance to send profiling data to.
9427+
* If null, ondemand profiling is disabled.
9428+
* @var string|null $wgXhguiProfilerUrl
9429+
*/
9430+
$wgXhguiProfilerUrl = null;
9431+
94259432
/**
94269433
* Expiration timestamp for post forum migration message
94279434
*/

0 commit comments

Comments
 (0)