From 23190bd2f599c3b3a95b6c201059ce7d782d1af2 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 20 Aug 2025 00:34:57 +0900 Subject: [PATCH] Remove all use of global variables as debug timers --- classes/display/HTMLDisplayHandler.php | 4 ++-- common/framework/Debug.php | 19 ++++++++++++------- common/framework/Template.php | 8 +------- common/tpl/debug_comment.html | 5 ++--- modules/widget/widget.controller.php | 5 ----- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/classes/display/HTMLDisplayHandler.php b/classes/display/HTMLDisplayHandler.php index c0cc31069..4f9a09bce 100644 --- a/classes/display/HTMLDisplayHandler.php +++ b/classes/display/HTMLDisplayHandler.php @@ -183,7 +183,7 @@ class HTMLDisplayHandler $pathInfo = pathinfo($layout_file); $onlyLayoutFile = $pathInfo['filename']; - $GLOBALS['__layout_compile_elapsed__'] = microtime(true) - $start; + Rhymix\Framework\Debug::addTime('layout', microtime(true) - $start); } } @@ -297,7 +297,7 @@ class HTMLDisplayHandler $output = preg_replace_callback('@]*\sname="' . $keys . '".+@isU', array(&$this, '_preserveTextAreaValue'), $output); } - $GLOBALS['__trans_content_elapsed__'] = microtime(true) - $start; + Rhymix\Framework\Debug::addTime('trans_content', microtime(true) - $start); // Remove unnecessary information $output = preg_replace('/member\_\-([0-9]+)/s', 'member_0', $output); diff --git a/common/framework/Debug.php b/common/framework/Debug.php index 556ca5b49..d3266b9e8 100644 --- a/common/framework/Debug.php +++ b/common/framework/Debug.php @@ -28,9 +28,13 @@ class Debug * Store timers here. */ protected static $_timers = [ + 'query' => 0, 'session' => 0, 'remote' => 0, - 'query' => 0, + 'layout' => 0, + 'widget' => 0, + 'template' => 0, + 'trans_content' => 0, ]; /** @@ -577,6 +581,8 @@ class Debug ); self::$_widgets[] = $widget_object; + self::$_timers['widget'] += $widget_object->widget_time; + if ($widget_object->widget_time && $widget_object->widget_time >= (self::$_config['log_slow_widgets'] ?? 1)) { self::$_slow_widgets[] = $widget_object; @@ -904,13 +910,12 @@ class Debug 'total' => sprintf('%0.4f sec', microtime(true) - \RX_MICROTIME), 'db_query' => sprintf('%0.4f sec (count: %d)', self::$_timers['query'], count(self::$_queries)), 'db_class' => sprintf('%0.4f sec', max(0, $db->getTotalElapsedTime() - self::$_timers['query'])), - 'layout' => sprintf('%0.4f sec', $GLOBALS['__layout_compile_elapsed__'] ?? 0), - 'widget' => sprintf('%0.4f sec', $GLOBALS['__widget_excute_elapsed__'] ?? 0), - 'remote' => sprintf('%0.4f sec', self::$_timers['remote']), 'session' => sprintf('%0.4f sec', self::$_timers['session']), - 'xmlparse' => sprintf('%0.4f sec', $GLOBALS['__xmlparse_elapsed__'] ?? 0), - 'template' => sprintf('%0.4f sec (count: %d)', $GLOBALS['__template_elapsed__'] ?? 0, $GLOBALS['__TemplateHandlerCalled__'] ?? 0), - 'trans' => sprintf('%0.4f sec', $GLOBALS['__trans_content_elapsed__'] ?? 0), + 'remote' => sprintf('%0.4f sec', self::$_timers['remote']), + 'layout' => sprintf('%0.4f sec', self::$_timers['layout']), + 'widget' => sprintf('%0.4f sec', self::$_timers['widget']), + 'template' => sprintf('%0.4f sec', self::$_timers['template']), + 'trans' => sprintf('%0.4f sec', self::$_timers['trans_content']), ), 'entries' => array_values(self::$_entries), 'errors' => array_values(self::$_errors), diff --git a/common/framework/Template.php b/common/framework/Template.php index 105da4fa6..d7b164f2a 100644 --- a/common/framework/Template.php +++ b/common/framework/Template.php @@ -378,13 +378,7 @@ class Template $output = $this->execute(); // Record the time elapsed. - $elapsed_time = microtime(true) - $start; - if (!isset($GLOBALS['__template_elapsed__'])) - { - $GLOBALS['__template_elapsed__'] = 0; - } - $GLOBALS['__template_elapsed__'] += $elapsed_time; - + Debug::addTime('template', microtime(true) - $start); return $output; } diff --git a/common/tpl/debug_comment.html b/common/tpl/debug_comment.html index b07a39ff3..e585366d1 100644 --- a/common/tpl/debug_comment.html +++ b/common/tpl/debug_comment.html @@ -17,11 +17,10 @@ Page Generation Time Total Time: timing->total . "\n"; ?> DB Query Time: timing->db_query . "\n"; ?> DB Processing Time: timing->db_class . "\n"; ?> +Session Lock Wait Time: timing->session . "\n"; ?> +Remote Request Time: timing->remote . "\n"; ?> Layout Processing Time: timing->layout . "\n"; ?> Widget Processing Time: timing->widget . "\n"; ?> -Remote Request Time: timing->remote . "\n"; ?> -Session Lock Wait Time: timing->session . "\n"; ?> -XML Parsing Time: timing->xmlparse . "\n"; ?> Template Compile Time: timing->template . "\n"; ?> Content Transform Time: timing->trans . "\n"; ?> diff --git a/modules/widget/widget.controller.php b/modules/widget/widget.controller.php index 62c19b046..c6044fb53 100644 --- a/modules/widget/widget.controller.php +++ b/modules/widget/widget.controller.php @@ -730,11 +730,6 @@ class WidgetController extends Widget // Debug widget creation time information added to the results $elapsed_time = microtime(true) - $start; - if (!isset($GLOBALS['__widget_excute_elapsed__'])) - { - $GLOBALS['__widget_excute_elapsed__'] = 0; - } - $GLOBALS['__widget_excute_elapsed__'] += $elapsed_time; if (Rhymix\Framework\Debug::isEnabledForCurrentUser()) { Rhymix\Framework\Debug::addWidget(array(