phperf/xh-tool

XHPROF 配置查看 CLI 工具

维护者

详细信息

github.com/phperf/xh-tool

源代码

问题

安装量: 4,096

依赖项: 7

建议者: 0

安全性: 0

星标: 5

关注者: 2

分支: 1

开放性问题: 0

类型:工具

v1.1.0 2018-03-04 06:16 UTC

This package is auto-updated.

Last update: 2024-09-18 01:31:26 UTC


README

一个用于分析 XHPROF 层次数据的命令行工具。

安装

从发行版下载 xh-tool.phar,可选安装 bash 完整性并使用以下命令将其符号链接到 /usr/local/bin

php xh-tool.phar --install

或者通过 composer 安装

composer require --dev phperf/xh-tool

用法

获取序列化配置数据文件,例如:xhprof_report_sample.1518071438.9016.serialized

您可以使用 phperf/php-profiler docker 镜像来获取独立脚本的配置

docker run --rm -v $(pwd):/code phperf/php-profiler php test_me.php

信息

获取配置的基本信息

xh-tool info --help
v1.1.0 xh-tool info
XHPROF profile viewer
Usage:
   xh-tool info <profile>
   profile   Path to XHPROF hierarchical profile

Options:
   --cpu         Show CPU time instead of wall time
   --with-mem    Add memory info
xh-tool info xhprof_report_sample.1518071438.9016.serialized 

Nodes: 2082
Functions: 731
Calls: 16M
Total
name     wallTime   wallTime%   wallTime1   ownTime   ownTime%   ownTime1   count
main()   34.99s     100         34.99s      7.56ms    0.02       7.56ms     1    

顶部

获取排序后的函数列表

xh-tool top --help
v1.1.0 xh-tool top
XHPROF profile viewer
Usage:
   xh-tool top <profile>
   profile   Path to XHPROF hierarchical profile

Options:
   --strip-nesting     Strip @N for nested calls
   --limit <limit>     Number of rows in result, default no limit
   --filter <filter>   Case-insensitive regex to filter by function name, example: "process$", "swaggest", "^MyNs\\MyClass\\MyMethod$"
   --cpu               Show CPU time instead of wall time
   --with-mem          Add memory info
   --order <order>     Order by field, default: ownTime
                       Allowed values: name, wallTime, wallTime1, wallTime%, cpuTime, cpuTime1, cpuTime%, ownTime,
                       ownTime1, ownTime%, ownCpuTime, ownCpuTime1, ownCpuTime%, memoryUsage1, peakMemoryUsage,
                       peakMemoryShift, count

  • wallTime 是在函数中花费的时间(包括子函数调用)。
  • wallTime% 是将函数中花费的时间按 main() 总时间归一化。
  • wallTime1 是 1 次函数调用的平均时间,计算为 wallTime / count
  • ownTime 是在函数中花费的时间(不包括子函数调用)。
  • ownTime% 是将 ownTimemain() 总时间归一化。
  • ownTime1 是 1 次函数调用的平均时间(不包括子函数调用),计算为 ownTime / count
  • cpuTime 是在函数中花费的 CPU 时间(包括子函数调用)。
  • cpuTime% 是将函数中花费的 CPU 时间按 main() 总 CPU 时间归一化。
  • cpuTime1 是 1 次函数调用的平均 CPU 时间,计算为 cpuTime / count
  • ownCpuTime 是在函数中花费的时间(不包括子函数调用)。
  • ownCpuTime% 是将 ownCpuTimemain() 总 CPU 时间归一化。
  • ownCpuTime1 是 1 次函数调用的平均时间(不包括子函数调用),计算为 ownCpuTime / count
  • memoryUsage1 是 1 次函数调用的平均内存使用量。
  • peakMemoryUsage 是如果函数调用后更改,则为内存使用的峰值值。
  • peakMemoryShift 是函数对 peakMemoryUsage 贡献的内存量。
  • count 是发生的函数调用次数。
