Browse Source

check-debug-notify-protect

David Rose 20 years ago
parent
commit
b82652aaaa

+ 4 - 2
dtool/src/interrogatedb/typeRegistry.cxx

@@ -594,8 +594,10 @@ init_global_pointer() {
 void TypeRegistry::
 void TypeRegistry::
 rebuild_derivations() {
 rebuild_derivations() {
 #ifdef NOTIFY_DEBUG
 #ifdef NOTIFY_DEBUG
-  interrogatedb_cat->debug()
-    << "Rebuilding derivation tree.\n";
+  if (interrogatedb_cat->is_debug()) {
+    interrogatedb_cat->debug()
+      << "Rebuilding derivation tree.\n";
+  }
 #endif
 #endif
 
 
   // First, remove all of the old data from the last type
   // First, remove all of the old data from the last type

+ 38 - 0
dtool/src/prc/notifyCategory.cxx

@@ -107,6 +107,23 @@ out(NotifySeverity severity, bool prefix) const {
     } else {
     } else {
       return nout;
       return nout;
     }
     }
+
+  } else if (severity <= NS_debug && get_check_debug_notify_protect()) {
+    // Someone issued a debug Notify output statement without
+    // protecting it within an if statement.  This can cause a
+    // significant runtime performance hit, since it forces the
+    // iostream library to fully format its output, and then discards
+    // the output.
+    nout << " **Not protected!** ";
+    if (prefix) {
+      nout << *this << "(" << severity << "): ";
+    }
+    if (assert_abort) {
+      nassertr(false, nout);
+    }
+
+    return nout;
+
   } else {
   } else {
     return Notify::null();
     return Notify::null();
   }
   }
@@ -186,3 +203,24 @@ get_notify_timestamp() {
   }
   }
   return *notify_timestamp;
   return *notify_timestamp;
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: NotifyCategory::get_check_debug_notify_protect
+//       Access: Private, Static
+//  Description: Returns the value of the check-debug-notify-protect
+//               ConfigVariable.  This is defined using a method
+//               accessor rather than a static ConfigVariableBool, to
+//               protect against the variable needing to be accessed
+//               at static init time.
+////////////////////////////////////////////////////////////////////
+bool NotifyCategory::
+get_check_debug_notify_protect() {
+  static ConfigVariableBool *check_debug_notify_protect = NULL;
+  if (check_debug_notify_protect == (ConfigVariableBool *)NULL) {
+    check_debug_notify_protect = new ConfigVariableBool
+      ("check-debug-notify-protect", false,
+       "Set true to issue a warning message if a debug or spam "
+       "notify output is not protected within an if statement.");
+  }
+  return *check_debug_notify_protect;
+}

+ 1 - 0
dtool/src/prc/notifyCategory.h

@@ -81,6 +81,7 @@ PUBLISHED:
 private:
 private:
   string get_config_name() const;
   string get_config_name() const;
   static bool get_notify_timestamp();
   static bool get_notify_timestamp();
+  static bool get_check_debug_notify_protect();
 
 
   string _fullname;
   string _fullname;
   string _basename;
   string _basename;