Skip to content

Commit

Permalink
Merge fb051a2 into 1b82a3e
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-i committed Feb 7, 2022
2 parents 1b82a3e + fb051a2 commit d050ed6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Options:
-S, --stop-process[=STOP-PROCESS] stop the target process while reading its trace (default: off)
--php-regex[=PHP-REGEX] regex to find the php binary loaded in the target process
--libpthread-regex[=LIBPTHREAD-REGEX] regex to find the libpthread.so loaded in the target process
--php-version[=PHP-VERSION] php version of the target (default: auto)
--php-version[=PHP-VERSION] php version (auto|v7[0-4]|v8[01]) of the target (default: auto)
--php-path[=PHP-PATH] path to the php binary (only needed in tracing chrooted ZTS target)
--libpthread-path[=LIBPTHREAD-PATH] path to the libpthread.so (only needed in tracing chrooted ZTS target)
-t, --template[=TEMPLATE] template name (phpspy|phpspy_with_opcode|json_lines) (default: phpspy)
Expand Down Expand Up @@ -132,7 +132,7 @@ Options:
-S, --stop-process[=STOP-PROCESS] stop the target process while reading its trace (default: off)
--php-regex[=PHP-REGEX] regex to find the php binary loaded in the target process
--libpthread-regex[=LIBPTHREAD-REGEX] regex to find the libpthread.so loaded in the target process
--php-version[=PHP-VERSION] php version of the target (default: auto)
--php-version[=PHP-VERSION] php version (auto|v7[0-4]|v8[01]) of the target (default: auto)
--php-path[=PHP-PATH] path to the php binary (only needed in tracing chrooted ZTS target)
--libpthread-path[=LIBPTHREAD-PATH] path to the libpthread.so (only needed in tracing chrooted ZTS target)
-t, --template[=TEMPLATE] template name (phpspy|phpspy_with_opcode|json_lines) (default: phpspy)
Expand Down Expand Up @@ -162,7 +162,7 @@ Options:
-S, --stop-process[=STOP-PROCESS] stop the target process while reading its trace (default: off)
--php-regex[=PHP-REGEX] regex to find the php binary loaded in the target process
--libpthread-regex[=LIBPTHREAD-REGEX] regex to find the libpthread.so loaded in the target process
--php-version[=PHP-VERSION] php version of the target (default: auto)
--php-version[=PHP-VERSION] php version (auto|v7[0-4]|v8[01]) of the target (default: auto)
--php-path[=PHP-PATH] path to the php binary (only needed in tracing chrooted ZTS target)
--libpthread-path[=LIBPTHREAD-PATH] path to the libpthread.so (only needed in tracing chrooted ZTS target)
-h, --help Display help for the given command. When no command is given display help for the list command
Expand Down Expand Up @@ -190,7 +190,7 @@ Options:
-p, --pid=PID process id
--php-regex[=PHP-REGEX] regex to find the php binary loaded in the target process
--libpthread-regex[=LIBPTHREAD-REGEX] regex to find the libpthread.so loaded in the target process
--php-version[=PHP-VERSION] php version of the target (default: auto)
--php-version[=PHP-VERSION] php version (auto|v7[0-4]|v8[01]) of the target (default: auto)
--php-path[=PHP-PATH] path to the php binary (only needed in tracing chrooted ZTS target)
--libpthread-path[=LIBPTHREAD-PATH] path to the libpthread.so (only needed in tracing chrooted ZTS target)
-h, --help Display help for the given command. When no command is given display help for the list command
Expand Down Expand Up @@ -220,7 +220,7 @@ $ ./php-profiler i:trace -- php -r "fgets(STDIN);"
### Attach to a running process
```bash
$ sudo ~/.phpenv/versions/8.1snapshot/bin/php ./php-profiler i:tr -p 2182685
$ sudo php ./php-profiler i:tr -p 2182685
0 time_nanosleep <internal>:-1
1 PhpProfiler\Lib\Loop\LoopMiddleware\NanoSleepMiddleware::invoke /home/sji/work/php-profiler/src/Lib/Loop/LoopMiddleware/NanoSleepMiddleware.php:33
2 PhpProfiler\Lib\Loop\LoopMiddleware\KeyboardCancelMiddleware::invoke /home/sji/work/php-profiler/src/Lib/Loop/LoopMiddleware/KeyboardCancelMiddleware.php:39
Expand Down Expand Up @@ -300,7 +300,7 @@ $ docker run -it --security-opt="apparmor=unconfined" --cap-add=SYS_PTRACE --pid
### Generate flamegraphs from traces
```bash
$ sudo php ./php-profiler i:trace -p <pid of the target process or thread> >traces
./php-profiler c:flamegraph <traces >flame.svg
$ ./php-profiler c:flamegraph <traces >flame.svg
```
### Generate the [speedscope](https://github.com/jlfwong/speedscope) format from phpspy compatible traces
Expand All @@ -312,14 +312,28 @@ $ speedscope profile.speedscope.json
See [#101](https://github.com/sj-i/php-profiler/pull/101).
# Troubleshooting
## I get an error message "php module not found" and can't get a trace!
If your PHP binary uses a non-standard binary name that does not end with `/php`, use the `--php-regex` option to specify the name of the executable (or shared object) that contains the PHP interpreter.
## I don't think the trace is accurate.
The -S option will stop the execution of the target process for a moment at every sampling, but the trace obtained will be more accurate.
## Trace retrieval from ZTS target does not work on Ubuntu 21.10 or later.
Try to specify `--libpthread-regex="libc.so"` as an option.
## I can't get traces on Amazon Linux 2.
First, try `cat /proc/<pid>/maps` to check the memory map of the target PHP process. If the first module does not indicate the location of the PHP binary and looks like an anonymous region, try to specify `--php-regex="^$"` as an option.
# Goals
I would like to achieve the following 5 goals through this project.
- To be able to closely observe what is happening inside a running PHP script.
- To be a framework for PHP programmers to create a freely customizable PHP profiler.
- To be experimentation for the use of PHP outside of the web, where recent improvements of PHP like JIT and FFI have opened the door.
- Another entry point for PHP programmers to learn about PHP's internal implementation.
- To create programs that are fun to write for me.
- To create a program that is fun to write for me.
# LICENSE
- MIT (mostly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function setOptions(Command $command): void
'php-version',
null,
InputOption::VALUE_OPTIONAL,
'php version of the target (default: v80)'
'php version (auto|v7[0-4]|v8[01]) of the target (default: auto)'
)
->addOption(
'php-path',
Expand Down

0 comments on commit d050ed6

Please sign in to comment.