-
Notifications
You must be signed in to change notification settings - Fork 3.2k
About continuous profiling #5277
-
Is there anyone who uses continuous profiling on the Swoole-based project?
I know the blackfire.io supports Swoole but I'm looking for OSS.
Now I am trying to use Grafana Pyroscope but It does not work well with Swoole.
Any information or suggestions are appreciated.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments
-
Have you tested xhprof or excimer?
Beta Was this translation helpful? Give feedback.
All reactions
-
I think https://github.com/NoiseByNorthwest/php-spx could be made Swoole-friendly provided one uses PHP's builtin server for the visualization of the profiling and spx_profiler_start() and spx_profiler_stop() in the Swoole server while setting automatic start to 0
Then a UNIX domain socket could be used to inform the Swoole server to either enable or disable profiling during runtime (which - for instance - would modify a Swoole\Atomic variable)
If the message coming in over the UNIX domain socket is to enable, then the Atomic variable would be set to 1 and some INI settings might be set via ini_set() (See the SPX extension repository for help on this)
Also be sure to check out their ISSUES section as I recall I found one issue that helped me.
Finally, in the code that needs to be profiled, you might do something like:
global $profilingEnabled; // This is the Swoole\Atomic variable controlling if PROFILING is currently enabled
if ((int) $profilingEnabled->get() === 1) {
spx_profiler_start();
}
// ... Code to be profiled ....
if ((int) $profilingEnabled->get() === 1) {
spx_profiler_stop();
}
I have previously done this on a project, however there is one caveat:
All INI settings of PHP SPX profiler extension are PHP_INI_SYSTEM if I recall correctly, so what I ended up doing was to modify the source code of the SPX extension such that all INI settings were instead PHP_INI_ALL (meaning that they are modifyable from any context)
Just my 2 cents...
Beta Was this translation helpful? Give feedback.