src/Debug.php
static public function end($ret = null)
    {
        // 非调试状态,不处理
        if (!self::isDebug()) {
            return $ret;
        }

        //分别统计三种操作的总耗时
        $counts = $sums = ['sql' => 0, 'net' => 0, 'debug' => 0, 'cache' => 0];
        $others = [];

        $sqls = [['方法', '用时', '堆栈', 'SQL语句']];
        $caches = [['类型', '操作', '堆栈', '键', '值']];
        $nets = [['用时', '地址', '数据']];

        foreach (self::$msgs as $key => $msg) {
            if (!is_array($msg)) {
                continue;
            }

            $type = $msg['type'];

            $sums[$type] += floatval(isset($msg['time']) ? $msg['time'] : 0);
            $counts[$type]++;

            if ($type == 'sql') {
                $sqls[] = [$msg['method'], $msg['time'] . ' ms', $msg['trace'], $msg['sql']];
            } elseif ($type == 'cache') {
                $caches[] = [$msg['server'], $msg['method'], $msg['info'], $msg['key'], $msg['value']];
            } elseif ($type == 'net') {
                $nets[] = [$msg['time'] . ' ms', $msg['url'], $msg['return']];
            } elseif (!is_string($msg)) {
                $others[] = json($msg);
            }
        }

        // 如果有数据库访问调试信息并且要求记录
        if (self::isDebug('sql') and $counts['sql']) {
            $sqls[] = ['全部 ' . $counts['sql'], round($sums['sql'], 3) . ' ms', '', ''];
        }

        //如果有网络调试信息,并要求记录
        if (self::isDebug('net') and $counts['net']) {
            $nets[] = ['全部 ' . $counts['net'], round($sums['net'], 3) . ' ms', ''];
        }

        // 否则是按模板输出
        $debug = [
            'persist' => self::getPersist(),
            'msgs' => [$sqls, $caches, $nets],
            'others' => $others
        ];

        // Ajax模式
        if (isAjax() or isset($_REQUEST['callback']) or is_array($ret)) {
            $ret['debug'] = $debug;
            return $ret;
        }

        // 如果是命令行模式,直接输出显示
        if (isCliMode()) {
            foreach ($debug['msgs'] as $info) {
                echo "\r\n";
                foreach ($info as $row) {
                    echo "\r\n";
                    foreach ($row as $item) {
                        echo $item . "\t\t";
                    }
                }
            }
            echo 'Persist:' . $debug['persist'] . "\r\n\r\n";
            return dump($debug, 'DEBUG', true);
        }

        // 显示输出模块
        {
            $persist = $debug['persist'];
            $usage = kmgt(memory_get_peak_usage());
            $msgs = $debug['msgs'];
            require __DIR__ . '/template.php';
        }

        return '';
    }
static public function end($ret = null)
    {
        // 非调试状态,不处理
        if (!self::isDebug()) {
            return $ret;
        }

        //分别统计三种操作的总耗时
        $counts = $sums = ['sql' => 0, 'net' => 0, 'debug' => 0, 'cache' => 0];
        $others = [];

        $sqls = [['方法', '用时', '堆栈', 'SQL语句']];
        $caches = [['类型', '操作', '堆栈', '键', '值']];
        $nets = [['用时', '地址', '数据']];

        foreach (self::$msgs as $key => $msg) {
            if (!is_array($msg)) {
                continue;
            }

            $type = $msg['type'];

            $sums[$type] += floatval(isset($msg['time']) ? $msg['time'] : 0);
            $counts[$type]++;

            if ($type == 'sql') {
                $sqls[] = [$msg['method'], $msg['time'] . ' ms', $msg['trace'], $msg['sql']];
            } elseif ($type == 'cache') {
                $caches[] = [$msg['server'], $msg['method'], $msg['info'], $msg['key'], $msg['value']];
            } elseif ($type == 'net') {
                $nets[] = [$msg['time'] . ' ms', $msg['url'], $msg['return']];
            } elseif (!is_string($msg)) {
                $others[] = json($msg);
            }
        }

        // 如果有数据库访问调试信息并且要求记录
        if (self::isDebug('sql') and $counts['sql']) {
            $sqls[] = ['全部 ' . $counts['sql'], round($sums['sql'], 3) . ' ms', '', ''];
        }

        //如果有网络调试信息,并要求记录
        if (self::isDebug('net') and $counts['net']) {
            $nets[] = ['全部 ' . $counts['net'], round($sums['net'], 3) . ' ms', ''];
        }

        // 否则是按模板输出
        $debug = [
            'persist' => self::getPersist(),
            'msgs' => [$sqls, $caches, $nets],
            'others' => $others
        ];

        // Ajax模式
        if (isAjax() or isset($_REQUEST['callback']) or is_array($ret)) {
            $ret['debug'] = $debug;
            return $ret;
        }

        // 如果是命令行模式,直接输出显示
        if (isCliMode()) {
            foreach ($debug['msgs'] as $info) {
                echo "\r\n";
                foreach ($info as $row) {
                    echo "\r\n";
                    foreach ($row as $item) {
                        echo $item . "\t\t";
                    }
                }
            }
            echo 'Persist:' . $debug['persist'] . "\r\n\r\n";
            return dump($debug, 'DEBUG', true);
        }

        // 显示输出模块
        {
            $persist = $debug['persist'];
            $usage = kmgt(memory_get_peak_usage());
            $msgs = $debug['msgs'];
            require __DIR__ . '/template.php';
        }

        return '';
    }
