【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了Profiler.php提供大家参考,希望对大家有所帮助!
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to version 1.0 of the Zend Framework
* license, that is bundled with this package in the file LICENSE, and
* is available through the world-wide-web at the following URL:
* http://www.zend.com/license/framework/1_0.txt. If you did not receive
* a copy of the Zend Framework license and are unable to obtain it
* through the world-wide-
web, please send a note to license@zend.com
* so we can mail you a copy immediately.
*
* @package Zend_Db
* @subpackage Profiler
* @copyright Copyright (c) 2005-2006 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0
*/
/**
* Zend_Db_Profiler_Query
*/
require_once 'Zend/Db/Profiler/Query.php';
/**
* Zend_Db_Profiler_Exception
*/
require_once 'Zend/Db/Profiler/Exception.php';
/**
* @package Zend_Db
* @subpackage Profiler
* @copyright Copyright (c) 2005-2006 Zend Technologies Inc. (http://www.zend.com)
* @license Zend Framework License version 1.0
*/
class Zend_Db_Profiler
{
/**
* A connection operation or selecting a database.
*/
const CONNECT = 1;
/**
* Any general database query that does not fit into the other constants.
*/
const QUERY = 2;
/**
* Adding new data to the database, such as SQL's INSERT.
*/
const INSERT = 4;
/**
* Updating existing information in the database, such as SQL's UPDATE.
*
*/
const UPDATE = 8;
/**
* An operation related to deleting data in the database,
* such as SQL's DELETE.
*/
const DELETE = 16;
/**
* Retrieving information from the database, such as SQL's SELECT.
*/
const SELECT = 32;
/**
* Transactional operation, such as start transaction, commit, or rollback.
*/
const TRANSACTION = 64;
/**
* Array of Zend_Db_Profiler_Query objects.
*
* @var Zend_Db_Profiler_Query
*/
protected $_queryProfiles = array();
/**
* Stores enabled state of the profiler. If set to False, calls to
* queryStart() will simply be ignored.
*
* @var bool
*/
protected $_enabled = false;
/**
* Stores the number of seconds to filter. NULL if filtering by time is
* disabled. If an integer is stored here, profiles whose elapsed time
* is less than this value in seconds will be unset from
* the self::$_queryProfiles array.
*
* @var integer
*/
protected $_filterElapsedSecs = null;
/**
* Logical OR of any of the filter constants. NULL if filtering by query
* type is disable. If an integer is stored here, it is the logical OR of
* any of the query type constants. When the query ends, if it is not
* one of the types specified, it will be unset from the
* self::$_queryProfiles array.
*
* @var integer
*/
protected $_filterTypes = null;
/**
* Class constructor. The profiler is disabled by default unless it is
* specifically enabled by passing in $enabled here or calling setEnabled().
*
* @param bool $enabled
*/
public function __construct($enabled=false)
{
$this->setEnabled($enabled);
}
/**
* Enable or disable the profiler. If $enable is false, the profiler
* is disabled and will not log any queries sent to it.
*
* @param bool $enable
* @return bool
*/
public function setEnabled($enable)
{
$this->_enabled = $enable;
return true;
}
/**
* Sets a minimum number of seconds for saving query profiles. If this
* is set, only those queries whose elapsed time is equal or greater than
* $minimumSeconds will be saved. To save all queries regardless of
* elapsed time, set $minimumSeconds to null.
*
* @param int $minimumSeconds
* @return bool
*/
public function setFilterElapsedSecs($minimumSeconds=null)
{
if (is_null($minimumSeconds)) {
$this->_filterElapsedSecs = null;
}
$this->_filterElapsedSecs = $minimumSeconds;
return true;
}
/**
* Sets the types of query profiles to save. Set $queryType to one of
* the Zend_Db_Profiler::* constants to only save profiles for that type of
* query. To save more than one type, logical OR them together. To
* save all queries regardless of type, set $queryType to null.
*
* @param null|integer $queryTypes
*/
public function setFilterQueryType($queryTypes=null)
{
$this->_filterTypes = $queryTypes;
return true;
}
/**
* Get the current state of enable. If True is returned,
* the profiler is enabled.
*
* @return bool
*/
public function getEnabled()
{
return $this->_enabled;
}
/**
* Clears the history of any past query profiles. This is unrelentless
* and will even clear queries that were started and may not have
* been marked as ended.
*
* @return unknown
*/
public function clear()
{
$this->_queryProfiles = array();
return true;
}
/**
* Start a query. Cre