xh-tool top xhprof_report_sample.1518071438.9016.serialized --order ownTime --limit 10 --filter swaggest

name                                                                     wallTime   wallTime%   wallTime1   ownTime    ownTime%   ownTime1   count
Swaggest\JsonSchema\Schema::process                                      12.52s     35.79       113.2us     1.12s      3.2        10.1us     111K 
Swaggest\JsonSchema\Schema::process@1                                    9.2s       26.3        98.1us      1.05s      2.99       11.1us     94K  
Swaggest\JsonSchema\Schema::processObject                                10.05s     28.72       138.6us     965.02ms   2.76       13.3us     73K  
Swaggest\JsonSchema\Tests\PHPUnit\Spec\Draft7OpisTest::runSpecTest       14.78s     42.23       275.6us     884.17ms   2.53       16.5us     54K  
Swaggest\JsonSchema\Schema::in                                           14.36s     41.04       129.8us     813.56ms   2.33       7.4us      111K 
Swaggest\JsonSchema\Schema::process@2                                    6.98s      19.95       101us       773.07ms   2.21       11.2us     69K  
Swaggest\JsonSchema\Schema::process@3                                    4.99s      14.26       81.4us      740.24ms   2.12       12.1us     61K  
Swaggest\JsonSchema\Tests\PHPUnit\Spec\Draft7SwaggestTest::runSpecTest   17.01s     48.62       307.6us     734.24ms   2.1        13.3us     55K  
Swaggest\JsonSchema\Constraint\Type::isValid                             746.13ms   2.13        2.8us       718.75ms   2.05       2.7us      269K 
Swaggest\JsonSchema\Schema::process@4                                    3.06s      8.76        54.2us      691.08ms   1.98       12.2us     57K  

Func

获取特定函数的信息

v1.1.0 xh-tool func
XHPROF profile viewer
Usage:
   xh-tool func <profile> <filter>
   profile   Path to XHPROF hierarchical profile
   filter    Case-insensitive regex to filter by function name, example: "process$", "swaggest", "^MyNs\\MyClass\\MyMethod$"

Options:
   --strip-nesting    Strip @N for nested calls
   --limit <limit>    Number of rows in result, default no limit
   --cpu              Show CPU time instead of wall time
   --with-mem         Add memory info
   --order <order>    Order by field, default: ownTime
                      Allowed values: name, wallTime, wallTime1, wallTime%, cpuTime, cpuTime1, cpuTime%, ownTime,
                      ownTime1, ownTime%, ownCpuTime, ownCpuTime1, ownCpuTime%, memoryUsage1, peakMemoryUsage,
                      peakMemoryShift, count
xh-tool func xhprof_report_sample.1518071438.9016.serialized Schema::process$

Function
name                                  wallTime   wallTime%   wallTime1   ownTime   ownTime%   ownTime1   count
Swaggest\JsonSchema\Schema::process   12.52s     35.79       113.2us     1.12s     3.2        10.1us     111K 

Parents
name                              wallTime   wallTime%   wallTime1   count
Swaggest\JsonSchema\Schema::in    12.42s     35.51       112.3us     111K 
Swaggest\JsonSchema\Schema::out   97.63ms    0.28        97.63ms     1    

