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
            )
     
    )
     
  • 相关阅读:
    Visual Studio 2019 使用 Web Deploy 发布远程站点到IIS服务器
    postman下载地址
    ASP.NET Core开发-Docker部署运行
    C# ffmpeg 视频处理格式转换具体案例
    C# ffmpeg 视频处理格式转换和添加水印
    C# ffmpeg 视频处理
    Tomcat 安装与配置
    Maven 快速入门
    Jenkins 快速搭建
    Google SRE 读书笔记 扒一扒SRE用的那些工具
  • 原文地址:https://www.cnblogs.com/krisy/p/3600562.html
Copyright © 2011-2022 走看看