diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-16 21:14:08 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-16 21:14:08 +0000 |
commit | 5a236f79082386a5c9edb6da07d02b3fd1d3cd25 (patch) | |
tree | 0a00575ae0a0767868c7c6123209870a84f4424b /base | |
parent | 690a7dcc59e1867280f18b5f428e005e2f5c95a0 (diff) | |
download | chromium_src-5a236f79082386a5c9edb6da07d02b3fd1d3cd25.zip chromium_src-5a236f79082386a5c9edb6da07d02b3fd1d3cd25.tar.gz chromium_src-5a236f79082386a5c9edb6da07d02b3fd1d3cd25.tar.bz2 |
Make LeakTracker be enabled using ENABLE_LEAK_TRACKER, rather than NDEBUG.
This way it is easy to toggle it on in release builds.
Review URL: http://codereview.chromium.org/196130
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26389 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/leak_tracker.h | 21 | ||||
-rw-r--r-- | base/leak_tracker_unittest.cc | 15 |
2 files changed, 20 insertions, 16 deletions
diff --git a/base/leak_tracker.h b/base/leak_tracker.h index d289691e..a5d105a 100644 --- a/base/leak_tracker.h +++ b/base/leak_tracker.h @@ -5,13 +5,18 @@ #ifndef BASE_LEAK_TRACKER_H_ #define BASE_LEAK_TRACKER_H_ +// Only enable leak tracking in debug builds. #ifndef NDEBUG +#define ENABLE_LEAK_TRACKER +#endif + +#ifdef ENABLE_LEAK_TRACKER #include "base/debug_util.h" #include "base/linked_list.h" #include "base/logging.h" -#endif +#endif // ENABLE_LEAK_TRACKER -// LeakTracker is a debug helper to verify that all instances of a class +// LeakTracker is a helper to verify that all instances of a class // have been destroyed. // // It is particularly useful for classes that are bound to a single thread -- @@ -36,13 +41,13 @@ // then the allocation callstack for each leaked instances is dumped to // the error log. // -// In RELEASE mode the check has no effect. +// If ENABLE_LEAK_TRACKER is not defined, then the check has no effect. namespace base { -#ifdef NDEBUG +#ifndef ENABLE_LEAK_TRACKER -// In release mode we do nothing. +// If leak tracking is disabled, do nothing. template<typename T> class LeakTracker { public: @@ -52,7 +57,7 @@ class LeakTracker { #else -// In debug mode we track where the object was allocated from. +// If leak tracking is enabled we track where the object was allocated from. template<typename T> class LeakTracker : public LinkNode<LeakTracker<T> > { @@ -75,7 +80,7 @@ class LeakTracker : public LinkNode<LeakTracker<T> > { LOG(ERROR) << "Leaked " << node << " which was allocated by:"; node->value()->allocation_stack_.PrintBacktrace(); } - DCHECK_EQ(0, count); + CHECK(0 == count); } static int NumLiveInstances() { @@ -99,7 +104,7 @@ class LeakTracker : public LinkNode<LeakTracker<T> > { StackTrace allocation_stack_; }; -#endif // NDEBUG +#endif // ENABLE_LEAK_TRACKER } // namespace base diff --git a/base/leak_tracker_unittest.cc b/base/leak_tracker_unittest.cc index 8f0e2f2..0217b17 100644 --- a/base/leak_tracker_unittest.cc +++ b/base/leak_tracker_unittest.cc @@ -18,10 +18,10 @@ class ClassB { base::LeakTracker<ClassB> leak_tracker_; }; -#ifdef NDEBUG +#ifndef ENABLE_LEAK_TRACKER -// In RELEASE mode, leak tracking is disabled. -TEST(LeakTrackerTest, ReleaseMode) { +// If leak tracking is disabled, we should do nothing. +TEST(LeakTrackerTest, NotEnabled) { EXPECT_EQ(-1, base::LeakTracker<ClassA>::NumLiveInstances()); EXPECT_EQ(-1, base::LeakTracker<ClassB>::NumLiveInstances()); @@ -36,8 +36,7 @@ TEST(LeakTrackerTest, ReleaseMode) { #else -// In DEBUG mode, leak tracking should work. -TEST(LeakTrackerTest, DebugMode) { +TEST(LeakTrackerTest, Basic) { { ClassA a1; @@ -67,7 +66,7 @@ TEST(LeakTrackerTest, DebugMode) { // Try some orderings of create/remove to hit different cases in the linked-list // assembly. -TEST(LeakTrackerTest, DebugMode_LinkedList) { +TEST(LeakTrackerTest, LinkedList) { EXPECT_EQ(0, base::LeakTracker<ClassB>::NumLiveInstances()); scoped_ptr<ClassA> a1(new ClassA); @@ -98,11 +97,11 @@ TEST(LeakTrackerTest, DebugMode_LinkedList) { EXPECT_EQ(0, base::LeakTracker<ClassA>::NumLiveInstances()); } -TEST(LeakTrackerTest, DebugMode_NoOpCheckForLeaks) { +TEST(LeakTrackerTest, NoOpCheckForLeaks) { // There are no live instances of ClassA, so this should do nothing. base::LeakTracker<ClassA>::CheckForLeaks(); } -#endif // NDEBUG +#endif // ENABLE_LEAK_TRACKER } // namespace |