티스토리 수익 글 보기
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add initial XHProf support to wp-env #48147
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
base: trunk
Are you sure you want to change the base?
Add initial XHProf support to wp-env #48147
Conversation
This updates the configuration scripts to support passing a new --xdebug flag to wp env start, which will install and configure XHProf support to the WordPress environment. To enable profiling, you'll need to edit the wp-config.php file to include the following code where the `wp-settings.php` file is included: ```php // start profiling xhprof_enable(); /** Sets up WordPress vars and included files. */ require_once ABSPATH . 'wp-settings.php'; // stop profiler $xhprof_data = xhprof_disable(); // display raw xhprof data for the profiler run print_r($xhprof_data); ``` For more info about how to configure XHProf, see: https://github.com/longxinH/xhprof. Also see the original Facebook docs for XHProf here: http://web.archive.org/web/20110514095512/http://mirror.facebook.net/facebook/xhprof/doc.html.
packages/env/lib/init-config.js
Outdated
| // config has changed when only the xdebug param has changed. This is needed | ||
| // so that Docker will rebuild the image whenever the xdebug flag changes. | ||
| // config has changed when only the xdebug or xhprof params have changed. This | ||
| // is needed so that Docker will rebuild the image whenever the either flag changes. |
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.
| // is needed so that Docker will rebuild the image whenever the either flag changes. | |
| // is needed so that Docker will rebuild the image whenever either flag changes. |
| args.option( 'xhprof', { | ||
| describe: | ||
| 'Enables XHProf. If not passed, XHProf is turned off.', | ||
| type: 'string', |
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.
If there’s only one XHProf mode, I think this should be a boolean instead.
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.
XHProf does support different configuration modes, though I’m unsure how important it is to support that config through the CLI versus as an option passed to the profiler when it’s loaded. See: https://github.com/joemcgill/wp-profiler/blob/trunk/plugin.php#L19-L24 for an example of how these flags can be set via code rather than configuration.
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.
Good point. I think if people will have to configure this code in the first place, we don’t need to support setting the options via flags. If we did find a way to automate the wp-config.php changes, then it’d make sense to add them to the flags.
packages/env/lib/init-config.js
Outdated
| } | ||
|
|
||
| // @todo: test compat. | ||
| if ( config.xhprof !== 'off' ) { |
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.
If the xhprof flag is a boolean (see above), this could be written like config.xhprof === true
|
Neat! Does this extension support most PHP versions? I know for Xdebug, we had to disable it for some PHP versions it didn’t support. |
|
Thanks for the quick look, @noahtallen! This is working, but can surely be simplified a bit so I decided to open this early for discussion. I’ll follow up with your comments above. One thing that I’ve been debating is whether we should try to include support for XHGui directly with this PR, or if it is best to leave that to individual developers to use whatever GUI options they find most useful. I’d value your input on that question. |
|
According to the GitHub repo for the official XHProf PECL package, it currently supports PHP versions 7.2–8.2. |
I’m not mainly a PHP developer, so I haven’t used XHProf before. Is the GUI something most developers would expect to have available? |
I think including it directly would make the developer experience much easier, since profiling is really not super helpful without some way to read/analyze the data that’s collected. There are other SaaS companies that have XHProf compatible/derivative GUIs as part of their service that could be used, but bundling XHGui would be a great help for someone wanting to get up and running without much extra config. If we were to do so, I think it would require modifying the docker config to create two new containers: One for the XHGui application, and another for the MongoDB backend that it requires. The XHGui repo includes a docker-compose.yml file that could be used as part of the setup, but I may need some guidance on how to best approach that part in the context of the |
|
It should be relatively easy to update the docker compose file. It’s similarly generated in JS, so you could basically copy paste the docker-compose file you linked into |
|
Is the goal of this PR scoped to just provide the tooling for local users to test and review manually in XHGui, or is there also some form of CI or local collation/reporting that that I’m just oblivious to in the diff? |
|
@justlevine this was initially only targeted at setting up the XHProf profiler in a It should definitely be possible to use this tooling in a CI environment, but that’s not the goal of this specific PR. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don’t worry if you don’t have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you’re merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project’s expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
So, it’s been a while 😬 and I thought I’d revisit this experiment. I’ve refreshed the branch so this applies cleanly against the new Looking back at the conversation @noahtallen and I were having about this previously, the assumption was that this was only useful to support if we were also exposing some tooling that allowed folks to observe the profiling data via some included UI, like XHGUI. However, since then I’ve seen other tools like https://github.com/humanmade/query-monitor-flamegraph that depend on |
What?
This updates the configuration scripts to support passing a new –xhprof flag to
wp env start, which will install and configure XHProf support to the WordPress environment.Why?
Application profiling is an important tool for developers to use in order to discover potential performance bottlenecks in their code, but traditionally this tooling has been difficult to set up. By including support for the XHProf profiler directly in
wp-env, we can “democratize profiling” by making these tools easier to use.Additionally, these tools are already being used by the WordPress Core Performance team to help identify potential performance improvements to WordPress Core, and by including these tools natively in this package, we can make it easier for a broad number of people to contribute profiling information based on their own use cases.
How?
This works by installing the official XHProfile package from the PECL repository when the
--xhprofflag is set, and updates the php.ini configuration as needed to support profiling PHP applications.To enable profiling, you’ll need to include code to start the profiler and store or display the data that the profiler collects during an application run. One example of how to collect and analyze profiling data is to use XHGui (see these instructions for installing via Docker) and a library like PHP Profiler to send data collected during a profiling operation to XHGui. A simplified setup using an mu-plugin is demonstrated here: https://github.com/joemcgill/wp-profiler.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast