00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SUPPORT_ATOM_DEBUG_H
00014 #define _SUPPORT_ATOM_DEBUG_H
00015
00016 #include <support/Atom.h>
00017 #include <support/atomic.h>
00018
00019 #define INITIAL_PRIMARY_VALUE (1<<28)
00020
00021 #ifndef SUPPORTS_ATOM_DEBUG
00022 #if BUILD_TYPE == BUILD_TYPE_DEBUG
00023 #define SUPPORTS_ATOM_DEBUG 1
00024 #else
00025 #define SUPPORTS_ATOM_DEBUG 0
00026 #endif
00027 #endif
00028
00029 #if SUPPORTS_ATOM_DEBUG
00030
00031 #include <support/CallStack.h>
00032 #include <support/Locker.h>
00033 #include <support/ITextStream.h>
00034 #include <support/SortedVector.h>
00035 #include <support/String.h>
00036
00037 #if _SUPPORTS_NAMESPACE
00038 namespace palmos {
00039 namespace osp {
00040
00041 using namespace palmos::support;
00042 using namespace std;
00043 #endif // _SUPPORTS_NAMESPACE
00044
00045
00046 int32_t AtomDebugLevel();
00047 int32_t AtomReportLevel(uint32_t flags);
00048
00049
00050
00051 class SAtomLeakChecker {
00052 public:
00053 SAtomLeakChecker();
00054 ~SAtomLeakChecker();
00055
00056 void Reset();
00057 void Shutdown();
00058
00059 void NoteCreate();
00060 void NoteDestroy();
00061 void NoteFree();
00062
00063 private:
00064 int32_t fCreated;
00065 int32_t fDestroyed;
00066 int32_t fFreed;
00067 };
00068
00069 struct atom_ref_info {
00070 const void* id;
00071 SCallStack stack;
00072 int32_t count;
00073 SysHandle thid;
00074 nsecs_t when;
00075 char* note;
00076 atom_ref_info* next;
00077
00078 atom_ref_info();
00079 ~atom_ref_info();
00080
00081 bool operator==(const atom_ref_info& o) const;
00082 void report(const sptr<ITextOutput>& io, bool longForm=false) const;
00083
00084 int32_t refcount() const;
00085 atom_ref_info* find_last_ref();
00086 };
00087
00088 struct atom_debug : public SLocker {
00089 SAtom* atom;
00090 SLightAtom* lightAtom;
00091 SString typenm;
00092 int32_t primary;
00093 int32_t secondary;
00094 int32_t initialized;
00095 int32_t mark;
00096 atom_ref_info* incStrongs;
00097 atom_ref_info* decStrongs;
00098 atom_ref_info* incWeaks;
00099 atom_ref_info* decWeaks;
00100
00101 atom_debug(SAtom* inAtom);
00102 atom_debug(SLightAtom* inAtom);
00103 ~atom_debug();
00104
00105 void report(const sptr<ITextOutput>& io, uint32_t flags) const;
00106 };
00107
00108 class SAtomTracker
00109 {
00110 public:
00111 SAtomTracker();
00112 ~SAtomTracker();
00113
00114 void Reset();
00115 void Shutdown();
00116
00117 void AddAtom(atom_debug* info);
00118 void RemoveAtom(atom_debug* info);
00119
00120 inline int32_t CurrentMark() const { return fCurMark; }
00121 inline int32_t IncrementMark() { return atomic_add(&fCurMark, 1) + 1; }
00122
00123 void PrintActive(const sptr<ITextOutput>& io, int32_t mark, int32_t last, uint32_t flags) const;
00124
00125 bool HasAtom(SAtom* a, bool primary);
00126 bool HasLightAtom(SLightAtom* a);
00127 void GetActiveTypeNames(SSortedVector<SString>* outNames);
00128 void GetAllWithTypeName(const char* typeName, SVector<wptr<SAtom> >* outAtoms, SVector<sptr<SLightAtom> >* outLightAtoms);
00129
00130 void StartWatching(const B_SNS(std::)type_info* type);
00131 void StopWatching(const B_SNS(std::)type_info* type);
00132 void WatchAction(const SAtom* which, const char* action);
00133 void WatchAction(const SLightAtom* which, const char* action);
00134
00135 private:
00136 mutable SNestedLocker fAccess;
00137 bool fGone;
00138 bool fWatching;
00139 int32_t fFirstMark;
00140 int32_t fCurMark;
00141
00142 SSortedVector<atom_debug*> fActiveAtoms;
00143 SSortedVector<B_SNS(std::)type_info*> fWatchTypes;
00144 };
00145
00146 SAtomLeakChecker* LeakChecker();
00147 SAtomTracker* Tracker();
00148
00149 #if _SUPPORTS_NAMESPACE
00150 } }
00151 #endif // _SUPPORTS_NAMESPACE
00152
00153 #endif
00154
00155 #endif