From 06008ed8eb33d995f41b9add2def79038342f8d2 Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Fri, 31 Dec 2021 12:12:32 +0100 Subject: [PATCH] * Add KPI object loaded counter --- core/kpi.class.inc.php | 22 ++++++++++++++++++++ sources/application/Service/EventService.php | 6 +++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/kpi.class.inc.php b/core/kpi.class.inc.php index 446cc7aa6..5760bf89c 100644 --- a/core/kpi.class.inc.php +++ b/core/kpi.class.inc.php @@ -15,6 +15,9 @@ // // You should have received a copy of the GNU Affero General Public License // along with iTop. If not, see +use Combodo\iTop\Service\EventData; +use Combodo\iTop\Service\EventName; +use Combodo\iTop\Service\EventService; /** @@ -37,6 +40,8 @@ class ExecutionKPI * @var array[ExecutionKPI] */ static protected $m_aExecutionStack = []; // embedded execution stats + // Event listener + static protected $oKPIEventListener; protected $m_fStarted = null; protected $m_fChildrenDuration = 0; // Count embedded @@ -288,6 +293,9 @@ class ExecutionKPI public function __construct() { + if (is_null(static::$oKPIEventListener)) { + static::$oKPIEventListener = new KPIEventListener(); + } $this->ResetCounters(); self::Push($this); } @@ -450,3 +458,17 @@ class ExecutionKPI } } +class KPIEventListener +{ + public function __construct() + { + EventService::Register(EventName::DB_OBJECT_LOADED, [get_class($this), 'OnObjectLoaded']); + } + + public static function OnObjectLoaded(EventData $oEventData) + { + $oObject = $oEventData->GetEventData()['object']; + $oKPI = new ExecutionKPI(); + $oKPI->ComputeStats('Objects Loaded (no duration)', get_class($oObject)); + } +} \ No newline at end of file diff --git a/sources/application/Service/EventService.php b/sources/application/Service/EventService.php index 700bb92b3..4ef07e21a 100644 --- a/sources/application/Service/EventService.php +++ b/sources/application/Service/EventService.php @@ -58,8 +58,8 @@ class EventService }); self::$aEvents[$sEvent] = $aEventCallbacks; - if (IssueLog::CanLog(IssueLog::LEVEL_DEBUG, LOG_EVENT_SERVICE_CHANNEL)) - { +// if (IssueLog::CanLog(IssueLog::LEVEL_DEBUG, LOG_EVENT_SERVICE_CHANNEL)) +// { $iTotalRegistrations = 0; foreach (self::$aEvents as $aEvent) { @@ -67,7 +67,7 @@ class EventService } $sEventName = "$sEvent:".self::GetSourcesAsString($sEventSource); IssueLog::Trace("Registering event '$sEventName' for '$sName' with id '$sId' (total $iTotalRegistrations)", LOG_EVENT_SERVICE_CHANNEL); - } +// } return $sId; }