php運行狀態報表工具:php-timer

來源:互聯網
上載者:User
最近寫了一個非同步mysql用戶端的封裝,想與傳統的串列方式做下效能對比。包括已耗用時間、記憶體使用量情況等資訊。在github和packagist上搜尋並沒有找到自己想要的,xhprof又太大了,結果也太複雜,不符合現在的需要。所以決定自己寫一個package,來實現對php指令碼已耗用時間和記憶體使用量情況的監控,並產生報告。

範例程式碼:

requiredirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR .'vendor'. DIRECTORY_SEPARATOR .'autoload.php';//初始化,設定記憶體單位$timer=new\Jenner\Timer(\Jenner\Timer::UNIT_KB);//記錄a狀態$timer->mark('a');sleep(2);//記錄b狀態$timer->mark('b');sleep(3);//記錄c狀態$timer->mark('c');sleep(4);//記錄d狀態$timer->mark('d');//列印總體報告(不包含差值)$timer->printReport();//擷取總體報告,返回數組$report=$timer->getReport();//擷取一個mark的報告$a_report=$timer->getReport('a');print_r($a_report);//列印a狀態和b狀態的差異資訊,包含已耗用時間、使用記憶體等$timer->printDiffReportByStartAndEnd('a','b');//擷取a狀態和b狀態的差異報告$ab_diff_report=$timer->getDiffReportByStartAndEnd('a','b');//列印第一個mark和最後一個mark之間的差異資訊$timer->printDiffReport();//擷取第一個mark和最後一個mark之間的差異資訊$diff_report=$timer->getDiffReport();

輸出結果:

 ------------------------------------------mark:atime:1437535424.9998smemory_real:1280KBmemory_emalloc:833.046875KBmemory_peak_real:1280KBmemory_peak_emalloc:843.2890625KB------------------------------------------mark:btime:1437535427smemory_real:1280KBmemory_emalloc:834.2265625KBmemory_peak_real:1280KBmemory_peak_emalloc:843.2890625KB------------------------------------------mark:ctime:1437535430.0002smemory_real:1280KBmemory_emalloc:835.1875KBmemory_peak_real:1280KBmemory_peak_emalloc:843.2890625KB------------------------------------------mark:dtime:1437535434.0004smemory_real:1280KBmemory_emalloc:836.1484375KBmemory_peak_real:1280KBmemory_peak_emalloc:843.2890625KBArray(    [time] => 1437535424.9998    [memory_real] => 1310720    [memory_emalloc] => 853040    [memory_peak_real] => 1310720    [memory_peak_emalloc] => 863528)------------------------------------------mark:[diff] start_mark:a end_mark:btime:2.0001850128174smemory_real:0KBmemory_emalloc:1.1796875KBmemory_peak_real:0KBmemory_peak_emalloc:0KB------------------------------------------mark:[totaldiff]time:9.0006000995636smemory_real:0KBmemory_emalloc:3.1015625KBmemory_peak_real:0KBmemory_peak_emalloc:0KB

項目首頁:http://www.open-open.com/lib/view/home/1437969396019

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.