1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-04-28 06:59:25 +03:00

fix + вынос статистики производительности из index.php в отдельный шаблон

This commit is contained in:
Mzhelskiy Maxim 2010-06-05 12:24:37 +00:00
parent a7a09cdcfb
commit a6317f7d9d
11 changed files with 187 additions and 58 deletions

View file

@ -0,0 +1,42 @@
<?php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Регистрация хука для вывода статистики производительности
*
*/
class HookStatisticsPerformance extends Hook {
public function RegisterHook() {
$this->AddHook('template_body_end','Statistics',__CLASS__,-1000);
}
public function Statistics() {
$oEngine=Engine::getInstance();
$iTimeInit=$oEngine->GetTimeInit();
$iTimeFull=round(microtime(true)-$iTimeInit,3);
$this->Viewer_Assign('iTimeFullPerformance',$iTimeFull);
$aStats=$oEngine->getStats();
$aStats['cache']['time']=round($aStats['cache']['time'],5);
$this->Viewer_Assign('aStatsPerformance',$aStats);
$this->Viewer_Assign('bIsShowStatsPerformance',Router::GetIsShowStats());
return $this->Viewer_Fetch(Plugin::GetTemplatePath(__CLASS__).'statistics_performance.tpl');
}
}
?>

View file

@ -40,6 +40,7 @@ class Engine extends Object {
protected $aPlugins=array();
protected $aConfigModule;
public $iTimeLoadModule=0;
protected $iTimeInit=null;
/**
* Массив содержит меппер кастомизации сущностей
@ -53,6 +54,7 @@ class Engine extends Object {
*
*/
protected function __construct() {
$this->iTimeInit=microtime(true);
if (get_magic_quotes_gpc()) {
func_stripslashes($_REQUEST);
func_stripslashes($_GET);
@ -394,6 +396,10 @@ class Engine extends Object {
public function getStats() {
return array('sql'=>$this->Database_GetStats(),'cache'=>$this->Cache_GetStats(),'engine'=>array('time_load_module'=>round($this->iTimeLoadModule,3)));
}
public function GetTimeInit() {
return $this->iTimeInit;
}
/**
* Ставим хук на вызов неизвестного метода и считаем что хотели вызвать метод какого либо модуля

View file

@ -25,11 +25,17 @@ abstract class Hook extends Object {
}
protected function AddHook($sName,$sCallBack,$sClassNameHook,$iPriority=1) {
protected function AddHook($sName,$sCallBack,$sClassNameHook=null,$iPriority=1) {
if (is_null($sClassNameHook)) {
$sClassNameHook=get_class($this);
}
$this->Hook_AddExecHook($sName,$sCallBack,$iPriority,array('sClassName'=>$sClassNameHook));
}
protected function AddDelegateHook($sName,$sCallBack,$sClassNameHook,$iPriority=1) {
protected function AddDelegateHook($sName,$sCallBack,$sClassNameHook=null,$iPriority=1) {
if (is_null($sClassNameHook)) {
$sClassNameHook=get_class($this);
}
$this->Hook_AddDelegateHook($sName,$sCallBack,$iPriority,array('sClassName'=>$sClassNameHook));
}

View file

@ -20,8 +20,6 @@ define('LS_VERSION','0.4.1');
define('SYS_HACKER_CONSOLE',false);
header('Content-Type: text/html; charset=utf-8');
$t1=microtime(true);
set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__));
chdir(dirname(__FILE__));
@ -35,52 +33,5 @@ $iTimeId=$oProfiler->Start('full_time');
$oRouter=Router::getInstance();
$oRouter->Exec();
$oEngine=Engine::getInstance();
$aStats=$oEngine->getStats();
$t2=microtime(true);
$oProfiler->Stop($iTimeId);
?>
<?php
$oUser=$oRouter->User_GetUserCurrent();
if (Router::GetIsShowStats() and $oUser and $oUser->isAdministrator()) {
?>
<fieldset>
<legend>Statistics performance</legend>
<table>
<tr align="top">
<td align="top">
<ul>
<li>
<b>MySql</b> <br>
&nbsp;&nbsp;&nbsp;query: <?php echo($aStats['sql']['count']);?><br>
&nbsp;&nbsp;&nbsp;time: <?php echo($aStats['sql']['time']);?><br><br><br>
</li>
</ul>
</td>
<td>
<ul>
<li>
<b>Cache</b> <br>
&nbsp;&nbsp;&nbsp;query: <?php echo($aStats['cache']['count']);?><br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set: <?echo($aStats['cache']['count_set']);?><br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get: <?echo($aStats['cache']['count_get']);?><br>
&nbsp;&nbsp;&nbsp;time: <?php echo(round($aStats['cache']['time'],5));?>
</li>
</ul>
</td>
<td align="top">
<ul>
<li>
<b>PHP</b> <br>
&nbsp;&nbsp;&nbsp;time load modules:<?php echo($aStats['engine']['time_load_module']);?><br>
&nbsp;&nbsp;&nbsp;full time:<?php echo(round($t2-$t1,3));?><br><br><br>
</li>
</ul>
</td>
</tr>
</table>
</fieldset>
<p align="center">Profiler: <?php print (Config::Get('sys.logs.profiler')) ? 'On' : 'Off'; ?> | <a href="<?php echo Router::GetPath('profiler');?>">Profiler reports</a></p>
<?php }?>
?>

View file

@ -0,0 +1,39 @@
<?php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Регистрация хуков
*
*/
class PluginProfiler_HookProfiler extends Hook {
public function RegisterHook() {
/**
* Хук для вставки HTML кода
*/
$this->AddHook('template_body_end', 'Profiler');
}
/**
* Выводим HTML
*
*/
public function Profiler() {
return $this->Viewer_Fetch(Plugin::GetTemplatePath(__CLASS__).'link.tpl');
}
}
?>

View file

@ -0,0 +1,4 @@
<p align="center">
Profiler: {if $oConfig->GetValue('sys.logs.profiler')}On{else}Off{/if} |
<a href="{router page='profiler'}">Profiler reports</a>
</p>

View file

@ -0,0 +1,4 @@
<p align="center">
Profiler: {if $oConfig->GetValue('sys.logs.profiler')}On{else}Off{/if} |
<a href="{router page='profiler'}">Profiler reports</a>
</p>

View file

@ -0,0 +1,4 @@
<p align="center">
Profiler: {if $oConfig->GetValue('sys.logs.profiler')}On{else}Off{/if} |
<a href="{router page='profiler'}">Profiler reports</a>
</p>

View file

@ -44,18 +44,15 @@
{/if}
</div>
{* Логотип *}
<h1><a href="{cfg name='path.root.web'}">LiveStreet</a></h1>
{* Список страниц *}
<ul class="pages">
<li {if $sMenuHeadItemSelect=='blog'}class="active"{/if}><a href="{router page='blog'}">{$aLang.clean_posts}</a></li>
<li {if $sMenuHeadItemSelect=='blogs'}class="active"{/if}><a href="{router page='blogs'}">{$aLang.blogs}</a></li>
<li {if $sMenuHeadItemSelect=='people'}class="active"{/if}><a href="{router page='people'}">{$aLang.people}</a></li>
{* Список страниц плагина "Page" *}
{if $aPluginActive.page}
<li {if $sAction=='page' and $sEvent=='about'}class="active"{/if}><a href="{router page='page'}about/">{$aLang.page_about}</a></li>
{/if}

View file

@ -0,0 +1,38 @@
{if $bIsShowStatsPerformance and $oUserCurrent and $oUserCurrent->isAdministrator()}
<fieldset>
<legend>Statistics performance</legend>
<table>
<tr align="top">
<td align="top">
<ul>
<li>
<b>MySql</b> <br>
&nbsp;&nbsp;&nbsp;query: {$aStatsPerformance.sql.count}<br>
&nbsp;&nbsp;&nbsp;time: {$aStatsPerformance.sql.time}<br><br><br>
</li>
</ul>
</td>
<td>
<ul>
<li>
<b>Cache</b> <br>
&nbsp;&nbsp;&nbsp;query: {$aStatsPerformance.cache.count}<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set: {$aStatsPerformance.cache.count_set}<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get: {$aStatsPerformance.cache.count_get}<br>
&nbsp;&nbsp;&nbsp;time: {$aStatsPerformance.cache.time}
</li>
</ul>
</td>
<td align="top">
<ul>
<li>
<b>PHP</b> <br>
&nbsp;&nbsp;&nbsp;time load modules:{$aStatsPerformance.engine.time_load_module}<br>
&nbsp;&nbsp;&nbsp;full time:{$iTimeFullPerformance}<br><br><br>
</li>
</ul>
</td>
</tr>
</table>
</fieldset>
{/if}

View file

@ -0,0 +1,38 @@
{if $bIsShowStatsPerformance and $oUserCurrent and $oUserCurrent->isAdministrator()}
<fieldset>
<legend>Statistics performance</legend>
<table>
<tr align="top">
<td align="top">
<ul>
<li>
<b>MySql</b> <br>
&nbsp;&nbsp;&nbsp;query: {$aStatsPerformance.sql.count}<br>
&nbsp;&nbsp;&nbsp;time: {$aStatsPerformance.sql.time}<br><br><br>
</li>
</ul>
</td>
<td>
<ul>
<li>
<b>Cache</b> <br>
&nbsp;&nbsp;&nbsp;query: {$aStatsPerformance.cache.count}<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set: {$aStatsPerformance.cache.count_set}<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get: {$aStatsPerformance.cache.count_get}<br>
&nbsp;&nbsp;&nbsp;time: {$aStatsPerformance.cache.time}
</li>
</ul>
</td>
<td align="top">
<ul>
<li>
<b>PHP</b> <br>
&nbsp;&nbsp;&nbsp;time load modules:{$aStatsPerformance.engine.time_load_module}<br>
&nbsp;&nbsp;&nbsp;full time:{$iTimeFullPerformance}<br><br><br>
</li>
</ul>
</td>
</tr>
</table>
</fieldset>
{/if}