PHP性能試験利器xhprof
4939 ワード
1、XHProfを取り付ける:
1
2
3
4
5
6
7
8
9
10
11
12
編集/etc/php.ini:
1
2
3
4
5
6
7
8
PHPサービス(/etc/init.d/php-fpm restart)を再起動して修正を有効にし、XHProfを使用できるようになりましたが、より効果的に表示されるようにGraphvizをインストールし続けたほうがいいです.
libpngとGraphvizのインストール:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
インストールが完了すると、/usr/local/bin/dotファイルが生成されます.パスがPATH環境変数にあることを確認して、XHProfがそれを見つけることができます.
XHProfを使用:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
これにより、上に設定xhprofが得られる.output_dirディレクトリには49 bafaa 3 a 3 f 66のような名前が生成される.xhprof_fooのデータファイルは、Webで簡単に閲覧できます.
次のように見えます.
Function Name
Calls
Calls%
Incl. Wall Time (microsec)
IWall%
Excl. Wall Time (microsec)
EWall%
main()
1
33.3%
1,000,135
100.0%
40
0.0%
sleep
1
33.3%
1,000,094
100.0%
1,000,094
100.0%
xhprof_disable
1
33.3%
1
0.0%
1
0.0%
[View Full Callgraph]をクリックすると、画像が表示されます.
【全文完了】
1
2
3
4
5
6
7
8
9
10
11
12
wget http:
//pecl
.php.net
/get/xhprof-0
.9.2.tgz
tar
zxf xhprof-0.9.2.tgz
cd
xhprof-0.9.2
mkdir
-p
/web/xhprof/output
cp
-r xhprof_html xhprof_lib
/web/xhprof
# xhprof
chown
-R web.web
/web/xhprof
cd
extension
phpize
.
/configure
make
make
install
make
test
#
編集/etc/php.ini:
1
2
3
4
5
6
7
8
[xhprof]
extension=xhprof.so
;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
;
xhprof.output_dir=/web/xhprof/output
PHPサービス(/etc/init.d/php-fpm restart)を再起動して修正を有効にし、XHProfを使用できるようになりましたが、より効果的に表示されるようにGraphvizをインストールし続けたほうがいいです.
libpngとGraphvizのインストール:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# , yum install libpng
wget http:
//sourceforge
.net
/projects/libpng/files/libpng15/1
.5.11
/libpng-1
.5.11.
tar
.gz
/download
tar
zxf libpng-1.5.11.
tar
.gz
cd
libpng-1.5.11
.
/configure
make
make
install
wget http:
//www
.graphviz.org
/pub/graphviz/stable/SOURCES/graphviz-2
.24.0.
tar
.gz
tar
zxf graphviz-2.24.0.
tar
.gz
cd
graphviz-2.24.0
.
/configure
make
make
install
dot -V
# dot
インストールが完了すると、/usr/local/bin/dotファイルが生成されます.パスがPATH環境変数にあることを確認して、XHProfがそれを見つけることができます.
XHProfを使用:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// start profiling
xhprof_enable();
// run program
sleep(1);
// stop profiler
$xhprof_data
= xhprof_disable();
//
// Saving the XHProf run
// using the default implementation of iXHProfRuns.
//
$XHPROF_ROOT
=
"/web/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();
// Save the run under a namespace "xhprof_foo".
//
// **NOTE**:
// By default save_run() will automatically generate a unique
// run id for you. [You can override that behavior by passing
// a run id (optional arg) to the save_run() method instead.]
//
$run_id
=
$xhprof_runs
->save_run(
$xhprof_data
,
"xhprof_foo"
);
echo
"<a href='/xhprof/xhprof_html/index.php?run=$run_id&source=xhprof_foo'>[display xhprof report]</a>"
;
これにより、上に設定xhprofが得られる.output_dirディレクトリには49 bafaa 3 a 3 f 66のような名前が生成される.xhprof_fooのデータファイルは、Webで簡単に閲覧できます.
次のように見えます.
Function Name
Calls
Calls%
Incl. Wall Time (microsec)
IWall%
Excl. Wall Time (microsec)
EWall%
main()
1
33.3%
1,000,135
100.0%
40
0.0%
sleep
1
33.3%
1,000,094
100.0%
1,000,094
100.0%
xhprof_disable
1
33.3%
1
0.0%
1
0.0%
[View Full Callgraph]をクリックすると、画像が表示されます.
【全文完了】