Children
name                                         wallTime   wallTime%   wallTime1   count
Swaggest\JsonSchema\Schema::processType      308.63ms   0.88        4.8us       65K  
Swaggest\JsonSchema\Schema::processAnyOf     66.77ms    0.19        51.4us      1K   
SplObjectStorage::attach                     2us        0           2us         1    
SplObjectStorage::contains                   1us        0           1us         1    
Swaggest\JsonSchema\Schema::processContent   17.4ms     0.05        24.9us      700  
Swaggest\JsonSchema\Schema::processOneOf     102.59ms   0.29        73.3us      1K   
Swaggest\JsonSchema\Schema::processIf        40.04ms    0.11        33.4us      1K   
Swaggest\JsonSchema\Schema::processEnum      2.68ms     0.01        5.4us       500  
Swaggest\JsonSchema\Schema::processConst     48.98ms    0.14        40.8us      1K   
Swaggest\JsonSchema\Schema::processNot       51.65ms    0.15        25.8us      2K   
Swaggest\JsonSchema\Schema::processAllOf     94.92ms    0.27        59.3us      2K   
array_key_exists                             12.17ms    0.03        0.1us       105K 
Swaggest\JsonSchema\Schema::processNumeric   14.43ms    0.04        1.9us       8K   
Swaggest\JsonSchema\Schema::processArray     212.15ms   0.61        30.3us      7K   
Swaggest\JsonSchema\Schema::processString    431.46ms   1.23        25.1us      17K  
is_array                                     5.39ms     0.02        0.1us       88K  
Swaggest\JsonSchema\Schema::processObject    9.97s      28.5        143.9us     69K  
is_float                                     7.24ms     0.02        0.1us       93K  
is_int                                       7.64ms     0.02        0.1us       97K  
is_string                                    8.06ms     0.02        0.1us       103K 
PHPUnitBenchmark\Suite::jsonSerialize        22us       0           22us        1    

Edges

显示配置数据的原始边缘

xh-tool edges --help
v1.1.0 xh-tool edges
XHPROF profile viewer
Usage:
   xh-tool edges <profile>
   profile   Path to XHPROF hierarchical profile

Options:
   --strip-nesting     Strip @N for nested calls
   --limit <limit>     Number of rows in result, default no limit
   --filter <filter>   Case-insensitive regex to filter by function name, example: "process$", "swaggest", "^MyNs\\MyClass\\MyMethod$"
   --cpu               Show CPU time instead of wall time
   --with-mem          Add memory info
   --order <order>     Order by field, default: ownTime
                       Allowed values: name, wallTime, wallTime1, wallTime%, cpuTime, cpuTime1, cpuTime%, ownTime,
                       ownTime1, ownTime%, ownCpuTime, ownCpuTime1, ownCpuTime%, memoryUsage1, peakMemoryUsage,
                       peakMemoryShift, count
xh-tool edges xhprof_report_sample.1518071438.9016.serialized --order ownTime --limit 10 --filter swaggest
name                                                                                            wallTime   wallTime%   wallTime1   count
Swaggest\JsonSchema\Schema::processObject@1==>Swaggest\JsonSchema\Schema::process@2             5.23s      14.96       172.1us     30K
Swaggest\JsonSchema\Helper::toPregPattern==>strpos                                              905us      0           0.2us       5K
Swaggest\JsonSchema\Schema::processObject==>spl_autoload_call                                   13.55ms    0.04        4.52ms      3
Swaggest\JsonSchema\Schema::processObject==>Swaggest\JsonSchema\Structure\ObjectItem::key       7.8ms      0.02        1.7us       5K
Swaggest\JsonSchema\Structure\ObjectItem::key==>ArrayIterator::key                              574us      0           0.1us       5K
Swaggest\JsonSchema\Schema::processObject==>Swaggest\JsonSchema\Structure\ObjectItem::current   8.25ms     0.02        1.8us       5K
Swaggest\JsonSchema\Structure\ObjectItem::current==>ArrayIterator::current                      463us      0           0.1us       5K
Swaggest\JsonSchema\Schema::processObject==>Swaggest\JsonSchema\Structure\ObjectItem::valid     12.79ms    0.04        1.9us       7K
Swaggest\JsonSchema\Structure\ObjectItem::valid==>ArrayIterator::valid                          1.08ms     0           0.2us       7K
Swaggest\JsonSchema\Schema::processObject==>Swaggest\JsonSchema\Structure\ObjectItem::rewind    9.72ms     0.03        2.9us       3K