oMapper=new Mapper_Profiler($this->Database_GetConnect()); $this->hLog = @fopen(Config::Get('path.root.server').'/logs/'.Config::Get('sys.logs.profiler_file'),'r+'); } /** * Добавить новую запись в базу данных * * @param ProfilerEntity_Entry $oEntry * @return bool */ public function AddEntry(ProfilerEntity_Entry $oEntry) { return $this->oMapper->AddEntry($oEntry); } /** * Читает из лог-файла записи * * @param string $sPath * @return ProfilerEntity_Entry */ public function ReadEntry() { /** * Если хендлер не определен, или лог закончен, вовращаем null */ if(!$this->hLog or feof($this->hLog)) return null; /** * Читаем следующую строку и формируем объект Entry */ $sLine=fgets($this->hLog); if(!$sLine) return null; $aTime = array(); list( $aTime['request_date'],$aTime['request_id'],$aTime['time_full'], $aTime['time_start'],$aTime['time_stop'],$aTime['time_id'], $aTime['time_pid'],$aTime['time_name'],$aTime['time_comment'] )=explode($this->sDataDelimiter,$sLine,9); return Engine::GetEntity('Profiler_Entry',$aTime); } /** * Выгружает записи из лога в базу данных * * @param string $sDateStart * @param string $sPath * @return bool|int */ public function UploadLog($sDateStart,$sPath=null) { if($sPath) $this->hLog = @fopen($sPath,'r+'); if(!$this->hLog) return null; rewind($this->hLog); $iCount=0; while($oEntry=$this->ReadEntry()) { if(strtotime($oEntry->getDate())>strtotime($sDateStart)){ $this->AddEntry($oEntry); $iCount++; } unset($oEntry); } return $iCount; } /** * Получает дату последней записи профайлера в базе данных * * @return string */ public function GetDatabaseStat() { return $this->oMapper->GetDatabaseStat(); } /** * Очищает файл лога * * @return bool */ public function EraseLog() { } /** * Получает записи профайлера из базы данных, группированных по уровню "Report" * TODO: Реализовать кеширование данных * * @param array $aFilter * @param int $iPage * @param int $iPerPage * @return array */ public function GetReportsByFilter($aFilter,$iPage,$iPerPage) { $data=array( 'collection'=>$this->oMapper->GetReportsByFilter($aFilter,$iCount,$iPage,$iPerPage), 'count'=>$iCount ); return $data; } /** * Получает профайл-отчет по идентификатору * TODO: доработать система вывода записей в виде дерева * * @param int $sId * @return ProfileEntity_Report */ public function GetReportById($sId) { $aReportRows=$this->oMapper->GetReportById($sId); if(count($aReportRows)) { //$aEntries = $this->BuildEntriesRecursive($aReportRows); $oReport = Engine::GetEntity('Profiler_Report'); foreach ($aReportRows as $aEntry) { $oReport->addEntry(Engine::GetEntity('Profiler_Entry',$aEntry)); } return $oReport; } return null; } protected function BuildEntriesRecursive($aEntries,$bBegin=true) { static $aResultEntries; static $iLevel; if ($bBegin) { $aResultEntries=array(); $iLevel=0; } foreach ($aEntries as $aEntry) { $aTemp=$aEntry; $aTemp['level']=$iLevel; unset($aTemp['childNodes']); $aResultEntries[]=Engine::GetEntity('Profiler_Entry',$aTemp); if (isset($aEntry['childNodes']) and count($aEntry['childNodes'])>0) { $iLevel++; $this->BuildEntriesRecursive($aEntry['childNodes'],false); } } $iLevel--; return $aResultEntries; } /** * Удаление отчетов из базы данных * TODO: Добавить обработку кеша данных * * @param array|int $aIds * @return bool */ public function DeleteEntryByRequestId($aIds) { if(!is_array($aIds)) $aIds = array($aIds); return $this->oMapper->DeleteEntryByRequestId($aIds); } } ?>