generated from ddev/ddev-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from stasadev/20241028_stasadev_xhprof_cpu
Add XHPROF_FLAGS_CPU for xhprof, cleanup for `ddev get`
- Loading branch information
Showing
3 changed files
with
69 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
name: ddev-buggregator | ||
|
||
project_files: | ||
- docker-compose.buggregator.yaml | ||
- docker-compose.buggregator.yaml | ||
- xhprof/xhprof_prepend.php | ||
|
||
# needed for xhprof/xhprof_prepend.php | ||
ddev_version_constraint: '>= v1.23.2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
// #ddev-generated | ||
|
||
// Bugreggator throws an error with only xhprof_enable(XHPROF_FLAGS_MEMORY) (DDEV default). | ||
// This file uses xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY) to make it work. | ||
// See https://github.com/buggregator/server/issues/230 | ||
|
||
// If you want to take over and customize this file, remove the line above | ||
// And check this file in. | ||
|
||
// This file is used by `ddev xhprof on` and determines the behavior | ||
// of xhprof when it is enabled. It is mounted into the ddev-webserver container | ||
// as /usr/local/bin/xhprof/xhprof_prepend.php | ||
|
||
// It can be customized for particular sites or for particular CMS versions. | ||
// Some suggestions and examples are provided below. | ||
|
||
$uri = "none"; | ||
if (!empty($_SERVER) && array_key_exists('REQUEST_URI', $_SERVER)) { | ||
$uri = $_SERVER['REQUEST_URI']; | ||
} | ||
|
||
// Enable xhprof profiling if we're not on an xhprof page | ||
if (extension_loaded('xhprof') && strpos($uri, '/xhprof') === false) { | ||
// If this is too much information, just use xhprof_enable(), which shows CPU only | ||
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); | ||
register_shutdown_function('xhprof_completion'); | ||
} | ||
|
||
// Write to the xhprof_html output and latest on completion | ||
function xhprof_completion() | ||
{ | ||
$xhprof_link_dir = "/var/xhprof/xhprof_html/latest/"; | ||
|
||
$xhprof_data = xhprof_disable(); | ||
$appNamespace = "ddev"; | ||
include_once '/var/xhprof/xhprof_lib/utils/xhprof_lib.php'; | ||
include_once '/var/xhprof/xhprof_lib/utils/xhprof_runs.php'; | ||
|
||
$xhprof_runs = new XHProfRuns_Default(); | ||
$run_id = $xhprof_runs->save_run($xhprof_data, $appNamespace); | ||
|
||
// Uncomment to append profile link to the page (and remove the ddev generated first line) | ||
// append_profile_link($run_id, $appNamespace); | ||
} | ||
|
||
// If invoked, this will append a profile link to the output HTML | ||
// This works on some CMSs, like Drupal 7. It does not work on Drupal8/9 | ||
// and can have unwanted side-effects on TYPO3 | ||
function append_profile_link($run_id, $appNamespace) | ||
{ | ||
$base_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]/xhprof/"; | ||
|
||
$profiler_url = sprintf('%sindex.php?run=%s&source=%s', $base_link, $run_id, $appNamespace); | ||
echo '<div id="xhprof"><a href="' . $profiler_url . '" target="_blank">xhprof profiler output</a></div>'; | ||
} |