wp-cli/profile-command

Profiling an intermediate hook is sometimes empty

danielbachhuber opened this issue ยท 9 comments

When profiling an intermediate hook (e.g. wp profile hook plugins_loaded:before), some environments don't log any results:

image

In debugging this initial report, the callback hooked into register_tick_function() is only fired once.

This is a bug in PHP 7 https://bugs.php.net/bug.php?id=72966

Related thread from another profiling plugin khromov/wp-performance-profiler#1

One of the comments in https://bugs.php.net/bug.php?id=71448 mentioned the following:

PHP 7.1 supports async signals, see https://wiki.php.net/rfc/async_signals. It looks like pcntl_async_signals() is not documented yet. This allows handling signals without using ticks.

Maybe this issue can be resolved by recoding how intermediate hooks work with PHP7.1?

Yeah, after running into this now, and going through the PHP bug discussion - it actually was a bug in PHP5, and PHP7 fixed the leak.

Looks like profile intermediate hooks won't work at all on PHP 7.0, and the only way forward for PHP 7.1+ is to modernize our approach here like upstream has noted (via @austinginder).

Is there another way to profile the (for example) wp_head:before hook? Or is switching back to PHP 5.6 the only option for now?

PHP 5.6 is the only option.

So currently this won't work on PHP 7.1+ either, correct?

(But could be made to work?)

Hello,
i am not a professional on github. Sorry for my question if it's stupid. For this bug here looks like there is a fix (https://gist.github.com/danielbachhuber/6bc4276ce559ddaa8b809a17c5ad6cd5) - there is a way to download this wp-cli profile package including this fix?

tdiam commented

Hello, i am not a professional on github. Sorry for my question if it's stupid. For this bug here looks like there is a fix (https://gist.github.com/danielbachhuber/6bc4276ce559ddaa8b809a17c5ad6cd5) - there is a way to download this wp-cli profile package including this fix?

Assuming you have WP-CLI and the profile command installed, you can apply the patch with the following one-liner:

wget -qO- https://gist.githubusercontent.com/danielbachhuber/6bc4276ce559ddaa8b809a17c5ad6cd5/raw/9ca11c146c88f481367494e62eb940835b0bcd95/wp-cli-profile-command-160.diff | patch -p1 -d ~/.wp-cli/packages/vendor/wp-cli/profile-command/

However, bear in mind that the patch by @danielbachhuber isn't complete and there are missing parts. Specifically, the FileStreamWrapper class in the patch does not fully implement streamWrapper .

For example, WordPress when loading the translation files (load_textdomain function), uses the fseek operation which is not implemented in the patch and so the command breaks:

Warning: fseek(): Stream does not support seeking in /home/user/public_html/wp-includes/pomo/streams.php on line 197

Also, this leaves *_file.php files behind, which you can easily cleanup:

find . -name '*_file.php' -delete