static public function end ( $ ret = null ) { // 非调试状态,不处理 if ( ! self :: isDebug ( ) ) { return $ ret ; } //分别统计三种操作的总耗时 $ counts = $ sums = [ 'sql' => 0 , 'net' => 0 , 'debug' => 0 , 'cache' => 0 ] ; $ others = [ ] ; $ sqls = [ [ '方法', '用 时 , '堆栈',  ' QL语句']]; $ caches = [ [ '类型', '操 作 , '堆栈',  ' ', '值']] ; $ nets = [ [ '用时', '地 址 , '数据']] ; foreach ( self :: $ msgs as $ key => $ msg ) { if ( ! is_array ( $ msg ) ) { continue ; } $ type = $ msg [ 'type' ] ; $ sums [ $ type ] += floatval ( isset ( $ msg [ 'time' ] ) ? $ msg [ 'time' ] : 0 ) ; $ counts [ $ type ] ++ ; if ( $ type == 'sql' ) { $ sqls [ ] = [ $ msg [ 'method' ] , $ msg [ 'time' ] . ' ms' , $ msg [ 'trace' ] , $ msg [ 'sql' ] ] ; } elseif ( $ type == 'cache' ) { $ caches [ ] = [ $ msg [ 'server' ] , $ msg [ 'method' ] , $ msg [ 'info' ] , $ msg [ 'key' ] , $ msg [ 'value' ] ] ; } elseif ( $ type == 'net' ) { $ nets [ ] = [ $ msg [ 'time' ] . ' ms' , $ msg [ 'url' ] , $ msg [ 'return' ] ] ; } elseif ( ! is_string ( $ msg ) ) { $ others [ ] = json ( $ msg ) ; } } // 如果有数据库访问调试信息并且要求记录 if ( self :: isDebug ( 'sql' ) and $ counts [ 'sql' ] ) { $ sqls [ ] = [ '全部 ' . $ o n ts['sq l '], r o u d($su m s ['sq l '], 3 ) ' m ', '' , '' ] } //如果有网络调试信息,并要求记录 if ( self :: isDebug ( 'net' ) and $ counts [ 'net' ] ) { $ nets [ ] = [ '全部 ' . $ o n ts['ne t '], r o u d($su m s ['ne t '], 3 ) ' m ', '' ] } // 否则是按模板输出 $ debug = [ 'persist' => self :: getPersist ( ) , 'msgs' => [ $ sqls , $ caches , $ nets ] , 'others' => $ others ] ; // Ajax模式 if ( isAjax ( ) or isset ( $ _REQUEST [ 'callback' ] ) or is_array ( $ ret ) ) { $ ret [ 'debug' ] = $ debug ; return $ ret ; } // 如果是命令行模式,直接输出显示 if ( isCliMode ( ) ) { foreach ( $ debug [ 'msgs' ] as $ info ) { echo "\r\n" ; foreach ( $ info as $ row ) { echo "\r\n" ; foreach ( $ row as $ item ) { echo $ item . "\t\t" ; } } } echo 'Persist:' . $ debug [ 'persist' ] . "\r\n\r\n" ; return dump ( $ debug , 'DEBUG' , true ) ; } // 显示输出模块 { $ persist = $ debug [ 'persist' ] ; $ usage = kmgt ( memory_get_peak_usage ( ) ) ; $ msgs = $ debug [ 'msgs' ] ; require __DIR__ . '/template.php' ; } return '' ; }
页面处理结束,在页面正文显示调试信息
@param $ret mixed 原来要处理的数据
@return string|array
页面处理结束 在页面正文显示调试信息