michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef DMD_h___ michael@0: #define DMD_h___ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "mozilla/Types.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dmd { michael@0: michael@0: // Mark a heap block as reported by a memory reporter. michael@0: MOZ_EXPORT void michael@0: Report(const void* aPtr); michael@0: michael@0: // Mark a heap block as reported immediately on allocation. michael@0: MOZ_EXPORT void michael@0: ReportOnAlloc(const void* aPtr); michael@0: michael@0: class Writer michael@0: { michael@0: public: michael@0: typedef void (*WriterFun)(void* aWriteState, const char* aFmt, va_list aAp); michael@0: michael@0: Writer(WriterFun aWriterFun, void* aWriteState) michael@0: : mWriterFun(aWriterFun), mWriteState(aWriteState) michael@0: {} michael@0: michael@0: void Write(const char* aFmt, ...) const; michael@0: michael@0: private: michael@0: WriterFun mWriterFun; michael@0: void* mWriteState; michael@0: }; michael@0: michael@0: // Clears existing reportedness data from any prior runs of the memory michael@0: // reporters. The following sequence should be used. michael@0: // - ClearReports() michael@0: // - run the memory reporters michael@0: // - Dump() michael@0: // This sequence avoids spurious twice-reported warnings. michael@0: MOZ_EXPORT void michael@0: ClearReports(); michael@0: michael@0: // Checks which heap blocks have been reported, and dumps a human-readable michael@0: // summary (via |aWrite|). If |aWrite| is nullptr it will dump to stderr. michael@0: // Beware: this output may have very long lines. michael@0: MOZ_EXPORT void michael@0: Dump(Writer aWriter); michael@0: michael@0: // A useful |WriterFun|. If |fp| is a FILE* you want |Dump|'s output to be michael@0: // written to, call: michael@0: // michael@0: // dmd::Writer writer(FpWrite, fp); michael@0: // dmd::Dump(writer); michael@0: MOZ_EXPORT void michael@0: FpWrite(void* aFp, const char* aFmt, va_list aAp); michael@0: michael@0: struct Sizes michael@0: { michael@0: size_t mStackTracesUsed; michael@0: size_t mStackTracesUnused; michael@0: size_t mStackTraceTable; michael@0: size_t mBlockTable; michael@0: michael@0: Sizes() { Clear(); } michael@0: void Clear() { memset(this, 0, sizeof(Sizes)); } michael@0: }; michael@0: michael@0: // Gets the size of various data structures. Used to implement a memory michael@0: // reporter for DMD. michael@0: MOZ_EXPORT void michael@0: SizeOf(Sizes* aSizes); michael@0: michael@0: // Indicates whether or not DMD is enabled. michael@0: MOZ_EXPORT bool michael@0: IsEnabled(); michael@0: michael@0: } // namespace mozilla michael@0: } // namespace dmd michael@0: michael@0: #endif /* DMD_h___ */