memory/replace/dmd/DMD.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef DMD_h___
michael@0 8 #define DMD_h___
michael@0 9
michael@0 10 #include <stdarg.h>
michael@0 11 #include <string.h>
michael@0 12
michael@0 13 #include "mozilla/Types.h"
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace dmd {
michael@0 17
michael@0 18 // Mark a heap block as reported by a memory reporter.
michael@0 19 MOZ_EXPORT void
michael@0 20 Report(const void* aPtr);
michael@0 21
michael@0 22 // Mark a heap block as reported immediately on allocation.
michael@0 23 MOZ_EXPORT void
michael@0 24 ReportOnAlloc(const void* aPtr);
michael@0 25
michael@0 26 class Writer
michael@0 27 {
michael@0 28 public:
michael@0 29 typedef void (*WriterFun)(void* aWriteState, const char* aFmt, va_list aAp);
michael@0 30
michael@0 31 Writer(WriterFun aWriterFun, void* aWriteState)
michael@0 32 : mWriterFun(aWriterFun), mWriteState(aWriteState)
michael@0 33 {}
michael@0 34
michael@0 35 void Write(const char* aFmt, ...) const;
michael@0 36
michael@0 37 private:
michael@0 38 WriterFun mWriterFun;
michael@0 39 void* mWriteState;
michael@0 40 };
michael@0 41
michael@0 42 // Clears existing reportedness data from any prior runs of the memory
michael@0 43 // reporters. The following sequence should be used.
michael@0 44 // - ClearReports()
michael@0 45 // - run the memory reporters
michael@0 46 // - Dump()
michael@0 47 // This sequence avoids spurious twice-reported warnings.
michael@0 48 MOZ_EXPORT void
michael@0 49 ClearReports();
michael@0 50
michael@0 51 // Checks which heap blocks have been reported, and dumps a human-readable
michael@0 52 // summary (via |aWrite|). If |aWrite| is nullptr it will dump to stderr.
michael@0 53 // Beware: this output may have very long lines.
michael@0 54 MOZ_EXPORT void
michael@0 55 Dump(Writer aWriter);
michael@0 56
michael@0 57 // A useful |WriterFun|. If |fp| is a FILE* you want |Dump|'s output to be
michael@0 58 // written to, call:
michael@0 59 //
michael@0 60 // dmd::Writer writer(FpWrite, fp);
michael@0 61 // dmd::Dump(writer);
michael@0 62 MOZ_EXPORT void
michael@0 63 FpWrite(void* aFp, const char* aFmt, va_list aAp);
michael@0 64
michael@0 65 struct Sizes
michael@0 66 {
michael@0 67 size_t mStackTracesUsed;
michael@0 68 size_t mStackTracesUnused;
michael@0 69 size_t mStackTraceTable;
michael@0 70 size_t mBlockTable;
michael@0 71
michael@0 72 Sizes() { Clear(); }
michael@0 73 void Clear() { memset(this, 0, sizeof(Sizes)); }
michael@0 74 };
michael@0 75
michael@0 76 // Gets the size of various data structures. Used to implement a memory
michael@0 77 // reporter for DMD.
michael@0 78 MOZ_EXPORT void
michael@0 79 SizeOf(Sizes* aSizes);
michael@0 80
michael@0 81 // Indicates whether or not DMD is enabled.
michael@0 82 MOZ_EXPORT bool
michael@0 83 IsEnabled();
michael@0 84
michael@0 85 } // namespace mozilla
michael@0 86 } // namespace dmd
michael@0 87
michael@0 88 #endif /* DMD_h___ */

mercurial