IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> PHP知识库 -> php-xhprof安装-基本使用 -> 正文阅读

[PHP知识库]php-xhprof安装-基本使用

介绍

官网的我直接拿过来了

XHProf 是一个轻量级的分层性能测量分析器。 在数据收集阶段,它跟踪调用次数与测量数据,展示程序动态调用的弧线图。 它在报告、后期处理阶段计算了独占的性能度量,例如运行经过的时间、CPU 计算时间和内存开销。 函数性能报告可以由调用者和被调用者终止。 在数据搜集阶段 XHProf 通过调用图的循环来检测递归函数,通过赋予唯一的深度名称来避免递归调用的循环。

XHProf 包含了一个基于 HTML 的简单用户界面(由 PHP 写成)。 基于浏览器的用户界面使得浏览、分享性能数据结果更加简单方便。 同时也支持查看调用图。

XHProf 的报告对理解代码执行结构常常很有帮助。 比如此分层报告可用于确定在哪个调用链里调用了某个函数。

XHProf 对两次运行进行比较(又名 “diff” 报告),或者多次运行数据的合计。 对比、合并报告,很像针对单次运行的“平式视图”性能报告,就像“分层式视图”的性能报告

更多额外文档可以在 ? facebook xhprof上找到。

安装

安装xhprof

下载地址:https://pecl.php.net/package/xhprof

由于我这里下载xhprof

/var/www/html # pecl list
Installed packages, channel pecl.php.net:
=========================================
Package Version State
redis   4.2.0   stable
xhprof  0.9.4   beta

先进行卸载

/var/www/html # pecl uninstall xhprof
Unable to remove "extension=xhprof.so" from php.ini
uninstall ok: channel://pecl.php.net/xhprof-0.9.
/var/www/html # pecl list
Installed packages, channel pecl.php.net:
=========================================
Package Version State
redis   4.2.0   stable

选择对应的版本
在这里插入图片描述
我这里下载的是0.9.4

/var/www/html # wget https://pecl.php.net/get/xhprof-0.9.4.tgz
--2021-07-15 10:28:07--  https://pecl.php.net/get/xhprof-0.9.4.tgz
Resolving pecl.php.net... 104.236.228.160
Connecting to pecl.php.net|104.236.228.160|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 842077 (822K) [application/octet-stream]
Saving to: 'xhprof-0.9.4.tgz'

xhprof-0.9.4.tgz                              100%[==============================================================================================>] 822.34K   246KB/s    in 3.3s

2021-07-15 10:28:13 (246 KB/s) - 'xhprof-0.9.4.tgz' saved [842077/842077]

/var/www/html # rm -rf xhprof-0.9.4*
/var/www/html # pecl install https://pecl.php.net/get/xhprof-0.9.4.tgz
downloading xhprof-0.9.4.tgz ...
Starting to download xhprof-0.9.4.tgz (842,077 bytes)
........................................................................................................................................................................done: 842,077 bytes
11 source files, building
running: phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
building in /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4
running: /tmp/pear/temp/xhprof/extension/configure --with-php-config=/usr/local/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
expr: syntax error
sh: 0: unknown operand
expr: syntax error
sh: 0: unknown operand
expr: syntax error
sh: 0: unknown operand
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20131226
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.14.3 (ok)
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable xhprof support... yes, shared
checking for ld used by cc... /usr/x86_64-alpine-linux-musl/bin/ld
checking if the linker (/usr/x86_64-alpine-linux-musl/bin/ld) is GNU ld... yes
checking for /usr/x86_64-alpine-linux-musl/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 98304
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/x86_64-alpine-linux-musl/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/libtool --mode=compile cc  -I. -I/tmp/pear/temp/xhprof/extension -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/include -I/tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/main -I/tmp/pear/temp/xhprof/extension -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/xhprof/extension/xhprof.c -o xhprof.lo
mkdir .libs
 cc -I. -I/tmp/pear/temp/xhprof/extension -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/include -I/tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/main -I/tmp/pear/temp/xhprof/extension -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/xhprof/extension/xhprof.c  -fPIC -DPIC -o .libs/xhprof.o
/tmp/pear/temp/xhprof/extension/xhprof.c:825:10: warning: 'hp_globals' is static but used in inline function 'hp_ignore_entry' which is not static
   return hp_globals.ignored_function_names != NULL &&
          ^
