From abf2bc74233948dcc9524b57e5f38ac4518f072c Mon Sep 17 00:00:00 2001 From: Igor Panychek Date: Tue, 3 Dec 2019 20:25:12 +0400 Subject: [PATCH] Add the 'profiler.skip_built_in' option --- config/config.default.php | 2 ++ external/header.php | 46 ++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/config/config.default.php b/config/config.default.php index 558fe21..3fe4c96 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -68,4 +68,6 @@ //}, 'profiler.options' => array(), + + 'profiler.skip_built_in' => false, ); diff --git a/external/header.php b/external/header.php index 76c2609..b604b34 100644 --- a/external/header.php +++ b/external/header.php @@ -43,15 +43,18 @@ * Adds more information about function calls (this information is not currently used by XHGui) */ -/* Tideways support - * The tideways extension is a fork of xhprof. See https://github.com/tideways/php-profiler-extension +/* Tideways XHProf support + * The tideways_xhprof extension is a fork of xhprof. See https://github.com/tideways/php-profiler-extension * * It works on PHP 5.5+ and PHP 7 and improves on the ancient timing algorithms used by XHProf using * more modern Linux APIs to collect high performance timing data. * - * The TIDEWAYS_* constants are similar to the ones by XHProf, however you need to disable timeline + * v4 (tideways): The TIDEWAYS_* constants are similar to the ones by XHProf, however you need to disable timeline * mode when using XHGui, because it only supports callgraphs and we can save the overhead. Use * TIDEWAYS_FLAGS_NO_SPANS to disable timeline mode. + * + * v5 (tideways_xhprof): The TIDEWAYS_XHPROF_* constants are similar to the ones by XHProf, however you cannot use + * additional TIDEWAYS_XHPROF_FLAGS_MEMORY_* flags since XHGui does not support the extra data that they produce. */ // this file should not - under no circumstances - interfere with any other application @@ -92,19 +95,42 @@ $_SERVER['REQUEST_TIME_FLOAT'] = microtime(true); } +$skipBuiltIn = Xhgui_Config::read('profiler.skip_built_in'); $options = Xhgui_Config::read('profiler.options'); + if (extension_loaded('uprofiler')) { - uprofiler_enable(UPROFILER_FLAGS_CPU | UPROFILER_FLAGS_MEMORY, $options); + $flags = UPROFILER_FLAGS_CPU | UPROFILER_FLAGS_MEMORY; + + if ($skipBuiltIn) { + $flags |= UPROFILER_FLAGS_NO_BUILTINS; + } + + uprofiler_enable($flags, $options); } else if (extension_loaded('tideways')) { - tideways_enable(TIDEWAYS_FLAGS_CPU | TIDEWAYS_FLAGS_MEMORY | TIDEWAYS_FLAGS_NO_SPANS, $options); + $flags = TIDEWAYS_FLAGS_CPU | TIDEWAYS_FLAGS_MEMORY | TIDEWAYS_FLAGS_NO_SPANS; + + if ($skipBuiltIn) { + $flags |= TIDEWAYS_FLAGS_NO_BUILTINS; + } + + tideways_enable($flags, $options); } elseif (extension_loaded('tideways_xhprof')) { - tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_CPU | TIDEWAYS_XHPROF_FLAGS_MEMORY); + $flags = TIDEWAYS_XHPROF_FLAGS_CPU | TIDEWAYS_XHPROF_FLAGS_MEMORY; + + if ($skipBuiltIn) { + $flags |= TIDEWAYS_XHPROF_FLAGS_NO_BUILTINS; + } + + tideways_xhprof_enable($flags); } else { - if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 4) { - xhprof_enable(XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_NO_BUILTINS, $options); - } else { - xhprof_enable(XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY, $options); + $flags = XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY; + + $isFaulted = (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 4); + if ($skipBuiltIn || $isFaulted) { + $flags |= XHPROF_FLAGS_NO_BUILTINS; } + + xhprof_enable($flags, $options); } register_shutdown_function(