ProfilerSimple
Package | engine.lib |
---|---|
Inheritance | class ProfilerSimple |
Since | 1.0 |
Source Code | /engine/lib/internal/ProfilerSimple/Profiler.class.php |
Ведение профайлинга
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
aTimes | array | Массив данных | ProfilerSimple |
bEnable | bool | Статус активности профайлера | ProfilerSimple |
iTimeId | int | Счетчик | ProfilerSimple |
iTimePidCurrent | int|null | Текущий родитель | ProfilerSimple |
oInstance | ProfilerSimple | Инстанция профайлера | ProfilerSimple |
sFileName | string|null | Путь до файла лога профайлера | ProfilerSimple |
sRequestId | string | Уникальный номер | ProfilerSimple |
Public Methods
Method | Description | Defined By |
---|---|---|
Save() | Сохранение лога в файл | ProfilerSimple |
Start() | Запуск подсчета времени выполнения операции | ProfilerSimple |
Stop() | Завершение подсчета времени выполнения операции | ProfilerSimple |
__destruct() | Сохраняем лог при завершении работы | ProfilerSimple |
getInstance() | Ограничиваем объект только одним экземпляром | ProfilerSimple |
Protected Methods
Method | Description | Defined By |
---|---|---|
GetTimeFull() | Вычисляет полное время замера | ProfilerSimple |
__construct() | Инициализация | ProfilerSimple |
Property Details
aTimes
property
protected array $aTimes;
Массив данных
bEnable
property
protected bool $bEnable;
Статус активности профайлера
iTimeId
property
protected int $iTimeId;
Счетчик
iTimePidCurrent
property
protected int|null $iTimePidCurrent;
Текущий родитель
oInstance
property
protected static ProfilerSimple $oInstance;
Инстанция профайлера
sFileName
property
protected string|null $sFileName;
Путь до файла лога профайлера
sRequestId
property
protected string $sRequestId;
Уникальный номер
Method Details
GetTimeFull()
method
protected float GetTimeFull(int $iTimeId)
| ||
$iTimeId | int | Номер операции |
{return} | float |
Source Code: /engine/lib/internal/ProfilerSimple/Profiler.class.php#173 (show)
protected function GetTimeFull($iTimeId) {
list($iStartSeconds,$iStartGeneral)=explode(' ',$this->aTimes[$this->sRequestId.$iTimeId]['time_start'],2);
list($iStopSeconds,$iStopGeneral)=explode(' ',$this->aTimes[$this->sRequestId.$iTimeId]['time_stop'],2);
return ($iStopSeconds-$iStartSeconds)+($iStopGeneral-$iStartGeneral);
}
Вычисляет полное время замера
Save()
method
public bool Save()
| ||
{return} | bool |
Source Code: /engine/lib/internal/ProfilerSimple/Profiler.class.php#137 (show)
public function Save() {
if (!$this->bEnable or !$this->sFileName) {
return false;
}
if ($fp=fopen($this->sFileName,"a")) {
foreach ($this->aTimes as $aTime) {
/**
* Проверяем есть ли "открытые" счетчики
*/
if (!isset($aTime['time_full'])) {
$this->Stop($aTime['time_id']);
$aTime=$this->aTimes[$aTime['request_id'].$aTime['time_id']];
}
if(!isset($aTime['time_pid'])) $aTime['time_pid']=0;
if(isset($aTime['time_comment']) and $aTime['time_comment']!='') {
$aTime['time_comment'] = preg_replace('/\s{1,}/',' ',$aTime['time_comment']);
}
$s=date('Y-m-d H:i:s')."\t{$aTime['request_id']}\t{$aTime['time_full']}\t{$aTime['time_start']}\t{$aTime['time_stop']}\t{$aTime['time_id']}\t{$aTime['time_pid']}\t{$aTime['time_name']}\t{$aTime['time_comment']}\r\n";
fwrite($fp,$s);
}
fclose($fp);
}
}
Сохранение лога в файл
Start()
method
public bool|int Start(string $sName, string $sComment='')
| ||
$sName | string | Название операции |
$sComment | string | Описание |
{return} | bool|int |
Source Code: /engine/lib/internal/ProfilerSimple/Profiler.class.php#102 (show)
public function Start($sName,$sComment='') {
if (!$this->bEnable) {
return false;
}
$this->iTimeId++;
$this->aTimes[$this->sRequestId.$this->iTimeId]=array(
'request_id' => $this->sRequestId,
'time_id' => $this->iTimeId,
'time_pid' => $this->iTimePidCurrent,
'time_name' => $sName,
'time_comment' => $sComment,
'time_start' => microtime(),
);
$this->iTimePidCurrent=$this->iTimeId;
return $this->iTimeId;
}
Запуск подсчета времени выполнения операции
Stop()
method
public bool Stop(int $iTimeId)
| ||
$iTimeId | int | Номер операции |
{return} | bool |
Source Code: /engine/lib/internal/ProfilerSimple/Profiler.class.php#124 (show)
public function Stop($iTimeId) {
if (!$this->bEnable or !$iTimeId or !isset($this->aTimes[$this->sRequestId.$iTimeId])) {
return false;
}
$this->aTimes[$this->sRequestId.$iTimeId]['time_stop']=microtime();
$this->aTimes[$this->sRequestId.$iTimeId]['time_full']=$this->GetTimeFull($iTimeId);
$this->iTimePidCurrent=$this->aTimes[$this->sRequestId.$iTimeId]['time_pid'];
}
Завершение подсчета времени выполнения операции
__construct()
method
protected void __construct(string $sFileName, bool $bEnable)
| ||
$sFileName | string | Путь до файла лога профайлера |
$bEnable | bool | Статус активности |
Source Code: /engine/lib/internal/ProfilerSimple/Profiler.class.php#73 (show)
protected function __construct($sFileName,$bEnable) {
$this->bEnable=$bEnable;
$this->sFileName=$sFileName;
$this->sRequestId=func_generator(32);
$this->iTimeId=0;
}
Инициализация
__destruct()
method
public void __destruct()
|
Source Code: /engine/lib/internal/ProfilerSimple/Profiler.class.php#164 (show)
public function __destruct() {
$this->Save();
}
Сохраняем лог при завершении работы
getInstance()
method
public static ProfilerSimple getInstance(null $sFileName=NULL, bool $bEnable=true)
| ||
$sFileName | null | Путь до файла лога профайлера |
$bEnable | bool | Статус активности |
{return} | ProfilerSimple |
Source Code: /engine/lib/internal/ProfilerSimple/Profiler.class.php#87 (show)
static public function getInstance($sFileName=null,$bEnable=true) {
if (isset(self::$oInstance)) {
return self::$oInstance;
} else {
self::$oInstance= new self($sFileName,$bEnable);
return self::$oInstance;
}
}
Ограничиваем объект только одним экземпляром