Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,27 @@ public function addListener(string $eventName, callable $callback, int $priority
$this->listeners[$eventName] = new ListenersPriorityQueue();
}

// Basic Profiling for Plugins
if (JDEBUG) {
$classObj = '';
$plgName = '';

// Try getting the reference to the Class
$classObj = debug_backtrace()[1]['object'];

if ($classObj) {
// If we have found a reference get the Name
$plgName = get_class($classObj);
}

// Wrapping the Callback to get the time it executed
$callback = function (...$args) use($callback, $plgName, $eventName) {
\Joomla\CMS\Profiler\Profiler::getInstance('Application')->mark('beforeExecutePlugin ' . $plgName.'::'.$eventName);
$callback(...$args);
\Joomla\CMS\Profiler\Profiler::getInstance('Application')->mark('afterExecutePlugin ' . $plgName.'::'.$eventName);
};
}

$this->listeners[$eventName]->add($callback, $priority);

return true;
Expand Down