/bin/sh /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/libtool --mode=link cc -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/include -I/tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/main -I/tmp/pear/temp/xhprof/extension -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o xhprof.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/modules  xhprof.lo
cc -shared  .libs/xhprof.o   -Wl,-soname -Wl,xhprof.so -o .libs/xhprof.so
creating xhprof.la
(cd .libs && rm -f xhprof.la && ln -s ../xhprof.la xhprof.la)
/bin/sh /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/libtool --mode=install cp ./xhprof.la /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/modules
cp ./.libs/xhprof.so /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/modules/xhprof.so
cp ./.libs/xhprof.lai /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/modules/xhprof.la
PATH="$PATH:/sbin" ldconfig -n /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /tmp/pear/temp/pear-build-defaultuserFBmoKa/xhprof-0.9.4/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4" install
Installing shared extensions:     /tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4/usr/local/lib/php/extensions/no-debug-non-zts-20131226/
running: find "/tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4" | xargs ls -dils
1576398      4 drwxr-xr-x    3 root     root          4096 Jul 15 10:28 /tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4
1576421      4 drwxr-xr-x    3 root     root          4096 Jul 15 10:28 /tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4/usr
1576422      4 drwxr-xr-x    3 root     root          4096 Jul 15 10:28 /tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4/usr/local
1576423      4 drwxr-xr-x    3 root     root          4096 Jul 15 10:28 /tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4/usr/local/lib
1576424      4 drwxr-xr-x    3 root     root          4096 Jul 15 10:28 /tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4/usr/local/lib/php
1576425      4 drwxr-xr-x    3 root     root          4096 Jul 15 10:28 /tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4/usr/local/lib/php/extensions
1576426      4 drwxr-xr-x    2 root     root          4096 Jul 15 10:28 /tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4/usr/local/lib/php/extensions/no-debug-non-zts-20131226
1576419     92 -rwxr-xr-x    1 root     root         91160 Jul 15 10:28 /tmp/pear/temp/pear-build-defaultuserFBmoKa/install-xhprof-0.9.4/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xhprof.so

Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xhprof.so'
install ok: channel://pecl.php.net/xhprof-0.9.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=xhprof.so" to php.ini

安装出错提示:Connection to `pecl.php.net:443‘ failed

提示最终安装路径为/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xhprof.so
也可以通过命令查看安装目录

/var/www/html # php -i |grep extension_dir
extension_dir => /usr/local/lib/php/extensions/no-debug-non-zts-20131226 => /usr/local/lib/php/extensions/no-debug-non-zts-20131226
sqlite3.extension_dir => no value => no value

查看加载的ini文件

/var/www/html # php --ini
Configuration File (php.ini) Path: /usr/local/etc/php
Loaded Configuration File:         /usr/local/etc/php/php.ini
Scan for additional .ini files in: /usr/local/etc/php/conf.d
Additional .ini files parsed:      /usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
/usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-redis.ini,
/usr/local/etc/php/conf.d/docker-php-ext-shmop.ini,
/usr/local/etc/php/conf.d/docker-php-ext-zip.ini

编辑加载的文件

vi /usr/local/etc/php/php.ini

添加配置

extension=xhprof.so
xhprof.output_dir=”/data/xhprof/xhprof_data“

xhprof.output_dir string
储存 XHProf 运行数据的默认目录,用于接口 iXHProfRuns(即 XHProfRuns_Default 类)。

验证

/var/www/html # php --ri xhprof

xhprof

xhprof => 0.9.2
CPU num => 2

配置使用

安装完后/usr/local/lib/php/目录下会有两个目录 xhprof_lib,xhprof_html/ xhprof_lib为工具的依赖目录,xhprof_html为web展示的项目目录,把xhprof_html 配置在Nginx server下 可以通过web地址的形式的方式访问

cp -r /usr/local/lib/php/xhprof_html/ /data/xhprof/
cp -r /usr/local/lib/php/xhprof_lib/ /data/xhprof/

Nginx配置

server{
    server_name mydata.cn;
    listen 80;
    root /data;
    index       index.php;
    autoindex on;
    location / {
            try_files $uri $uri/ /index.php$is_args$args;
    }
    location ~ \.php$ {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass php5-4-33-fpm:9000;
            try_files $uri =404;
    }
}

编辑一个PHP文件测试

<?php
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

for ($i = 0; $i <= 1000; $i++) {
    $a = $i * $i;
}

$xhprof_data = xhprof_disable();

$XHPROF_ROOT = "./xhprof/";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");

echo "<a href='http://mydata.cn/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing'>goto</a>:http://mydata.cn/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";

运行php文件得到结果如下
在这里插入图片描述
goto
在这里插入图片描述

图形界面所需工具

apk add graphviz

不安装点击[View Full Callgraph]查看图形界面会提示

failed to execute cmd: " dot -Tpng". stderr: `sh: dot: not found 

在这里插入图片描述

  PHP知识库 最新文章
Laravel 下实现 Google 2fa 验证
UUCTF WP
DASCTF10月 web
XAMPP任意命令执行提升权限漏洞(CVE-2020-
[GYCTF2020]Easyphp
iwebsec靶场 代码执行关卡通关笔记
多个线程同步执行,多个线程依次执行,多个
php 没事记录下常用方法 (TP5.1)
php之jwt
2021-09-18
上一篇文章      下一篇文章      查看所有文章
加:2021-07-17 11:41:01  更:2021-07-17 11:43:00 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/6 2:15:17-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码