Added Memory tracking to index and controllers when Debug Verbose is on.
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 19 Jan 2018 18:14:41 +0000 (13:14 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 19 Jan 2018 18:14:41 +0000 (13:14 -0500)
config.php
controllers/admin.php
controllers/front.php
index.php

index 22c2502..38d05d1 100644 (file)
@@ -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
index 6f3ea31..3aeb976 100644 (file)
@@ -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;
         }
index f24d84b..97ffbd6 100644 (file)
@@ -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;
 
     }
index 4585ded..75296c5 100644 (file)
--- 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