-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WP Profiler mu-plugin #42
Open
joemcgill
wants to merge
1
commit into
main
Choose a base branch
from
add/wp-profilier
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"mappings": { | ||
"wp-content/mu-plugins": "./" | ||
}, | ||
"config": { | ||
"WP_DEBUG": false, | ||
"WP_DEBUG_LOG": false, | ||
"WP_DEBUG_DISPLAY": false, | ||
"SCRIPT_DEBUG": false | ||
} | ||
} | ||
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,15 @@ | ||
# WP Profiler | ||
|
||
WP Profiler is an mu-plugin implementation of the [PHP Profiler](https://github.com/perftools/php-profiler) library to make it easier to submit XHProf profiling data to XHGui. | ||
|
||
## Installation instructions | ||
|
||
After installing this mu-plugin in your application of choice, you'll need to run `composer install` to install the PHP Profiler library dependency. Next, you will need to configure the profiler settings in `plugin.php` to connect to your XHGui application. | ||
|
||
To use this as a standalone profiler with WordPress, a sample `.wp-env.json` configuration is included. | ||
|
||
See: https://github.com/WordPress/gutenberg/pull/48147 for the status of having XHProf supported directly in the `@wordpress/env` (i.e., `wp-env`) package. | ||
|
||
## Disclaimer | ||
|
||
This is not an officially supported Google product |
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,5 @@ | ||
{ | ||
"require": { | ||
"perftools/php-profiler": "^1.1" | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
require __DIR__ . '/vendor/autoload.php'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit-pick? Should we have a simple plugin header here? |
||
|
||
use Xhgui\Profiler\Profiler; | ||
use Xhgui\Profiler\ProfilingFlags; | ||
|
||
// Add this block inside some bootstrapper or other "early central point in execution" | ||
try { | ||
/** | ||
* The constructor will throw an exception if the environment | ||
* isn't fit for profiling (extensions missing, other problems) | ||
*/ | ||
$profiler = new Profiler( | ||
array( | ||
'save.handler.upload' => array( | ||
// Use docker's internal networking to connect containers. | ||
'url' => 'http://host.docker.internal:8142/run/import', | ||
), | ||
'profiler.flags' => array( | ||
ProfilingFlags::CPU, | ||
ProfilingFlags::MEMORY, | ||
// Comment out below to include built in PHP functions in profiling output. | ||
ProfilingFlags::NO_BUILTINS, | ||
), | ||
) | ||
); | ||
|
||
// The profiler itself checks whether it should be enabled | ||
// for request (executes lambda function from config) | ||
$profiler->start(); | ||
} catch (Exception $e){ | ||
// throw away or log error about profiling instantiation failure | ||
error_log($e->getMessage()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit-pick: This file doesn't follow WP coding standards (mostly indentation and spacing-wise). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this file here seems a bit out of scope to me as it's for the environment, and the plugin folder itself does not make that environment work.
I think it would be great to implement a simple wp-env configuration in this repository for XHProf so that it's standalone. Of course for XHProf that requires us to first merge your PR WordPress/gutenberg#48147.
My suggestion would be to, instead of a general
plugins
folder and this plugin, add a folder likewp-profiling-env
which includes a basicpackage.json
with the necessary dependencies and scripts to runwp-env
, and then anmu-plugins
folder with thewp-profiler
plugin you have here, as that is most useful as part of that environment.WDYT? We could of course split that work apart, since right now
@wordpress/env
does not yet support the necessary XHProf work, but I think eventually this would be a better outcome, have a standalone solution in here rather than only the MU plugin and require the rest to be set up manually.