<?php
if (class_exists('RvsLibs_Benchmark_register') === false) {
Class RvsLibs_Benchmark_register
{
var $aBenchmarkLog = array();
var $_sections = array();
var $markers = array();
var $_lastLine = array();
var $_lastTime = array();
var $_LogOver = array();
public static function singleton($autoLoad = false, $oFreeze=null)
{
static $instance;
if (is_null($oFreeze) === false) {
$instance = $oFreeze;
}
if (!isset($instance) || $autoLoad) {
$class = __CLASS__;
$instance = new $class($autoLoad);
}
return $instance;
}
}
}
if (class_exists('RvsLibs_Benchmark') === false) {
Class RvsLibs_Benchmark
{
public static function config($logLeval = 0, $aConfig = array())
{
$logLeval = md5($logLeval);
$oBenchmarkReg = RvsLibs_Benchmark_register::singleton();
if (isset($aConfig['log over'])) {
$oBenchmarkReg->_LogOver[$logLeval] = (int)$aConfig['log over'];
}
}
public static function unsetLog($logLeval = 0)
{
$logLeval = md5($logLeval);
$oBenchmarkReg = RvsLibs_Benchmark_register::singleton();
$oBenchmarkReg->_lastTime[$logLeval] = 0;
}
public static function benchmarkLog($msg = '', $logLeval = 0)
{
if (version_compare(phpversion(), '4.3.0') >= 0) {
$bt = debug_backtrace();
$logLeval = md5($logLeval);
if (isset($bt[1]['class']) && $bt[1]['type'] && isset($bt[1]['function'])) {
//$callInfo = $bt[1]['class'] . $bt[1]['type'] . $bt[1]['function'] . ': ';
//$bt[0]['line'] . ' of "' . $bt[0]['file'] . '"';
}
$_class = isset($bt[1]['class']) ? $bt[1]['class'] : 'not class';
$_func = isset($bt[1]['function']) ? $bt[1]['function'] : 'not func';
$_line = isset($bt[0]['line']) ? $bt[0]['line'] : 'not line';
$oBenchmarkReg = RvsLibs_Benchmark_register::singleton();
if (in_array($logLeval, $oBenchmarkReg->markers) === false) {
$oBenchmarkReg->markers[] = $logLeval;
}
$logkey = array_search($logLeval, $oBenchmarkReg->markers);
if (empty($oBenchmarkReg->_lastTime[$logLeval]) || $oBenchmarkReg->_lastTime[$logLeval] == 0) {
$msg = "Benchmark Log [{$logkey}] at {$_class}::{$_func} Line: {$_line} Start Benchmark Log";
$oBenchmarkReg->_lastLine[$logLeval] = "{$_class}::{$_func} Line: {$_line}";
$oBenchmarkReg->_lastTime[$logLeval] = getSystemTime();
SGL::logMessage($msg, PEAR_LOG_DEBUG);
} else {
$lastTime = $oBenchmarkReg->_lastTime[$logLeval];
$oBenchmarkReg->_lastTime[$logLeval] = getSystemTime();
$useTime = $oBenchmarkReg->_lastTime[$logLeval] - $lastTime;
$thisLine = "{$_class}::{$_func} Line: {$_line}";
$maxLog = isset( $oBenchmarkReg->_LogOver[$logLeval]) ? (int) $oBenchmarkReg->_LogOver[$logLeval] : 600;
if ($useTime > $maxLog) {
$isLoop = ($thisLine == $oBenchmarkReg->_lastLine[$logLeval]) ? '(Loop) ' : '';
$msg = "Benchmark Log [{$logkey}] {$oBenchmarkReg->_lastLine[$logLeval]} to {$_class}::{$_func} Line: {$_line} {$isLoop}use {$useTime} ms. {$msg}";
SGL::logMessage($msg, PEAR_LOG_DEBUG);
}
$oBenchmarkReg->_lastLine[$logLeval] = $thisLine;
}
}
}
}
}
?>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez