24 #ifndef PXR_BASE_TF_MALLOC_TAG_H
25 #define PXR_BASE_TF_MALLOC_TAG_H
28 #include "pxr/base/tf/api.h"
36 PXR_NAMESPACE_OPEN_SCOPE
41 struct Tf_MallocPathNode;
132 size_t maxPrintedNodes = 100000)
const;
142 const std::string &rootName)
const;
147 std::ostream &out)
const;
187 TF_API
static bool Initialize(std::string* errMsg);
194 return TfMallocTag::_doTagging;
223 TF_API
static bool GetCallTree(CallTree* tree,
bool skipRepeated =
true);
265 Auto& operator=(
const Auto &) =
delete;
281 Auto(
const char* name) : _threadData(0) {
282 if (TfMallocTag::_doTagging)
302 Auto(
const std::string& name) : _threadData(0) {
303 if (TfMallocTag::_doTagging)
334 TF_API
void _Begin(
const char* name);
335 TF_API
void _Begin(
const std::string& name);
338 _ThreadData* _threadData;
354 Auto2(
const char* name1,
const char* name2) :
363 Auto2(
const std::string& name1,
const std::string& name2) :
391 static void Push(
const std::string& name) {
393 noname._threadData = NULL;
397 static void Push(
const char* name) {
399 noname._threadData = NULL;
410 TF_API
static void Pop(
const char* name = NULL);
413 static void Pop(
const std::string& name) {
467 friend struct Tf_MallocGlobalData;
469 class _TemporaryTaggingState {
471 explicit _TemporaryTaggingState(_Tagging state);
472 ~_TemporaryTaggingState();
474 _TemporaryTaggingState(
const _TemporaryTaggingState &);
475 _TemporaryTaggingState& operator=(
const _TemporaryTaggingState &);
477 _TemporaryTaggingState(_TemporaryTaggingState &&);
478 _TemporaryTaggingState& operator=(_TemporaryTaggingState &&);
484 static void _SetTagging(_Tagging state);
485 static _Tagging _GetTagging();
487 static bool _Initialize(std::string* errMsg);
489 static inline bool _ShouldNotTag(_ThreadData**, _Tagging* t = NULL);
490 static inline Tf_MallocPathNode* _GetCurrentPathNodeNoLock(
491 const _ThreadData* threadData);
493 static void* _MallocWrapper_ptmalloc(
size_t,
const void*);
494 static void* _ReallocWrapper_ptmalloc(
void*,
size_t,
const void*);
495 static void* _MemalignWrapper_ptmalloc(
size_t,
size_t,
const void*);
496 static void _FreeWrapper_ptmalloc(
void*,
const void*);
498 static void* _MallocWrapper(
size_t,
const void*);
499 static void* _ReallocWrapper(
void*,
size_t,
const void*);
500 static void* _MemalignWrapper(
size_t,
size_t,
const void*);
501 static void _FreeWrapper(
void*,
const void*);
505 friend class TfMallocTag::Tls;
506 TF_API
static bool _doTagging;
549 PXR_NAMESPACE_CLOSE_SCOPE
551 #define TF_MALLOC_TAG_NEW(name1, name2) \
553 inline void* operator new(::std::size_t, void* ptr) { \
557 inline void* operator new(::std::size_t s) { \
558 PXR_NS::TfAutoMallocTag tag1(name1); \
559 PXR_NS::TfAutoMallocTag tag2(name2); \
563 inline void* operator new[](::std::size_t s) { \
564 PXR_NS::TfAutoMallocTag tag1(name1); \
565 PXR_NS::TfAutoMallocTag tag2(name2); \
570 inline void operator delete(void* ptr, void* place) {} \
572 inline void operator delete(void* ptr, size_t) { \
576 inline void operator delete[] (void* ptr, size_t) { \
static void Push(const char *name)
Summary data structure for malloc statistics.
Auto2(const char *name1, const char *name2)
Push two memory tags onto the local-call stack.
static TF_API void Pop(const char *name=NULL)
Manually pop a tag from the stack.
static TF_API size_t GetTotalBytes()
Return total number of allocated bytes.
This struct is used to represent a call stack taken for an allocation that was billed under a specifi...
size_t nAllocations
The number of allocations for this node.
void Release()
Pop the tag from the stack before it is destructed.
Auto(const char *name)
Push a memory tag onto the local-call stack with name name.
size_t nBytes
Allocated bytes by this or descendant nodes.
static TF_API bool GetCallTree(CallTree *tree, bool skipRepeated=true)
Return a snapshot of memory usage.
size_t size
The amount of allocated memory (accumulated over all allocations sharing this call stack)...
Print both tree and call sites.
std::vector< CallStackInfo > capturedCallStacks
The captured malloc stacks.
TF_API std::string GetPrettyPrintString(PrintSetting setting=BOTH, size_t maxPrintedNodes=100000) const
Return the malloc report string.
std::vector< uintptr_t > stack
The stack frame pointers.
TF_API void Report(std::ostream &out, const std::string &rootName) const
Generates a report to the ostream out.
std::vector< CallSite > callSites
All call sites.
std::string name
Tag name.
void Release()
Pop two memory tags from the local-call stack.
PathNode root
Root node of the call-site hierarchy.
Print the full call tree.
static TF_API void SetDebugMatchList(const std::string &matchList)
Sets the tags to trap in the debugger.
Print just the call sites > 0.1%.
TfMallocTag::Auto2 TfAutoMallocTag2
Top-down memory tagging system.
static TF_API void SetCapturedMallocStacksMatchList(const std::string &matchList)
Sets the tags to trace.
PrintSetting
Specify which parts of the report to print.
std::string siteName
Tag name.
static TF_API std::vector< std::vector< uintptr_t > > GetCapturedMallocStacks()
Returns the captured malloc stack traces for allocations billed to the malloc tags passed to SetCaptu...
std::vector< PathNode > children
Children nodes.
Auto(const std::string &name)
Push a memory tag onto the local-call stack with name name.
TfMallocTag::Auto TfAutoMallocTag
Top-down memory tagging system.
Top-down memory tagging system.
static bool IsInitialized()
Return true if the tagging system is active.
static void Push(const std::string &name)
Manually push a tag onto the stack.
static void Pop(const std::string &name)
size_t numAllocations
The number of allocations (always one unless stack frames have been combined to create unique stacks)...
size_t nBytesDirect
Allocated bytes (only for this node).
static TF_API size_t GetMaxTotalBytes()
Return the maximum total number of bytes that have ever been allocated at one time.
Node in the call tree structure.
Record of the bytes allocated under each different tag.
Auto2(const std::string &name1, const std::string &name2)
Push two memory tags onto the local-call stack.
static TF_API bool Initialize(std::string *errMsg)
Initialize the memory tagging system.
~Auto()
Pop a memory tag from the local-call stack.