aboutsummaryrefslogtreecommitdiff
path: root/src/armnnUtils/LeakChecking.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnnUtils/LeakChecking.cpp')
-rw-r--r--src/armnnUtils/LeakChecking.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/armnnUtils/LeakChecking.cpp b/src/armnnUtils/LeakChecking.cpp
new file mode 100644
index 0000000000..ac12fe01de
--- /dev/null
+++ b/src/armnnUtils/LeakChecking.cpp
@@ -0,0 +1,62 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#ifdef ARMNN_LEAK_CHECKING_ENABLED
+
+#include "LeakChecking.hpp"
+#include "gperftools/heap-checker.h"
+
+struct ScopedLeakChecker::Impl
+{
+ HeapLeakChecker m_LeakChecker;
+
+ Impl(const std::string & name)
+ : m_LeakChecker(name.c_str())
+ {
+ }
+};
+
+ScopedLeakChecker::ScopedLeakChecker(const std::string & name)
+: m_Impl(new Impl(name))
+{
+}
+
+ScopedLeakChecker::~ScopedLeakChecker() {}
+
+bool ScopedLeakChecker::IsActive()
+{
+ return HeapLeakChecker::IsActive();
+}
+
+bool ScopedLeakChecker::NoLeaks()
+{
+ return (IsActive() ? m_Impl->m_LeakChecker.NoLeaks() : true);
+}
+
+ssize_t ScopedLeakChecker::BytesLeaked() const
+{
+ return (IsActive() ? m_Impl->m_LeakChecker.BytesLeaked(): 0);
+}
+
+ssize_t ScopedLeakChecker::ObjectsLeaked() const
+{
+ return (IsActive() ? m_Impl->m_LeakChecker.ObjectsLeaked(): 0 );
+}
+
+struct ScopedDisableLeakChecking::Impl
+{
+ HeapLeakChecker::Disabler m_Disabler;
+};
+
+ScopedDisableLeakChecking::ScopedDisableLeakChecking()
+: m_Impl(new Impl)
+{
+}
+
+ScopedDisableLeakChecking::~ScopedDisableLeakChecking()
+{
+}
+
+#endif // ARMNN_LEAK_CHECKING_ENABLED