From 80d61c3ae69fd476872fa0d2a043a31fec383072 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 27 Jan 2025 11:23:58 +0100 Subject: [PATCH 1/2] Add Profiling to Dispatcher --- src/Dispatcher.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Dispatcher.php b/src/Dispatcher.php index 70496f9d..7d6f3d4c 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -246,6 +246,27 @@ public function addListener(string $eventName, callable $callback, int $priority $this->listeners[$eventName] = new ListenersPriorityQueue(); } + // Basic Profiling for Plugins + if (constant('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; From 3b76da761ae3a2fc7e365001ea6e705dcf7090cc Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 27 Jan 2025 14:25:36 +0100 Subject: [PATCH 2/2] Check JDEBUG without constant() Co-authored-by: Harald Leithner --- src/Dispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dispatcher.php b/src/Dispatcher.php index 7d6f3d4c..59d08805 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -247,7 +247,7 @@ public function addListener(string $eventName, callable $callback, int $priority } // Basic Profiling for Plugins - if (constant('JDEBUG')) { + if (JDEBUG) { $classObj = ''; $plgName = '';