php藉助Tideways擴展封裝輔助函數分析代碼執行性能

Tideways的安裝和使用:https://success.blog.csdn.net/article/details/103365063

static關鍵字實現單例模式:https://success.blog.csdn.net/article/details/103718450

 

函數代碼:

​
if (!function_exists('tideways')){
    function &tideways($begin = true, $file = '', $dir = '/tmp/')
    {
        static $data = [];
        if ($begin){
            extension_loaded('tideways_xhprof');
            tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_CPU | TIDEWAYS_XHPROF_FLAGS_MEMORY);
            $data['begin'] = microtime(true);
        }else{
            $data['end'] = microtime(true);
            $dir  = sprintf('%s%s-%s.log',  $dir, $file, date('Y-m-d', time()));
            $content = json_encode(tideways_xhprof_disable());
            file_put_contents($dir, $content);
        }

        return $data;
    }
}

​

使用代碼

tideways(true);

run code ......

tideways(false, substr(basename(__FILE__), 0, -4));

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章