From b82652aaaa25dbb298c40d6ce45d7484fa6b5137 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 20 Mar 2006 21:39:20 +0000 Subject: [PATCH] check-debug-notify-protect --- dtool/src/interrogatedb/typeRegistry.cxx | 6 ++-- dtool/src/prc/notifyCategory.cxx | 38 ++++++++++++++++++++++++ dtool/src/prc/notifyCategory.h | 1 + 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/dtool/src/interrogatedb/typeRegistry.cxx b/dtool/src/interrogatedb/typeRegistry.cxx index 306cc291ea..8922fda490 100644 --- a/dtool/src/interrogatedb/typeRegistry.cxx +++ b/dtool/src/interrogatedb/typeRegistry.cxx @@ -594,8 +594,10 @@ init_global_pointer() { void TypeRegistry:: rebuild_derivations() { #ifdef NOTIFY_DEBUG - interrogatedb_cat->debug() - << "Rebuilding derivation tree.\n"; + if (interrogatedb_cat->is_debug()) { + interrogatedb_cat->debug() + << "Rebuilding derivation tree.\n"; + } #endif // First, remove all of the old data from the last type diff --git a/dtool/src/prc/notifyCategory.cxx b/dtool/src/prc/notifyCategory.cxx index 535079d2d5..0b390d729a 100644 --- a/dtool/src/prc/notifyCategory.cxx +++ b/dtool/src/prc/notifyCategory.cxx @@ -107,6 +107,23 @@ out(NotifySeverity severity, bool prefix) const { } else { 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 { return Notify::null(); } @@ -186,3 +203,24 @@ get_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; +} diff --git a/dtool/src/prc/notifyCategory.h b/dtool/src/prc/notifyCategory.h index 6ec5cba860..3fca4813df 100644 --- a/dtool/src/prc/notifyCategory.h +++ b/dtool/src/prc/notifyCategory.h @@ -81,6 +81,7 @@ PUBLISHED: private: string get_config_name() const; static bool get_notify_timestamp(); + static bool get_check_debug_notify_protect(); string _fullname; string _basename;