mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-05-13 06:18:18 +03:00
fix + вынос статистики производительности из index.php в отдельный шаблон
This commit is contained in:
parent
a7a09cdcfb
commit
a6317f7d9d
42
classes/hooks/HookStatisticsPerformance.class.php
Normal file
42
classes/hooks/HookStatisticsPerformance.class.php
Normal 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');
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -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);
|
||||
|
@ -395,6 +397,10 @@ class Engine extends Object {
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ставим хук на вызов неизвестного метода и считаем что хотели вызвать метод какого либо модуля
|
||||
*
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
49
index.php
49
index.php
|
@ -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>
|
||||
query: <?php echo($aStats['sql']['count']);?><br>
|
||||
time: <?php echo($aStats['sql']['time']);?><br><br><br>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Cache</b> <br>
|
||||
query: <?php echo($aStats['cache']['count']);?><br>
|
||||
set: <?echo($aStats['cache']['count_set']);?><br>
|
||||
get: <?echo($aStats['cache']['count_get']);?><br>
|
||||
time: <?php echo(round($aStats['cache']['time'],5));?>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
<td align="top">
|
||||
<ul>
|
||||
<li>
|
||||
<b>PHP</b> <br>
|
||||
time load modules:<?php echo($aStats['engine']['time_load_module']);?><br>
|
||||
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 }?>
|
39
plugins/profiler/classes/hooks/HookProfiler.class.php
Normal file
39
plugins/profiler/classes/hooks/HookProfiler.class.php
Normal 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');
|
||||
}
|
||||
}
|
||||
?>
|
4
plugins/profiler/templates/skin/default/link.tpl
Normal file
4
plugins/profiler/templates/skin/default/link.tpl
Normal 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>
|
4
plugins/profiler/templates/skin/developer/link.tpl
Normal file
4
plugins/profiler/templates/skin/developer/link.tpl
Normal 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>
|
4
plugins/profiler/templates/skin/new/link.tpl
Normal file
4
plugins/profiler/templates/skin/new/link.tpl
Normal 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>
|
|
@ -45,17 +45,14 @@
|
|||
</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}
|
||||
|
|
38
templates/skin/developer/statistics_performance.tpl
Normal file
38
templates/skin/developer/statistics_performance.tpl
Normal 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>
|
||||
query: {$aStatsPerformance.sql.count}<br>
|
||||
time: {$aStatsPerformance.sql.time}<br><br><br>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Cache</b> <br>
|
||||
query: {$aStatsPerformance.cache.count}<br>
|
||||
set: {$aStatsPerformance.cache.count_set}<br>
|
||||
get: {$aStatsPerformance.cache.count_get}<br>
|
||||
time: {$aStatsPerformance.cache.time}
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
<td align="top">
|
||||
<ul>
|
||||
<li>
|
||||
<b>PHP</b> <br>
|
||||
time load modules:{$aStatsPerformance.engine.time_load_module}<br>
|
||||
full time:{$iTimeFullPerformance}<br><br><br>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
{/if}
|
38
templates/skin/new/statistics_performance.tpl
Normal file
38
templates/skin/new/statistics_performance.tpl
Normal 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>
|
||||
query: {$aStatsPerformance.sql.count}<br>
|
||||
time: {$aStatsPerformance.sql.time}<br><br><br>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Cache</b> <br>
|
||||
query: {$aStatsPerformance.cache.count}<br>
|
||||
set: {$aStatsPerformance.cache.count_set}<br>
|
||||
get: {$aStatsPerformance.cache.count_get}<br>
|
||||
time: {$aStatsPerformance.cache.time}
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
<td align="top">
|
||||
<ul>
|
||||
<li>
|
||||
<b>PHP</b> <br>
|
||||
time load modules:{$aStatsPerformance.engine.time_load_module}<br>
|
||||
full time:{$iTimeFullPerformance}<br><br><br>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
{/if}
|
Loading…
Reference in a new issue