zoukankan      html  css  js  c++  java
  • php ticks 调试应用

    declare(ticks=1);
    register_tick_function('do_profile');
    register_shutdown_function('show_profile');
     
    $profile = array();
    $last_time = microtime(true);
     
    a();
     
    function do_profile() {
        global $profile, $last_time;
        $bt = debug_backtrace();
        if (count($bt) <= 1) {
            return ;
        }
        $frame = $bt[1];
        unset($bt);
        $function = $frame['function'];
        if (!isset($profile[$function])) {
            $profile[$function] = array(
                'time'  => 0,
                'calls' => 0
            );
        }
        $profile[$function]['calls']++;
        $profile[$function]['time'] += (microtime(true) - $last_time);
        $last_time = microtime(true);
    }
     
    function show_profile() {
        global $profile;
        print_r($profile);
    }
     
    function a() {
        usleep(50 * 1000);
        b();
    }
     
    function b() {
        usleep(500 * 1000);
        c();
    }
     
    function c() {
        usleep(5000 * 1000);
    }

    输出:

    Array
    (
        [a] => Array
            (
                [time] => 0.0511748790741
                [calls] => 2
            )
     
        [b] => Array
            (
                [time] => 0.500598907471
                [calls] => 2
            )
     
        [c] => Array
            (
                [time] => 5.00052690506
                [calls] => 1
            )
     
    )
     
  • 相关阅读:
    "rel=nofollow"属性简介
    js获取微信code
    css--clearfix浮动
    css3--之HSL颜色
    数据库列名为关键字如何搜索
    flexigrid
    easyui-dialog
    关于在jsp中的表达式
    jquery 中 $('div','li')
    myeclipse中常用的快捷键
  • 原文地址:https://www.cnblogs.com/krisy/p/3600562.html
Copyright © 2011-2022 走看看