• XHPROF相关内容


    定义入口文件

    define('XHPROF_OPEN', 0);
    define('XHPROF_ROOT', '/home/www/xhprof/');
    
    // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false
    define('APP_DEBUG',true);
    
    // 定义应用目录
    define('APP_PATH','../app/');
    define('LOG_PATH',APP_PATH.'Runtime/Logs/');
    
    if(defined('XHPROF_OPEN') && XHPROF_OPEN) {
        require ('./xhprof.php');
    }

    加载xhprof.php

    <?php
    if (!defined('XHPROF_OPEN')) define('XHPROF_OPEN', 0);
    class Xhprof
    {
        private static $st = 0;
    
        /**
         * [start description]
         * @return [type] [description]
         */
        public static function start()
        {
            if (!function_exists('xhprof_enable')) {
                exit("xhprof_enable not exists!");
            } 
            if (!is_dir(XHPROF_ROOT)) {
                exit(XHPROF_ROOT . " not exists!");
            }
            //xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
            xhprof_enable(XHPROF_FLAGS_NO_BUILTINS |XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
            self::$st = microtime(true);
            register_shutdown_function(array(__CLASS__, 'end')); //php进程关闭时自动执行的方法
        }
    
        /**
         * [end description]
         * @return [type] [description]
         */
        public static function end()
        {
            $et = microtime(true);
            $data = xhprof_disable();
    
            include_once XHPROF_ROOT."xhprof_lib/utils/xhprof_lib.php";
            include_once XHPROF_ROOT."xhprof_lib/utils/xhprof_runs.php";
            $runs = new XHProfRuns_Default();
            $runId = $runs->save_run($data, "hx");
    
            $log = XHPROF_ROOT . 'xhprof_html/logs/'.date('YmdHis').'.html';
            $cost = $et - self::$st;
            $host = $_SERVER['HTTP_HOST'];
            $title = $_SERVER['REQUEST_URI'];
            $content = 'Time: '.date('H:i:s')."	Cost: {$cost}		Uri({$host}): <a href='/index.php?run={$runId}&source=hx' target='_blank'>{$title}</a><br/>";
            file_put_contents($log, $content, FILE_APPEND);
        }
    }
    if(XHPROF_OPEN) Xhprof::start();
    XHPROF_OPEN 调试为1就可用
  • 相关阅读:
    零基础学python-4.5 标准类型分类
    零基础学python-4.4 常用的一些内建函数
    零基础学python-4.3 对象的比较
    零基础学python-4.2 其他内建类型
    零基础学python-4.1 python对象的简介和标准类型
    7、postman中的Newman插件(可生成html测试报告)
    6、postman cookie和token使用
    5、postman认证方式简单了解
    4、postman动态参数传递(含token详细使用)
    3、postman中tests断言使用
  • 原文地址:https://www.cnblogs.com/wicub/p/6225350.html
Copyright © 2020-2023  润新知