Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #33 from panychek/feature/skip-built-in
Browse files Browse the repository at this point in the history
Skipping built-in functions
  • Loading branch information
markstory authored Dec 4, 2019
2 parents 1388249 + abf2bc7 commit 41428d1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
2 changes: 2 additions & 0 deletions config/config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@
//},

'profiler.options' => array(),

'profiler.skip_built_in' => false,
);
46 changes: 36 additions & 10 deletions external/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 41428d1

Please sign in to comment.