Linux 下安裝PHP性能分析工具 xhprof 筆記
為ECOS框架寫(xiě)了一個(gè)相關(guān)的APP應(yīng)用,前段時(shí)候要用xhprof來(lái)測(cè)試一下ECAE上的php的運(yùn)行效率又重新要安裝xhprof,本日志記錄下相關(guān)的過(guò)程,以便以后再次使用到。
編譯安裝
wget http://pecl.php.net/get/xhprof-0.9.2.tgztar zxf xhprof-0.9.2.tgzcd xhprof-0.9.2/extension/sudo phpize./configure --with-php-config=/usr/local/php/bin/php-configsudo makesudo make install
配置 php.ini
在php.ini里加入
[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=<directory_for_storing_xhprof_runs>xhprof.output_dir=/tmp/xhprof
注:如果是64位系統(tǒng)需要將xhprof.so文件拷貝到相關(guān)的lib64的目錄下
將代碼加入到要測(cè)試的php當(dāng)中
<?pho// cpu:XHPROF_FLAGS_CPU 內(nèi)存:XHPROF_FLAGS_MEMORY// 如果兩個(gè)一起:XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORYxhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);// 要測(cè)試的php代碼$data = xhprof_disable(); //返回運(yùn)行數(shù)據(jù)// xhprof_lib在下載的包里存在這個(gè)目錄,記得將目錄包含到運(yùn)行的php代碼中include_once 'xhprof_lib/utils/xhprof_lib.php';include_once 'xhprof_lib/utils/xhprof_runs.php';$objXhprofRun = new XHProfRuns_Default();// 第一個(gè)參數(shù)j是xhprof_disable()函數(shù)返回的運(yùn)行信息// 第二個(gè)參數(shù)是自定義的命名空間字符串(任意字符串),// 返回運(yùn)行ID,用這個(gè)ID查看相關(guān)的運(yùn)行結(jié)果$run_id = $objXhprofRun->save_run($data, 'xhprof');var_dump($run_id);
查看運(yùn)行結(jié)果
將xhprof_lib&&xhprof_html相關(guān)目錄copy到可以訪問(wèn)到的地址訪問(wèn) xxx/xhprof_html/index.php?run=$run_id&source=bluefrog 就可經(jīng)看到你的php代碼運(yùn)行的相關(guān)情況
下面是一些參數(shù)說(shuō)明
Inclusive Time 包括子函數(shù)所有執(zhí)行時(shí)間。Exclusive Time/Self Time 函數(shù)執(zhí)行本身花費(fèi)的時(shí)間,不包括子樹(shù)執(zhí)行時(shí)間。Wall Time 花去了的時(shí)間或掛鐘時(shí)間。CPU Time 用戶耗的時(shí)間+內(nèi)核耗的時(shí)間Inclusive CPU 包括子函數(shù)一起所占用的CPUExclusive CPU 函數(shù)自身所占用的CPU
注:?需要使用ctype這個(gè)擴(kuò)展
相關(guān)文章:
1. Spring security 自定義過(guò)濾器實(shí)現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實(shí)例代碼)2. Java8內(nèi)存模型PermGen Metaspace實(shí)例解析3. python tkinter實(shí)現(xiàn)下載進(jìn)度條及抖音視頻去水印原理4. ASP.NET MVC使用正則表達(dá)式驗(yàn)證手機(jī)號(hào)碼5. 一文搞懂 parseInt()函數(shù)異常行為6. Python 有可能刪除 GIL 嗎?7. Python使用sftp實(shí)現(xiàn)上傳和下載功能8. python捕獲警告的三種方法9. python 統(tǒng)計(jì)list中各個(gè)元素出現(xiàn)的次數(shù)的幾種方法10. Python基于百度AI實(shí)現(xiàn)抓取表情包
