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