N°6436 - Integrate Performance Audit pre requisite (log events for extensions)

This commit is contained in:
Eric Espie
2023-11-13 15:02:54 +01:00
parent 5465287089
commit b758113752
3 changed files with 30 additions and 8 deletions

View File

@@ -6285,7 +6285,9 @@ abstract class DBObject implements iDisplay
}
}
finally {
$oKPI->ComputeStats('FireEvent', $sEvent);
if (!$oKPI->ComputeStatsForExtension($this, $sCallback, "Event: $sEvent")) {
$oKPI->ComputeStats('FireEvent', $sEvent);
}
}
}
if (!is_null($oFirstException)) {

View File

@@ -3,6 +3,7 @@
* @copyright Copyright (C) 2010-2023 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Core\Kpi\KpiLogData;
use Combodo\iTop\Service\Module\ModuleService;
@@ -404,16 +405,31 @@ class ExecutionKPI
$this->ResetCounters();
}
public function ComputeStatsForExtension($object, $sMethod)
/**
* Compute statistics for a call to an extension
* Note: not working in dev mode (with links to env-production)
*
* @param object|string $object object called
* @param string $sMethod method called on the object
* @param string $sMessage additional message
*
* @return bool true if an extension was found for this object::method
* @throws \ReflectionException
*/
public function ComputeStatsForExtension($object, string $sMethod, string $sMessage = ''): bool
{
if (!self::IsEnabled()) {
return;
return true;
}
$sSignature = ModuleService::GetInstance()->GetModuleMethodSignature($object, $sMethod);
if (utils::StartsWith($sSignature, '[')) {
$this->ComputeStats('Extension', $sSignature);
$this->ComputeStats('Extension', "$sSignature $sMessage");
return true;
}
return false;
}
public function ComputeStats($sOperation, $sArguments)

View File

@@ -8,6 +8,7 @@ namespace Combodo\iTop\Service\Events;
use Closure;
use Combodo\iTop\Service\Events\Description\EventDescription;
use Combodo\iTop\Service\Module\ModuleService;
use ContextTag;
use CoreException;
use DBObject;
@@ -136,12 +137,9 @@ final class EventService
throw new CoreException($sError);
}
$eventSource = $oEventData->GetEventSource();
$oKPI = new ExecutionKPI();
$sLogEventName = "$sEvent - ".self::GetSourcesAsString($eventSource).' '.json_encode($oEventData->GetEventData());
EventServiceLog::Trace("Fire event '$sLogEventName'");
if (!isset(self::$aEventListeners[$sEvent])) {
$oKPI->ComputeStats('FireEvent', $sEvent);
return;
}
@@ -157,7 +155,14 @@ final class EventService
$bEventFired = true;
try {
$oEventData->SetCallbackData($aEventCallback['data']);
$oKPI = new ExecutionKPI();
call_user_func($aEventCallback['callback'], $oEventData);
if (isset($aEventCallback['callback'][1]) && !$oKPI->ComputeStatsForExtension($aEventCallback['callback'][0], $aEventCallback['callback'][1], "Event: $sEvent")) {
$sSignature = ModuleService::GetInstance()->GetModuleMethodSignature($aEventCallback['callback'][0], $aEventCallback['callback'][1]);
$oKPI->ComputeStats('FireEvent', "$sEvent callback: $sSignature");
}
}
catch (EventException $e) {
EventServiceLog::Error("Event '$sLogEventName' for '$sName' id {$aEventCallback['id']} failed with blocking error: ".$e->getMessage());
@@ -172,7 +177,6 @@ final class EventService
if ($bEventFired) {
EventServiceLog::Debug("End of event '$sLogEventName'");
}
$oKPI->ComputeStats('FireEvent', $sEvent);
if (!is_null($oLastException)) {
EventServiceLog::Error("Throwing the last exception caught: $sLastExceptionMessage");