首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xhprof-html不会显示运行报告(在XHProf中没有指定的运行)

xhprof-html不会显示运行报告(在XHProf中没有指定的运行)
EN

Stack Overflow用户
提问于 2022-05-26 14:14:46
回答 1查看 105关注 0票数 0

如何使用xhprof-html显示给定xhprof运行的运行报告

我安装了潮间带-

代码语言:javascript
复制
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中启用了

代码语言:javascript
复制
extension=/usr/lib/php/20190902/tideways_xhprof.so

配置wordpress以编写xhprof运行。在我的wp-config.php文件中

代码语言:javascript
复制
# 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文件转储出来。

代码语言:javascript
复制
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文件

代码语言:javascript
复制
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文件

代码语言:javascript
复制
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。但他们没有。相反,我只是看到

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-27 06:39:22

没有显示Run Report,因为它无法读取文件。

问题

您正在使用tideways xhprof生成文件,并将序列化的输出写入文件。

代码语言:javascript
复制
$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中的块更改为

代码语言:javascript
复制
# 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的新项目

代码语言:javascript
复制
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文件格式。

有关此问题的更多信息,请参见:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72393257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档