1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/memory/replace/dmd/DMD.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef DMD_h___ 1.11 +#define DMD_h___ 1.12 + 1.13 +#include <stdarg.h> 1.14 +#include <string.h> 1.15 + 1.16 +#include "mozilla/Types.h" 1.17 + 1.18 +namespace mozilla { 1.19 +namespace dmd { 1.20 + 1.21 +// Mark a heap block as reported by a memory reporter. 1.22 +MOZ_EXPORT void 1.23 +Report(const void* aPtr); 1.24 + 1.25 +// Mark a heap block as reported immediately on allocation. 1.26 +MOZ_EXPORT void 1.27 +ReportOnAlloc(const void* aPtr); 1.28 + 1.29 +class Writer 1.30 +{ 1.31 +public: 1.32 + typedef void (*WriterFun)(void* aWriteState, const char* aFmt, va_list aAp); 1.33 + 1.34 + Writer(WriterFun aWriterFun, void* aWriteState) 1.35 + : mWriterFun(aWriterFun), mWriteState(aWriteState) 1.36 + {} 1.37 + 1.38 + void Write(const char* aFmt, ...) const; 1.39 + 1.40 +private: 1.41 + WriterFun mWriterFun; 1.42 + void* mWriteState; 1.43 +}; 1.44 + 1.45 +// Clears existing reportedness data from any prior runs of the memory 1.46 +// reporters. The following sequence should be used. 1.47 +// - ClearReports() 1.48 +// - run the memory reporters 1.49 +// - Dump() 1.50 +// This sequence avoids spurious twice-reported warnings. 1.51 +MOZ_EXPORT void 1.52 +ClearReports(); 1.53 + 1.54 +// Checks which heap blocks have been reported, and dumps a human-readable 1.55 +// summary (via |aWrite|). If |aWrite| is nullptr it will dump to stderr. 1.56 +// Beware: this output may have very long lines. 1.57 +MOZ_EXPORT void 1.58 +Dump(Writer aWriter); 1.59 + 1.60 +// A useful |WriterFun|. If |fp| is a FILE* you want |Dump|'s output to be 1.61 +// written to, call: 1.62 +// 1.63 +// dmd::Writer writer(FpWrite, fp); 1.64 +// dmd::Dump(writer); 1.65 +MOZ_EXPORT void 1.66 +FpWrite(void* aFp, const char* aFmt, va_list aAp); 1.67 + 1.68 +struct Sizes 1.69 +{ 1.70 + size_t mStackTracesUsed; 1.71 + size_t mStackTracesUnused; 1.72 + size_t mStackTraceTable; 1.73 + size_t mBlockTable; 1.74 + 1.75 + Sizes() { Clear(); } 1.76 + void Clear() { memset(this, 0, sizeof(Sizes)); } 1.77 +}; 1.78 + 1.79 +// Gets the size of various data structures. Used to implement a memory 1.80 +// reporter for DMD. 1.81 +MOZ_EXPORT void 1.82 +SizeOf(Sizes* aSizes); 1.83 + 1.84 +// Indicates whether or not DMD is enabled. 1.85 +MOZ_EXPORT bool 1.86 +IsEnabled(); 1.87 + 1.88 +} // namespace mozilla 1.89 +} // namespace dmd 1.90 + 1.91 +#endif /* DMD_h___ */