From 81cc313a892f10fb0b07061a1bd3a0cc6904f5c0 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 19 Jan 2018 13:14:41 -0500 Subject: [PATCH] Added Memory tracking to index and controllers when Debug Verbose is on. --- config.php | 2 ++ controllers/admin.php | 31 +++++++++++++++++++++++++++---- controllers/front.php | 18 +++++++++++++++++- index.php | 17 +++++++++++++++++ 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/config.php b/config.php index 22c2502b..38d05d1f 100644 --- a/config.php +++ b/config.php @@ -38,6 +38,8 @@ if ($glmMembersDatabaseDbVersion) { define('GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE', $settings['admin_debug_verbose']); define('GLM_MEMBERS_PLUGIN_FRONT_DEBUG', $settings['front_debug']); define('GLM_MEMBERS_PLUGIN_FRONT_DEBUG_VERBOSE', $settings['front_debug_verbose']); + define('GLM_MEMBERS_PLUGIN_DEBUG', $settings['admin_debug'] || $settings['front_debug']); + define('GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE', $settings['admin_debug_verbose'] || $settings['front_debug_verbose']); } // Check for config value replacements in the current theme diff --git a/controllers/admin.php b/controllers/admin.php index 6f3ea31f..3aeb9764 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -122,7 +122,11 @@ class glmMembersAdmin extends GlmPluginSupport */ public function __construct ($wpdb, $config) { - + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + // Save WordPress Database object $this->wpdb = $wpdb; @@ -229,7 +233,11 @@ class glmMembersAdmin extends GlmPluginSupport } } - + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + } /** @@ -246,6 +254,10 @@ class glmMembersAdmin extends GlmPluginSupport public function glmMembersAdminAjax() { + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + // Get the model action if (isset($_REQUEST['glm_action']) && $_REQUEST['glm_action'] != '') { $glmAction = sanitize_text_field($_REQUEST['glm_action']); @@ -367,7 +379,11 @@ class glmMembersAdmin extends GlmPluginSupport // Generate output from model data and view $smarty->template->display($viewFile); - + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + exit; // Need to test if this is here for a reason! wp_die(); @@ -675,7 +691,10 @@ class glmMembersAdmin extends GlmPluginSupport */ public function controller( $menuItem, $action = false, $actionData = false, $returnOutput = false ) { - + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + // Enque admin scripts and css here so that only happens when we're doing something $this->glmMembersAdminScripts(); @@ -1010,6 +1029,10 @@ class glmMembersAdmin extends GlmPluginSupport // Restore timezone that was set before our code was called date_default_timezone_set($defaultTimeZone); + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + if ( $returnOutput ) { return $output; } diff --git a/controllers/front.php b/controllers/front.php index f24d84b3..97ffbd6c 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -40,6 +40,10 @@ class glmMembersFront extends GlmPluginSupport public function __construct ($wpdb, $config) { + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + // Save WordPress Database object $this->wpdb = $wpdb; @@ -97,7 +101,11 @@ class glmMembersFront extends GlmPluginSupport // Add filters for use anywhere else (apply_filter). Will have to add this to index.php eventually add_filter('glmMembersFrontScriptsFilter',array($this,'glmMembersFrontScripts')); add_action('glmMembersFrontCSSFilter',array($this,'glmMembersFrontCSS')); - + + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + } /** @@ -276,6 +284,10 @@ class glmMembersFront extends GlmPluginSupport public function controller ($atts, $content = null, $shortcode) { + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + // Start with no cache_code - This prevents caching for subordinate controller hits $cache_code = false; @@ -657,6 +669,10 @@ class glmMembersFront extends GlmPluginSupport } + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); + } + return $out; } diff --git a/index.php b/index.php index 4585dedf..75296c5b 100644 --- a/index.php +++ b/index.php @@ -22,6 +22,8 @@ * @version 2.10.20 */ +$GLOBALS['glmAssociateMemTracker'] = memory_get_usage(); + // Check that we're being called by WordPress. if (!defined('ABSPATH')) { header("Location: http://".$_SERVER['SERVER_NAME']."/error/404.html"); @@ -220,6 +222,10 @@ require_once 'defines.php'; // Get configuration require_once 'config.php'; +if (GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); +} + /* * * Hook in add-ons and integrate their actions @@ -417,6 +423,10 @@ if (function_exists('is_user_logged_in')) { $config['loggedInUser'] = apply_filters('glm_members_current_logged_in_user', $config['loggedInUser']); } +if (GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE) { + trigger_error(glmAssociateMemoryUsage(),E_USER_NOTICE); +} + /* * * Run desired controller @@ -716,3 +726,10 @@ ${GLM_MEMBERS_PLUGIN_PREFIX."updateChecker"} = new OpenToolsPluginUpdateChecker( ${GLM_MEMBERS_PLUGIN_PREFIX."updateChecker"}->declareCredentials(array( 'license_key' => __('License Key:') )); + + +function glmAssociateMemoryUsage() { + $m = memory_get_usage(); + $mu = $m - $GLOBALS['glmAssociateMemTracker']; + return 'GLM Associate Memory Usage: '.number_format($mu,0).' of '.number_format($m,0).' Bytes'; +} \ No newline at end of file -- 2.17.1