GitHub - shenzhe/php-xhprof-extension: Modern XHProf compatible PHP Profiler for...
source link: https://github.com/shenzhe/php-xhprof-extension
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
Tideways XHProf Extension
Home of the tideways_xhprof
extension - a hierarchical Profiler for PHP.
Looking for tideways
Extension to report to tideways.io? Go here.
Why did we rename the extension? Blog post here.
This PHP extension is a complete, modernized open-source rewrite of the original XHProf extension, with a new core datastructure and specifically optimized for PHP 7. The result is an XHProf data-format compatible extension with a much reduced overhead in the critical path that you are profiling.
The code for this extension is extracted from the main Tideways extension as we are moving to a new extension with incompatible data-format.
We are committed to provide support for this extension and port it to as many platforms as possible.
Note: The public API is not compatible to previous xhprof extensions and forks, as function names are different. Only the data format is compatible.
About tideways and tideways_xhprof Extensions
This repository now contains an extension by the name of tideways_xhprof
,
which only contains the XHProf related (Callgraph) Profiler functionality.
Previously the tideways
extension contained this functionality together with
other functionality used in our Software as a Service.
If you want to use the SaaS, the current approach is to fetch the code using precompiled binaries and packages from our Downloads page.
Requirements
- PHP >= 7.0
- OS: Linux, MacOS, Windows (Download DLLs)
Installation
You can install the extension from source:
phpize
./configure
make
sudo make install
Configure the extension to load with this PHP INI directive:
extension=tideways_xhprof.so
Restart Apache or PHP-FPM.
Usage
The API is not compatible to previous xhprof extensions and forks, only the data format is compatible:
<?php tideways_xhprof_enable(); my_application(); file_put_contents( sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid() . '.myapplication.xhprof', serialize(tideways_xhprof_disable()) );
By default only wall clock time is measured, you can enable
there additional metrics passing the $flags
bitmask to tideways_xhprof_enable
:
<?php tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_MEMORY | TIDEWAYS_XHPROF_FLAGS_CPU); my_application(); file_put_contents( sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid() . '.myapplication.xhprof', serialize(tideways_xhprof_disable()) );
In Swoole
The API is not compatible to previous xhprof extensions and forks, only the data format is compatible:
<?php tideways_xhprof_swoole_init(); tideways_xhprof_enable(); my_application(); file_put_contents( sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid() . '.myapplication.xhprof', serialize(tideways_xhprof_disable()) ); tideways_xhprof_swoole_end();
By default only wall clock time is measured, you can enable
there additional metrics passing the $flags
bitmask to tideways_xhprof_enable
:
<?php tideways_xhprof_swoole_init(); tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_MEMORY | TIDEWAYS_XHPROF_FLAGS_CPU); my_application(); file_put_contents( sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid() . '.myapplication.xhprof', serialize(tideways_xhprof_disable()) ); tideways_xhprof_swoole_end();
Data-Format
The XHProf data format records performance data for each parent => child
function call that was made between the calls to tideways_xhprof_enable
and
tideways_xhprof_disable
. It is formatted as an array with the parent and child
function names as a key concatenated with ==> and an array value with 2 to 5 entries:
wt
The summary wall time of all calls of this parent ==> child function pair.ct
The number of calls between this parent ==> child function pair.cpu
The cpu cycle time of all calls of thi sparent ==> child function pair.mu
The sum of increase inmemory_get_usage
for this parent ==> child function pair.pmu
The sum of increase inmemory_get_peak_usage
for this parent ==> child function pair.
When TIDEWAYS_XHPROF_FLAGS_MEMORY_ALLOC
flag is set, the following additional values are set:
mem.na
The sum of the number of all allocations in this function.mem.nf
The sum of the number of all frees in this function.mem.aa
The amount of allocated memory.
If TIDEWAYS_XHPROF_FLAGS_MEMORY_ALLOC_AS_MU
is set, TIDEWAYS_XHPROF_FLAGS_MEMORY_ALLOC
is activated
and, if TIDEWAYS_XHPROF_FLAGS_MEMORY_MU
is not set, mem.aa
is additionally returned in mu
.
There is a "magic" function call called "main()" that represents the entry into the profiling. The wall time on this performance data describes the full timeframe that the profiling ran.
Example:
<?php array( "main()" => array( "wt" => 1000, "ct" => 1, "cpu" => 400, ), "main()==>foo" => array( "wt" => 500, "ct" => 2, "cpu" => 200, ), "foo==>bar" => array( "wt" => 200, "ct" => 10, "cpu" => 100, ), )
Clock Sources
Any Profiler needs timer functions to calculate the duration of a function call
and the tideways_xhprof
extension is no different. On Linux you can collect
timing information through various means. The classic, most simple one is the
function gettimeofday
, which PHP uses when you call microtime()
. This function
is slower compared to other mechanisms that the kernel provides:
clock_gettime(CLOCK_MONOTONIC)
returns a monotonically increasing number (not a timestamp) at very high precision and much faster thangettimeofday()
. It is the preferred and recommended API to get high precision timestamps. On Xen based virtualizations (such as AWS) this call is much slower than on bare-metal or other virtualizations (Blog post)- TSC (Time Stamp Counter) API is accessible in C using inline assembler. It was the timing API that the original XHProf extension used and it is generally very fast, however depending on the make and generation of the CPU might not be synchronized between cores. On modern CPUs it is usually good to use without having to force the current process to a specific CPU.
Tideways on Linux defaults to using clock_gettime(CLOCK_MONOTONIC)
, but if
you are running on Xen based virtualization, you could try to reduce the
overhead by setting `tideways.clock_use_rdtsc=1" in your PHP.ini.
Recommend
-
127
Tideways XHProf Extension Home of the tideways_xhprof extension - a hierarchical Profiler for PHP. This extensions is not compatible with our Tideways service. Are you looking for tideways Extensio...
-
142
php-xhprof-extension - Modern XHProf compatible PHP Profiler for PHP 7
-
23
背景 最近2月把wise feed后端重构了一次,上线一周了,但一直没放量, 原因是压测太耗CPU,2G 4核的实例连50qps扛不住。 最初性能 50qps CPU直接消耗150%
-
43
README.md family 公众号 swoole4.0之打造自己的web开发框架 代码 欢迎关注公众号:
-
8
编译xhprof时的一个小意外 – CFC4N的博客新项目基本开发完毕,剩余收尾工作。趁美工调整新UI的时间,赶紧在测试机上安装PHP的性能检测利器xhprof。 下载地址http://pecl.php.net/package/xhprof...
-
1
在生产环境中使用php性能测试工具xhprof 浏览:3308次 出处信息
-
4
xhprof 简介与环境搭建 xhprof是Facebook的一款诊断PHP应用性能的扩展,拥有清晰明显的图表数据展示,可以方便快捷的帮助开发人员找到应用的性能瓶颈。 目前xhprof最新版本是0.9.4,适用于php5.2及以上的版本。我安装的是php5.4.40,xhprof0...
-
0
xhprof扩展实现的一些细节 我们知道zend的一些内核调用都是函数指针,对函数指针进行一层包裹,就可以实现在调用前后做相关的记录,这个就是一些优化、缓存、诊断扩展实现的部分原理。 xhprof_enable执行流程 回调...
-
3
xhprof 输入输出接口 由于这次是进行一次扩展升级,所以留给用户的接口最好不要发生变化。只要接口不变,xhprof_html或者其他的一些分析工具基本可以无修改移植了。 扩展提供的接口目前只有两个 void xhprof_enable([int $flags=0...
-
3
Maven Test Profiler This maven extension outputs summary of all tests ran by maven-surefire-plugin and maven-failsafe-plugin. Every test suite is listed separately with their elapsed time in order of slowest to faster. This...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK