當(dāng)前位置:首頁(yè) > IT技術(shù) > Web編程 > 正文

phpspy 進(jìn)行php 項(xiàng)目性能分析
2021-09-24 14:39:09

phpspy 是基于c 編寫的利用了ptrace 的php 性能分析工具,支持apache ,fpm sapi 注意php 主要支持7.0+

參考使用

為了方便,構(gòu)建了docker 鏡像,大家可以直接使用

  • 支持的命令



docker run -it  dalongrong/phpspy   ./phpspy/phpspy --help



Usage:



phpspy [options] -p <pid>



phpspy [options] -P <pgrep-args>



phpspy [options] [--] <cmd>


?


Options:



-h, --help                         Show this help



-p, --pid=<pid>                    Trace PHP process at `pid`



-P, --pgrep=<args>                 Concurrently trace processes that



match pgrep `args` (see also `-T`)



-T, --threads=<num>                Set number of threads to use with `-P`



(default: 16)



-s, --sleep-ns=<ns>                Sleep `ns` nanoseconds between traces



(see also `-H`) (default: 10101010)



-H, --rate-hz=<hz>                 Trace `hz` times per second



(see also `-s`) (default: 99)



-V, --php-version=<ver>            Set PHP version



(default: auto;



supported: 70 71 72 73 74 80)



-l, --limit=<num>                  Limit total number of traces to capture



(approximate limit in pgrep mode)



(default: 0; 0=unlimited)



-i, --time-limit-ms=<ms>           Stop tracing after `ms` milliseconds



(second granularity in pgrep mode)



(default: 0; 0=unlimited)



-n, --max-depth=<max>              Set max stack trace depth



(default: -1; -1=unlimited)



-r, --request-info=<opts>          Set request info parts to capture



(q=query c=cookie u=uri p=path



capital=negation)



(default: QCUP; none)



-m, --memory-usage                 Capture peak and current memory usage



with each trace (requires target PHP



process to have debug symbols)



-o, --output=<path>                Write phpspy output to `path`



(default: -; -=stdout)



-O, --child-stdout=<path>          Write child stdout to `path`



(default: phpspy.%d.out)



-E, --child-stderr=<path>          Write child stderr to `path`



(default: phpspy.%d.err)



-x, --addr-executor-globals=<hex>  Set address of executor_globals in hex



(default: 0; 0=find dynamically)



-a, --addr-sapi-globals=<hex>      Set address of sapi_globals in hex



(default: 0; 0=find dynamically)



-1, --single-line                  Output in single-line mode



-b, --buffer-size=<size>           Set output buffer size to `size`.



Note: In `-P` mode, setting this



above PIPE_BUF (4096) may lead to



interlaced writes across threads.



(default: 4096)



-f, --filter=<regex>               Filter output by POSIX regex



(default: none)



-F, --filter-negate=<regex>        Same as `-f` except negated



-d, --verbose-fields=<opts>        Set verbose output fields



(p=pid t=timestamp



capital=negation)



(default: PT; none)



-c, --continue-on-error            Attempt to continue tracing after



encountering an error



-#, --comment=<any>                Ignored; intended for self-documenting



commands



-@, --nothing                      Ignored



-v, --version                      Print phpspy version and exit


?



Experimental options:



-j, --event-handler=<handler>      Set event handler (fout, callgrind)



(default: fout)



-S, --pause-process                Pause process while reading stacktrace



(unsafe for production!)



-e, --peek-var=<varspec>           Peek at the contents of the var located



at `varspec`, which has the format:



<varname>@<path>:<lineno>



<varname>@<path>:<start>-<end>



e.g., xyz@/path/to.php:10-20



-g, --peek-global=<glospec>        Peek at the contents of a global var



located at `glospec`, which has



the format: <global>.<key>



where <global> is one of:



post|get|cookie|server|files|globals



e.g., server.REQUEST_TIME



-t, --top                          Show dynamic top-like output


  • 參考運(yùn)行命令




docker run -it --cap-add SYS_PTRACE dalongrong/phpspy ./phpspy/phpspy -V73 -r -- php -r 'sleep(1);'


效果

phpspy 進(jìn)行php 項(xiàng)目性能分析_apache

?

?

phpspy 進(jìn)行php 項(xiàng)目性能分析_參考資料_02

說明

類似的工具xdebug 以及php-profiler也是不錯(cuò)的選擇,docker 鏡像dalongrong/phpspy 直接可以使用,后續(xù)會(huì)寫直接集成到容器中的玩法

參考資料

??https://github.com/adsr/phpspy??

??https://github.com/sj-i/php-profiler??

??https://xdebug.org/docs/profiler??

本文摘自 :https://blog.51cto.com/r

開通會(huì)員,享受整站包年服務(wù)立即開通 >