2012-12-11 04:05:07 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef DMD_h___
|
|
|
|
#define DMD_h___
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2012-12-12 01:54:11 +04:00
|
|
|
#include <string.h>
|
2012-12-11 04:05:07 +04:00
|
|
|
|
|
|
|
#include "mozilla/Types.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dmd {
|
|
|
|
|
|
|
|
// Mark a heap block as reported by a memory reporter.
|
|
|
|
MOZ_EXPORT void
|
2012-12-17 04:56:04 +04:00
|
|
|
Report(const void* aPtr);
|
2012-12-11 04:05:07 +04:00
|
|
|
|
|
|
|
// Mark a heap block as reported immediately on allocation.
|
|
|
|
MOZ_EXPORT void
|
2012-12-17 04:56:04 +04:00
|
|
|
ReportOnAlloc(const void* aPtr);
|
2012-12-11 04:05:07 +04:00
|
|
|
|
|
|
|
class Writer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef void (*WriterFun)(void* aWriteState, const char* aFmt, va_list aAp);
|
|
|
|
|
|
|
|
Writer(WriterFun aWriterFun, void* aWriteState)
|
|
|
|
: mWriterFun(aWriterFun), mWriteState(aWriteState)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void Write(const char* aFmt, ...) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
WriterFun mWriterFun;
|
|
|
|
void* mWriteState;
|
|
|
|
};
|
|
|
|
|
2013-01-07 01:34:39 +04:00
|
|
|
// Clears existing reportedness data from any prior runs of the memory
|
|
|
|
// reporters. The following sequence should be used.
|
|
|
|
// - ClearReports()
|
|
|
|
// - run the memory reporters
|
2014-05-30 10:46:09 +04:00
|
|
|
// - AnalyzeReports()
|
2013-01-07 01:34:39 +04:00
|
|
|
// This sequence avoids spurious twice-reported warnings.
|
|
|
|
MOZ_EXPORT void
|
|
|
|
ClearReports();
|
|
|
|
|
2014-05-30 10:46:09 +04:00
|
|
|
// Determines which heap blocks have been reported, and dumps a human-readable
|
2012-12-11 04:05:07 +04:00
|
|
|
// summary (via |aWrite|). If |aWrite| is nullptr it will dump to stderr.
|
2014-05-30 10:46:09 +04:00
|
|
|
// Beware: this output may have very long lines.
|
2012-12-11 04:05:07 +04:00
|
|
|
MOZ_EXPORT void
|
2014-05-30 10:46:09 +04:00
|
|
|
AnalyzeReports(const Writer& aWriter);
|
2012-12-11 04:05:07 +04:00
|
|
|
|
2014-05-30 10:46:09 +04:00
|
|
|
// Measures all heap blocks, and dumps a human-readable summary (via |aWrite|).
|
|
|
|
// If |aWrite| is nullptr it will dump to stderr. Beware: this output may
|
|
|
|
// have very long lines.
|
|
|
|
MOZ_EXPORT void
|
|
|
|
AnalyzeHeap(const Writer& aWriter);
|
|
|
|
|
|
|
|
// A useful |WriterFun|. For example, if |fp| is a FILE* you want
|
|
|
|
// |AnalyzeReports|'s output to be written to, call:
|
2014-04-08 21:07:46 +04:00
|
|
|
//
|
|
|
|
// dmd::Writer writer(FpWrite, fp);
|
2014-05-30 10:46:09 +04:00
|
|
|
// dmd::AnalyzeReports(writer);
|
2012-12-11 04:05:07 +04:00
|
|
|
MOZ_EXPORT void
|
|
|
|
FpWrite(void* aFp, const char* aFmt, va_list aAp);
|
|
|
|
|
2012-12-12 01:54:11 +04:00
|
|
|
struct Sizes
|
|
|
|
{
|
2012-12-24 06:48:03 +04:00
|
|
|
size_t mStackTracesUsed;
|
|
|
|
size_t mStackTracesUnused;
|
2012-12-12 01:54:11 +04:00
|
|
|
size_t mStackTraceTable;
|
2012-12-18 07:56:51 +04:00
|
|
|
size_t mBlockTable;
|
2012-12-12 01:54:11 +04:00
|
|
|
|
2012-12-19 03:14:31 +04:00
|
|
|
Sizes() { Clear(); }
|
|
|
|
void Clear() { memset(this, 0, sizeof(Sizes)); }
|
2012-12-12 01:54:11 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Gets the size of various data structures. Used to implement a memory
|
|
|
|
// reporter for DMD.
|
|
|
|
MOZ_EXPORT void
|
|
|
|
SizeOf(Sizes* aSizes);
|
|
|
|
|
2014-09-05 07:45:22 +04:00
|
|
|
// Prints a status message prefixed with "DMD[<pid>]". Use sparingly.
|
|
|
|
MOZ_EXPORT void
|
|
|
|
StatusMsg(const char* aFmt, ...);
|
|
|
|
|
2014-05-23 06:45:14 +04:00
|
|
|
// Indicates whether or not DMD is running.
|
2014-04-24 23:43:11 +04:00
|
|
|
MOZ_EXPORT bool
|
2014-05-23 06:45:14 +04:00
|
|
|
IsRunning();
|
2014-04-24 23:43:11 +04:00
|
|
|
|
2012-12-11 04:05:07 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
} // namespace dmd
|
|
|
|
|
|
|
|
#endif /* DMD_h___ */
|