国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

PHP性能分析工具XHProf安裝使用教程

2024-04-25 20:16:40
字體:
供稿:網(wǎng)友

HProf是facebook開源出來的一個(gè)php輕量級的性能分析工具,跟Xdebug類似,但性能開銷更低,還可以用在生產(chǎn)環(huán)境中,也可以由程序開關(guān)來控制是否進(jìn)行profile。基于瀏覽器的性能分析用戶界面能更容易查看,或是與同行們分享成果。也能繪制調(diào)用關(guān)系圖。在數(shù)據(jù)收集階段,它記錄調(diào)用次數(shù)的追蹤和包容性的指標(biāo)弧在動態(tài)callgraph的一個(gè)程序。

它獨(dú)有的數(shù)據(jù)計(jì)算的報(bào)告/后處理階段。在數(shù)據(jù)收集時(shí),XHProfd通過檢測循環(huán)來處理遞歸的函數(shù)調(diào)用,并通過給遞歸調(diào)用中每個(gè)深度的調(diào)用一個(gè)有用的命名來避開死循環(huán)。

XHProf的輕量級性質(zhì)和匯聚功能,使得它非常適合用于收集“生產(chǎn)環(huán)境”的性能統(tǒng)計(jì)數(shù)據(jù)的統(tǒng)計(jì)。

1. 安裝XHProf,代碼如下:

  1. wget http://pecl.php.net/get/xhprof-0.9.2.tgz 
  2. tar zxf xhprof-0.9.2.tgz 
  3. cd xhprof-0.9.2 
  4. cp -r xhprof_html xhprof_lib <directory_for_htdocs> 
  5. cd extension 
  6. phpize 
  7. ./configure 
  8. make 
  9. make install 

2. 配置 php.ini 文件,代碼如下:

  1. [xhprof] 
  2. extension=xhprof.so 
  3. ; directory used by default implementation of the iXHProfRuns 
  4. interface (namely, the XHProfRuns_Default classfor storing 
  5. ; XHProf runs. 
  6. ; 記得<directory_for_storing_xhprof_runs>WEB要有寫入權(quán)限 
  7. xhprof.output_dir=<directory_for_storing_xhprof_runs> 

重啟服務(wù)讓修改生效,現(xiàn)在就可以使用XHProf了,不過為了顯示效果更炫,最好繼續(xù)安裝Graphviz。

3. 安裝Graphviz,代碼如下:

  1. wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.26.3.tar.gz   
  2. tar zxf graphviz-2.26.3.tar.gz    
  3. cd graphviz-2.26.3   
  4. ./configure 
  5. make    
  6. make install 

安裝完成后,會生成/usr/local/bin/dot文件,你應(yīng)該確保路徑在PATH環(huán)境變量里,以便XHProf能找到它。

4. 應(yīng)用XHProf,代碼如下:

  1. xhprof_enable();//打開xhprof 
  2. /******程序邏輯 Start******/ 
  3. function test1(){ 
  4.  sleep(3); 
  5.  return
  6. function test2(){ 
  7.  test1(); 
  8. function test3(){ 
  9.  test2(); 
  10. function p(){ 
  11.  echo '<h3>xhprof test</h3>'
  12. p(); 
  13. test3(); 
  14. /******程序邏輯 End******/ 
  15.  
  16. $xhprof_data = xhprof_disable();//關(guān)閉xhprof 
  17.  
  18. //保存xhprof數(shù)據(jù) 
  19. include_once '../xhprof_lib/utils/xhprof_lib.php'
  20. include_once '../xhprof_lib/utils/xhprof_runs.php'
  21.  
  22. $xhprof_runs = new XHProfRuns_Default(); 
  23. $xhprof_source = 'xhprof_test'
  24. $run_id = $xhprof_runs->save_run($xhprof_data$xhprof_source); 
  25. $report_url = 'http://xhprof.rebill.info/index.php?run='.$run_id.'&source='.$xhprof_source
  26. echo '<br>'
  27. echo 'view the performance report:<a href="'.$report_url.'" target="_blank">'.$report_url.'</a>'

如此一來,會在上面設(shè)定的xhprof.output_dir目錄里生成名字類似4c236583ef490.xhprof_test的數(shù)據(jù)文件,可以很方便的通過Web方式瀏覽效果:

http://xhprof.rebill.info/index.php?run=4c236583ef490&source=xhprof_test

目前顯示的是表格形式的顯示,點(diǎn)擊頁面上的[View Full Callgraph],就能看到精美的圖片顯示了。

在線測試體驗(yàn)地址:http://xhprof.rebill.info/test.php

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 海南省| 郓城县| 成武县| 大竹县| 潍坊市| 泉州市| 天峻县| 三穗县| 岱山县| 香河县| 德化县| 通化县| 嵊泗县| 遵化市| 青铜峡市| 衡阳市| 濮阳市| 安庆市| 大同市| 台中市| 大埔县| 牟定县| 夹江县| 裕民县| 东城区| 崇明县| 都兰县| 平遥县| 无锡市| 讷河市| 新密市| 兴化市| 宁晋县| 得荣县| 蓬安县| 隆化县| 崇义县| 灌阳县| 江川县| 太湖县| 卫辉市|