2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
7 #ifdef ARMNN_LEAK_CHECKING_ENABLED
16 class ScopedLeakChecker final
19 ScopedLeakChecker(const std::string & name);
22 // Forwarding these to Google Performance Tools.
23 static bool IsActive();
25 // Note that the following two functions only work after
26 // NoLeaks() has been called. See explanations in
28 ssize_t BytesLeaked() const;
29 ssize_t ObjectsLeaked() const;
32 // Hides imlementation so we don't litter other's namespaces
33 // with heap checker related stuff.
35 std::unique_ptr<Impl> m_Impl;
37 // No default construction and copying.
38 ScopedLeakChecker() = delete;
39 ScopedLeakChecker(const ScopedLeakChecker &) = delete;
40 ScopedLeakChecker & operator=(const ScopedLeakChecker &) = delete;
43 class ScopedDisableLeakChecking final
46 ScopedDisableLeakChecking();
47 ~ScopedDisableLeakChecking();
50 // Hides imlementation so we don't litter other's namespaces
51 // with heap checker related stuff.
53 std::unique_ptr<Impl> m_Impl;
56 ScopedDisableLeakChecking(const ScopedDisableLeakChecking &) = delete;
57 ScopedDisableLeakChecking & operator=(const ScopedDisableLeakChecking &) = delete;
60 // disable global leak checks starting from 'main'
61 void LocalLeakCheckingOnly();
63 } // namespace armnnUtils
65 #define ARMNN_SCOPED_LEAK_CHECKER(TAG) \
66 armnnUtils::ScopedLeakChecker __scoped_armnn_leak_checker__(TAG)
68 #define ARMNN_LEAK_CHECKER_IS_ACTIVE() \
69 armnnUtils::ScopedLeakChecker::IsActive()
71 #define ARMNN_NO_LEAKS_IN_SCOPE() \
72 __scoped_armnn_leak_checker__.NoLeaks()
74 #define ARMNN_BYTES_LEAKED_IN_SCOPE() \
75 __scoped_armnn_leak_checker__.BytesLeaked()
77 #define ARMNN_OBJECTS_LEAKED_IN_SCOPE() \
78 __scoped_armnn_leak_checker__.ObjectsLeaked()
80 #define ARMNN_DISABLE_LEAK_CHECKING_IN_SCOPE() \
81 armnnUtils::ScopedDisableLeakChecking __disable_leak_checking_in_scope__
83 #define ARMNN_LOCAL_LEAK_CHECKING_ONLY() \
84 armnnUtils::LocalLeakCheckingOnly()
86 #else // ARMNN_LEAK_CHECKING_ENABLED
88 #define ARMNN_SCOPED_LEAK_CHECKER(TAG)
89 #define ARMNN_LEAK_CHECKER_IS_ACTIVE() false
90 #define ARMNN_NO_LEAKS_IN_SCOPE() true
91 #define ARMNN_BYTES_LEAKED_IN_SCOPE() 0
92 #define ARMNN_OBJECTS_LEAKED_IN_SCOPE() 0
93 #define ARMNN_DISABLE_LEAK_CHECKING_IN_SCOPE()
94 #define ARMNN_LOCAL_LEAK_CHECKING_ONLY()
96 #endif // ARMNN_LEAK_CHECKING_ENABLED