如何使用xhprof-html显示给定xhprof运行的运行报告
我安装了潮间带-。
apt-get install php-dev
git clone "https://github.com/tideways/php-xhprof-extension.git"
cd php-xhprof-extension
phpize
./configure
make
make install我在我的php.ini中启用了
extension=/usr/lib/php/20190902/tideways_xhprof.so我配置wordpress以编写xhprof运行。在我的wp-config.php文件中
# PHP profiling with tideways-xhprof
# * https://pressjitsu.com/blog/profiling-wordpress-performance/
if ( isset( $_GET['profile'] ) && $_GET['profile'] === 'secret-string' ) {
tideways_xhprof_enable( TIDEWAYS_FLAGS_MEMORY + TIDEWAYS_FLAGS_CPU );
register_shutdown_function( function() {
$results = tideways_xhprof_disable();
file_put_contents( '/path/to/my/xhprof/dir/' .date('Y-m-d\TH:i:s\Z', time() - date('Z')). '.xhprof' , serialize( $results ) );
});
}
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');通过访问https://example.com/index.php?profile=secret-string,我成功地将xhprof文件转储出来。
root@host:/path/to/my/xhprof/dir/# du -sh *
1,6M 2022-05-25T18:15:45Z.xhprof
1,6M 2022-05-25T18:18:38Z.xhprof
root@host:/path/to/my/xhprof/dir/#我还用xhprof-html创建了一个网站。我用配置它来查找上面的.xhprof文件
root@host:/var/www/xhprof/xhprof-html# diff index.orig.php index.php
83c83
< $xhprof_runs_impl = new XHProfRuns_Default();
---
> $xhprof_runs_impl = new XHProfRuns_Default( '/path/to/my/xhprof/dir' );
root@host:/var/www/xhprof/xhprof-html#现在我可以加载访问xhprof-html/index.php文件,它成功地在https://xhprof.example.com/xhprof-html/index.php上显示了我的两个.xhprof文件
No XHProf runs specified in the URL.
Existing runs:
2022-05-25T18:18:38Z.xhprof 2022-05-25 18:18:38
2022-05-25T18:15:45Z.xhprof 2022-05-25 18:15:45如果我单击任何一个页面,我将被重定向(如预期的那样)到以下任何一个页面:
然而,我希望上面的页面来呈现实际的Run Report。但他们没有。相反,我只是看到
No XHProf runs specified in the URL.
Existing runs:
2022-05-25T18:18:38Z.xhprof 2022-05-25 18:18:38
2022-05-25T18:15:45Z.xhprof 2022-05-25 18:15:45喂? XHProf运行是在URL.中明确指定的
如何让xhprof-html显示实际的Run Report
发布于 2022-05-27 06:39:22
没有显示Run Report,因为它无法读取文件。
问题
您正在使用tideways xhprof生成文件,并将序列化的输出写入文件。
$results = tideways_xhprof_disable();
file_put_contents( '/path/to/my/xhprof/dir/' .date('Y-m-d\TH:i:s\Z', time() - date('Z')). '.xhprof' , serialize( $results ) );(来源)
但是,您切换到托管一个较旧的(不再维护的) xhprof分支,以便在web服务器的文档根目录中为xhprof_html提供服务。
注意:当然,您必须这样做,甚至tideways也会将您链接到
phacility回购。奇怪的是,tideways本身并不包括xhprof_html目录,可能是因为tideway是一家销售xhprof可视化SaaS的企业--因此,他们从他们维护的xhprof叉中剥离了“可怜人”的xhprof_html。
如果您想使用XHProfRuns_Default()读取文件,那么应该使用XHProfRuns_Default()编写文件。
解决方案
将wp-config.php中的块更改为
# PHP profiling with tideways-xhprof
# * https://pressjitsu.com/blog/profiling-wordpress-performance/
if ( isset( $_GET['profile'] ) && $_GET['profile'] === 'secret-string' ) {
tideways_xhprof_enable( TIDEWAYS_FLAGS_MEMORY + TIDEWAYS_FLAGS_CPU );
register_shutdown_function( function() {
$results = tideways_xhprof_disable();
include_once( '/var/www/xhprof/xhprof_lib/utils/xhprof_runs.php' );
$XHProfRuns = new XHProfRuns_Default( '/path/to/my/xhprof/dir' );
$XHProfRuns->save_run( $results, date('Y-m-d\TH:i:s\Z', time() - date('Z')) );
});
}然后生成一个新的配置文件
现在您将看到一个名为62906fb2c49b4.2022-05-27T06:29:06Z.xhprof的新项目
No XHProf runs specified in the URL.
Existing runs:
62906fb2c49b4.2022-05-27T06:29:06Z.xhprof 2022-05-27 06:29:06
2022-05-25T18:18:38Z.xhprof 2022-05-25 18:18:38
2022-05-25T18:15:45Z.xhprof 2022-05-25 18:15:45单击这个新项目,您就可以看到Run Report了,因为它可以读取xhprof文件格式。
有关此问题的更多信息,请参见:
https://stackoverflow.com/questions/72393257
复制相似问题