mallocTag.h File Reference
+ Include dependency graph for mallocTag.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


class  TfMallocTag
 Top-down memory tagging system. More...
struct  TfMallocTag::CallTree
 Summary data structure for malloc statistics. More...
struct  TfMallocTag::CallTree::PathNode
 Node in the call tree structure. More...
struct  TfMallocTag::CallTree::CallSite
 Record of the bytes allocated under each different tag. More...
struct  TfMallocTag::CallStackInfo
 This struct is used to represent a call stack taken for an allocation that was billed under a specific malloc tag. More...
class  TfMallocTag::Auto
 Scoped (i.e. More...
class  TfMallocTag::Auto2
 Scoped (i.e. More...


#define TF_MALLOC_TAG_NEW(name1, name2)
 Enable lib/tf memory management. More...


typedef TfMallocTag::Auto TfAutoMallocTag
 Top-down memory tagging system. More...
typedef TfMallocTag::Auto2 TfAutoMallocTag2
 Top-down memory tagging system. More...

Class Documentation

◆ TfMallocTag::CallTree::PathNode

struct TfMallocTag::CallTree::PathNode

Node in the call tree structure.

A PathNode captures the hierarchy of active TfAutoMallocTag objects that are pushed and popped during program execution. Each PathNode thus describes a sequence of call-sites (i.e. a path down the call tree). Repeated call sites (in the case of co-recursive function calls) can be skipped, e.g. pushing tags "A", "B", "C", "B", "C" leads to only three path-nodes, representing the paths "A", "AB", and "ABC". Allocations done at the bottom (i.e. when tags "A", "B", "C", "B", "C" are all active) are billed to the longest path node in the sequence, which corresponds to the path "ABC").

Path nodes track both the memory they incur directly (nBytesDirect) but more importantly, the total memory allocated by themselves and any of their children (nBytes). The name of a node (siteName) corresponds to the tag name of the final tag in the path.

Definition at line 79 of file mallocTag.h.

Class Members
vector< PathNode > children Children nodes.
size_t nAllocations The number of allocations for this node.
size_t nBytes Allocated bytes by this or descendant nodes.
size_t nBytesDirect Allocated bytes (only for this node).
string siteName Tag name.

◆ TfMallocTag::CallTree::CallSite

struct TfMallocTag::CallTree::CallSite

Record of the bytes allocated under each different tag.

Each construction of a TfAutoMallocTag object with a different argument produces a distinct CallSite record. The total bytes outstanding for all memory allocations made under a given call-site are recorded in nBytes, while the name of the call site is available as name.

Definition at line 96 of file mallocTag.h.

Class Members
string name Tag name.
size_t nBytes Allocated bytes.

◆ TfMallocTag::CallStackInfo

struct TfMallocTag::CallStackInfo

This struct is used to represent a call stack taken for an allocation that was billed under a specific malloc tag.

Definition at line 162 of file mallocTag.h.

Class Members
size_t numAllocations The number of allocations (always one unless stack frames have been combined to create unique stacks).
size_t size The amount of allocated memory (accumulated over all allocations sharing this call stack).
vector< uintptr_t > stack The stack frame pointers.

Macro Definition Documentation


#define TF_MALLOC_TAG_NEW (   name1,

Enable lib/tf memory management.

Invoking this macro inside a class body causes the class operator new to push two TfAutoMallocTag objects onto the stack before actually allocating memory for the class. The names passed into the tag are used for the two tags; pass NULL if you don't need the second tag. For example,

class MyBigMeshVertex {
TF_MALLOC_TAG_NEW("MyBigMesh", "Vertex");

will cause dynamic allocations of MyBigMeshVertex to be grouped under the tag Vertex which is in turn grouped under MyBigMesh. However,

class MyBigMesh {

specifies NULL for the second tag because the first tag is sufficient.

Normally, this macro should be placed in the public section of a class. Note that you cannot specify both this and TF_FIXED_SIZE_ALLOCATOR() for the same class.

Also, note that allocations of a class inside an STL datastructure will not be grouped under the indicated tags.

Placed in .h files.

Definition at line 551 of file mallocTag.h.

Typedef Documentation

◆ TfAutoMallocTag

Top-down memory tagging system.

Definition at line 510 of file mallocTag.h.

◆ TfAutoMallocTag2

Top-down memory tagging system.

Definition at line 513 of file mallocTag.h.