Alex Trofimov 11 лет назад
Родитель
Сommit
09da7f5307
2 измененных файлов с 55 добавлено и 2 удалено
  1. 6 2
      inc/classes/BxDolAlerts.php
  2. 49 0
      modules/boonex/profiler/classes/BxProfiler.php

+ 6 - 2
inc/classes/BxDolAlerts.php

@@ -109,6 +109,8 @@ class BxDolAlerts extends BxDol
             foreach($this->_aAlerts[$this->sUnit][$this->sAction] as $iHandlerId) {
                 $aHandler = $this->_aHandlers[$iHandlerId];
 
+                if (isset($GLOBALS['bx_profiler']) && 'bx_profiler' != $aHandler['name']) $GLOBALS['bx_profiler']->beginAlert($this->sUnit, $this->sAction, $aHandler['name']);
+
                 if (!empty($aHandler['file']) && !empty($aHandler['class']) && file_exists(BX_DIRECTORY_PATH_ROOT . $aHandler['file'])) {
                     if(!class_exists($aHandler['class'], false))
                         require_once(BX_DIRECTORY_PATH_ROOT . $aHandler['file']);
@@ -124,6 +126,8 @@ class BxDolAlerts extends BxDol
 
                     BxDolService::call($aService['module'], $aService['method'], $aParams, isset($aService['class']) ? $aService['class'] : 'Module');
                 }
+
+                if (isset($GLOBALS['bx_profiler']) && 'bx_profiler' != $aHandler['name']) $GLOBALS['bx_profiler']->endAlert($this->sUnit, $this->sAction, $aHandler['name']);
             }
     }
 
@@ -141,9 +145,9 @@ class BxDolAlerts extends BxDol
         foreach ($aAlerts as $aAlert)
             $aResult['alerts'][$aAlert['unit']][$aAlert['action']][] = $aAlert['handler_id'];
 
-        $aHandlers = $oDb->getAll("SELECT `id`, `class`, `file`, `service_call` FROM `sys_alerts_handlers` ORDER BY `id` ASC");
+        $aHandlers = $oDb->getAll("SELECT `id`, `class`, `file`, `service_call`, `name` FROM `sys_alerts_handlers` ORDER BY `id` ASC");
         foreach ($aHandlers as $aHandler)
-            $aResult['handlers'][$aHandler['id']] = array('class' => $aHandler['class'], 'file' => $aHandler['file'], 'service_call' => $aHandler['service_call']);
+            $aResult['handlers'][$aHandler['id']] = array('class' => $aHandler['class'], 'file' => $aHandler['file'], 'service_call' => $aHandler['service_call'], 'name' => $aHandler['name']);
 
         return $aResult;
     }

+ 49 - 0
modules/boonex/profiler/classes/BxProfiler.php

@@ -40,6 +40,9 @@ class BxProfiler extends BxDol
     protected $_aModulesNames = array();
     protected $_aModulesLevel = 0;
 
+    protected $_aAlerts = array();
+    protected $_iAlertsLevel = 0;
+
     protected $_aInjections = array();
     protected $_sInjectionIndex = 0;
 
@@ -112,6 +115,7 @@ class BxProfiler extends BxDol
             echo $this->_plankPagesBlocks ();
             echo $this->_plankSql ();
             echo $this->_plankModules ();
+            echo $this->_plankAlerts ();
         }
     }
 
@@ -201,6 +205,30 @@ class BxProfiler extends BxDol
             $this->logModuleQuery ($iTime, $this->_aModules[$sHash]);
     }
 
+    function beginAlert($sUnit, $sAction, $sHandler)
+    {
+        $sHash = md5($sUnit . $sAction . $sHandler);
+        ++$this->_iAlertsLevel;
+        $this->_aAlerts[$sHash] = array (
+            'name' => str_repeat("--", $this->_iAlertsLevel-1) . $sHandler,
+            'unit' => $sUnit,
+            'action' => $sAction,
+            'handler' => $sHandler,
+            'begin' => microtime (),
+            'time' => -1,
+        );
+    }
+
+    function endAlert($sUnit, $sAction, $sHandler)
+    {
+        $sHash = md5($sUnit . $sAction . $sHandler);
+        --$this->_iAlertsLevel;
+        $iTime = $this->_calcTime ($this->_aAlerts[$sHash]['begin']);
+        unset ($this->_aAlerts[$sHash]['begin']);
+        $this->_aAlerts[$sHash]['time'] = $this->_formatTime($iTime, 5);
+        $this->_aAlerts[$sHash]['raw_time'] = $iTime;
+    }
+
     function beginInjection ($sId)
     {
         $this->_sInjectionIndex = $sId;
@@ -526,6 +554,27 @@ class BxProfiler extends BxDol
         );
     }
 
+    function _plankAlerts ()
+    {
+        if (empty($GLOBALS['bx_profiler']->_aAlerts))
+            return;
+
+        $iTimeAlerts = 0;
+        foreach ($GLOBALS['bx_profiler']->_aAlerts as $k => $r) {
+            if (!isset($r['raw_time']))
+                continue;
+            $iTimeAlerts += $r['raw_time'];
+            unset ($GLOBALS['bx_profiler']->_aAlerts[$k]['raw_time']);
+        }
+
+        $sAlerts = count($GLOBALS['bx_profiler']->_aAlerts) . ' alerts responses (' . $this->_formatTime($iTimeAlerts, 3) . ')';
+
+        return $this->oTemplate->plank(
+            $this->oTemplate->nameValue('Alerts:', $sAlerts) .
+            $this->oTemplate->table($GLOBALS['bx_profiler']->_aAlerts)
+        );
+    }
+
     function _formatTime ($i, $iPrecision = 3)
     {
         return round($i, $iPrecision) . ' sec';