joomla1.56 profiler.php
来源:互联网 发布:android 申请网络权限 编辑:程序博客网 时间:2024/05/01 12:41
windows获得内存有点迷糊
- <?php
- /**
- * @version $Id: profiler.php 10707 2008-08-21 09:52:47Z eddieajau $
- * @package Joomla.Framework
- * @subpackage Error
- * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
- * @license GNU/GPL, see LICENSE.php
- * Joomla! is free software. This version may have been modified pursuant
- * to the GNU General Public License, and as distributed it includes or
- * is derivative of works licensed under the GNU General Public License or
- * other free or open source software licenses.
- * See COPYRIGHT.php for copyright notices and details.
- */
- // Check to ensure this file is within the rest of the framework
- //查看标志
- defined('JPATH_BASE') or die();
- /**
- * Utility class to assist in the process of benchmarking the execution
- * of sections of code to understand where time is being spent.
- *
- * @package Joomla.Framework
- * @subpackage Error
- * @since 1.0
- */
- class JProfiler extends JObject//继承jobject
- {
- /**
- *
- * @var int
- */
- var $_start = 0;
- /**
- *
- * @var string
- */
- var $_prefix = '';
- /**
- *
- * @var array
- */
- var $_buffer= null;
- /**
- * Constructor
- *
- * @access protected
- * @param string Prefix for mark messages
- */
- function __construct( $prefix = '' )
- {
- $this->_start = $this->getmicrotime();//设置开始时间
- $this->_prefix = $prefix;//设置前缀
- $this->_buffer = array();//空数组
- }
- /**
- * Returns a reference to the global Profiler object, only creating it
- * if it doesn't already exist.
- * 创建一个jprofiler实例,有防止重复创建的功能
- * This method must be invoked as:
- * <pre> $browser = & JProfiler::getInstance( $prefix );</pre>
- *
- * @access public
- * @param string Prefix used to distinguish profiler objects.
- * @return JProfiler The Profiler object.
- */
- function &getInstance($prefix = '')
- {
- //joomla系统的分析的$prefix=application
- static $instances;//防止重复
- if (!isset($instances)) {//头一回
- $instances = array();
- }
- if (emptyempty($instances[$prefix])) {//无重复,创建实例
- $instances[$prefix] = new JProfiler($prefix);
- }
- return $instances[$prefix];//返回实例
- }
- /**
- * Output a time mark
- *
- * The mark is returned as text enclosed in <div> tags
- * with a CSS class of 'profiler'.
- *
- * @access public
- * @param string A label for the time mark
- * @return string Mark enclosed in <div> tags
- */
- function mark( $label )
- {
- $mark = $this->_prefix." $label: ";//加上一个标签
- //开始到现在的用了多少时间,时间度量为毫秒
- $mark .= sprintf('%.3f', $this->getmicrotime() - $this->_start) . ' seconds';
- //如果存在memory_get_usage函数,加上PHP使用的内存,这个函数返回的单位是字节
- if ( function_exists('memory_get_usage') ) {
- $mark .= ', '.sprintf('%0.2f', memory_get_usage() / 1048576 ).' MB';
- }
- //放到_buffer中
- $this->_buffer[] = $mark;
- return $mark;
- }
- /**
- * Get the current time.
- * 取得现在的时间,毫秒为单位
- * @access public
- * @return float The current time
- */
- function getmicrotime()
- {
- list( $usec, $sec ) = explode( ' ', microtime() );
- return ((float)$usec + (float)$sec);
- }
- /**
- * Get information about current memory usage.
- *
- * @access public
- * @return int The memory usage
- * @link PHP_MANUAL#memory_get_usage
- */
- function getMemory()
- {
- static $isWin;
- if (function_exists( 'memory_get_usage' )) {
- return memory_get_usage();
- } else {
- // Determine if a windows server
- if (is_null( $isWin )) {
- $isWin = (substr(PHP_OS, 0, 3) == 'WIN');
- }
- // Initialize variables
- $output = array();
- $pid = getmypid();//进程ID
- if ($isWin) {
- // Windows workaround
- @exec( 'tasklist /FI "PID eq ' . $pid . '" /FO LIST', $output );
- if (!isset($output[5])) {
- $output[5] = null;
- }
- return substr( $output[5], strpos( $output[5], ':' ) + 1 );
- } else {
- @exec("ps -o rss -p $pid", $output);//ps shell命令
- return $output[1] *1024;
- }
- }
- }
- /**
- * Get all profiler marks.
- * 返回所有分析标志的结果
- * Returns an array of all marks created since the Profiler object
- * was instantiated. Marks are strings as per {@link JProfiler::mark()}.
- *
- * @access public
- * @return array Array of profiler marks
- */
- function getBuffer() {
- return $this->_buffer;
- }
- }
- joomla1.56 profiler.php
- joomla1.56 loader.php
- profiler
- Profiler
- Joomla1.5模板特征
- Joomla1.5学习笔记
- Xdebug分析Php脚本性能(xdebug.profiler)
- joomla1.5重新安装的方法
- joomla1.6的权限控制
- 学习Joomla1--密码加密方式
- 学习joomla1.5扩展开发
- joomla1.5与Phpbb3的桥接
- SQL Profiler
- SQL Profiler
- java profiler
- java profiler
- simple profiler
- VS2010 profiler
- J2ee测试工具
- 螺旋矩阵
- ORACLE字段排序
- java历史-偶感杂谈
- VC 编辑框 改变背景、字体、文本颜色、长度限制、英文 汉字判断
- joomla1.56 profiler.php
- codepage的概念
- 软件工程的25条建议
- Apache2 httpd.conf 中文版
- ORACLE控制文件的重建
- 位图文件读写综述
- 用实体关系图进行数据库建模
- 利用堆栈求多项式
- C# 常见错误处理