N°6436 - Performance Audit (KPI analysis)

This commit is contained in:
Eric Espie
2023-07-20 12:05:13 +02:00
parent 8b93a404ef
commit a59dacf679

View File

@@ -8,6 +8,7 @@ namespace Combodo\iTop\Service\Events;
use Closure; use Closure;
use Combodo\iTop\Service\Events\Description\EventDescription; use Combodo\iTop\Service\Events\Description\EventDescription;
use Combodo\iTop\Service\Module\ModuleService;
use ContextTag; use ContextTag;
use CoreException; use CoreException;
use Exception; use Exception;
@@ -70,6 +71,10 @@ final class EventService
return false; return false;
} }
if (utils::IsNullOrEmptyString($sModuleId)) {
$sModuleId = ModuleService::GetInstance()->GetModuleNameFromCallStack();
}
$aEventCallbacks = self::$aEventListeners[$sEvent] ?? []; $aEventCallbacks = self::$aEventListeners[$sEvent] ?? [];
$sId = 'event_'.self::$iEventIdCounter++; $sId = 'event_'.self::$iEventIdCounter++;
$aEventCallbacks[] = array( $aEventCallbacks[] = array(
@@ -125,11 +130,9 @@ final class EventService
throw new CoreException($sError); throw new CoreException($sError);
} }
$eventSource = $oEventData->GetEventSource(); $eventSource = $oEventData->GetEventSource();
$oKPI = new ExecutionKPI();
$sLogEventName = "$sEvent - ".self::GetSourcesAsString($eventSource).' '.json_encode($oEventData->GetEventData()); $sLogEventName = "$sEvent - ".self::GetSourcesAsString($eventSource).' '.json_encode($oEventData->GetEventData());
EventServiceLog::Trace("Fire event '$sLogEventName'"); EventServiceLog::Trace("Fire event '$sLogEventName'");
if (!isset(self::$aEventListeners[$sEvent])) { if (!isset(self::$aEventListeners[$sEvent])) {
$oKPI->ComputeStats('FireEvent', $sEvent);
return; return;
} }
@@ -146,7 +149,14 @@ final class EventService
$bEventFired = true; $bEventFired = true;
try { try {
$oEventData->SetCallbackData($aEventCallback['data']); $oEventData->SetCallbackData($aEventCallback['data']);
$oKPI = new ExecutionKPI();
call_user_func($aEventCallback['callback'], $oEventData); call_user_func($aEventCallback['callback'], $oEventData);
$sArguments = "Event: $sEvent";
if (utils::IsNotNullOrEmptyString($aEventCallback['module'])) {
$sArguments .= ' ['.$aEventCallback['module'].']';
}
$sArguments .= ' '.$aEventCallback['name'].'()';
$oKPI->ComputeStats('Extension', $sArguments);
} }
catch (EventException $e) { catch (EventException $e) {
EventServiceLog::Error("Event '$sLogEventName' for '$sName' id {$aEventCallback['id']} failed with blocking error: ".$e->getMessage()); EventServiceLog::Error("Event '$sLogEventName' for '$sName' id {$aEventCallback['id']} failed with blocking error: ".$e->getMessage());
@@ -161,7 +171,6 @@ final class EventService
if ($bEventFired) { if ($bEventFired) {
EventServiceLog::Debug("End of event '$sLogEventName'"); EventServiceLog::Debug("End of event '$sLogEventName'");
} }
$oKPI->ComputeStats('FireEvent', $sEvent);
if (!is_null($oLastException)) { if (!is_null($oLastException)) {
EventServiceLog::Error("Throwing the last exception caught: $sLastExceptionMessage"); EventServiceLog::Error("Throwing the last exception caught: $sLastExceptionMessage");