Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <tsteur@users.noreply.github.com>2018-11-28 08:30:36 +0300
committerdiosmosis <diosmosis@users.noreply.github.com>2018-11-28 08:30:36 +0300
commit504196e1e0410fbbfc4e25210bfbecdec8af781a (patch)
tree5c671af463a0ff189d9210df5d0274ed5f88d26c /core/Profiler.php
parent734f06480b1b6b104af191cb2c8beab0f52e7ee9 (diff)
Support tideways xhprof profiler (#13667)
XHProf isn't working so well anymore for PHP7.X so be good to support tideways profiler https://github.com/tideways/php-xhprof-extension
Diffstat (limited to 'core/Profiler.php')
-rw-r--r--core/Profiler.php32
1 files changed, 26 insertions, 6 deletions
diff --git a/core/Profiler.php b/core/Profiler.php
index 0a9ad2b0b2..850660d8cb 100644
--- a/core/Profiler.php
+++ b/core/Profiler.php
@@ -209,12 +209,19 @@ class Profiler
return;
}
- if (!function_exists('xhprof_enable')) {
+ $hasXhprof = function_exists('xhprof_enable');
+ $hasTidewaysXhprof = function_exists('tideways_xhprof_enable');
+
+ if (!$hasXhprof && !$hasTidewaysXhprof) {
$xhProfPath = PIWIK_INCLUDE_PATH . '/vendor/facebook/xhprof/extension/modules/xhprof.so';
throw new Exception("Cannot find xhprof_enable, make sure to 1) install xhprof: run 'composer install --dev' and build the extension, and 2) add 'extension=$xhProfPath' to your php.ini.");
}
$outputDir = ini_get("xhprof.output_dir");
+ if (!$outputDir && $hasTidewaysXhprof) {
+ $outputDir = sys_get_temp_dir();
+ }
+
if (empty($outputDir)) {
throw new Exception("The profiler output dir is not set. Add 'xhprof.output_dir=...' to your php.ini.");
}
@@ -239,12 +246,25 @@ class Profiler
self::setProfilingRunIds(array());
}
- xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
+ if (function_exists('xhprof_enable')) {
+ xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
+ } elseif (function_exists('tideways_xhprof_enable')) {
+ tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_MEMORY | TIDEWAYS_XHPROF_FLAGS_CPU);
+ }
- register_shutdown_function(function () use ($profilerNamespace, $mainRun) {
- $xhprofData = xhprof_disable();
- $xhprofRuns = new XHProfRuns_Default();
- $runId = $xhprofRuns->save_run($xhprofData, $profilerNamespace);
+ register_shutdown_function(function () use ($profilerNamespace, $mainRun, $outputDir) {
+ if (function_exists('xhprof_disable')) {
+ $xhprofData = xhprof_disable();
+ $xhprofRuns = new XHProfRuns_Default();
+ $runId = $xhprofRuns->save_run($xhprofData, $profilerNamespace);
+ } elseif (function_exists('tideways_xhprof_disable')) {
+ $xhprofData = tideways_xhprof_disable();
+ $runId = uniqid();
+ file_put_contents(
+ $outputDir . DIRECTORY_SEPARATOR . $runId . '.' . $profilerNamespace . '.xhprof',
+ serialize($xhprofData)
+ );
+ }
if (empty($runId)) {
die('could not write profiler run');