surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // See LICENSE file in the project root for full license information. |
| 4 | // |
| 5 | |
| 6 | #ifdef ARMNN_LEAK_CHECKING_ENABLED |
| 7 | |
| 8 | #include "LeakChecking.hpp" |
| 9 | #include "gperftools/heap-checker.h" |
| 10 | |
| 11 | struct ScopedLeakChecker::Impl |
| 12 | { |
| 13 | HeapLeakChecker m_LeakChecker; |
| 14 | |
| 15 | Impl(const std::string & name) |
| 16 | : m_LeakChecker(name.c_str()) |
| 17 | { |
| 18 | } |
| 19 | }; |
| 20 | |
| 21 | ScopedLeakChecker::ScopedLeakChecker(const std::string & name) |
| 22 | : m_Impl(new Impl(name)) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | ScopedLeakChecker::~ScopedLeakChecker() {} |
| 27 | |
| 28 | bool ScopedLeakChecker::IsActive() |
| 29 | { |
| 30 | return HeapLeakChecker::IsActive(); |
| 31 | } |
| 32 | |
| 33 | bool ScopedLeakChecker::NoLeaks() |
| 34 | { |
| 35 | return (IsActive() ? m_Impl->m_LeakChecker.NoLeaks() : true); |
| 36 | } |
| 37 | |
| 38 | ssize_t ScopedLeakChecker::BytesLeaked() const |
| 39 | { |
| 40 | return (IsActive() ? m_Impl->m_LeakChecker.BytesLeaked(): 0); |
| 41 | } |
| 42 | |
| 43 | ssize_t ScopedLeakChecker::ObjectsLeaked() const |
| 44 | { |
| 45 | return (IsActive() ? m_Impl->m_LeakChecker.ObjectsLeaked(): 0 ); |
| 46 | } |
| 47 | |
| 48 | struct ScopedDisableLeakChecking::Impl |
| 49 | { |
| 50 | HeapLeakChecker::Disabler m_Disabler; |
| 51 | }; |
| 52 | |
| 53 | ScopedDisableLeakChecking::ScopedDisableLeakChecking() |
| 54 | : m_Impl(new Impl) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | ScopedDisableLeakChecking::~ScopedDisableLeakChecking() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | #endif // ARMNN_LEAK_CHECKING_ENABLED |