Loading...
Searching...
No Matches
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.

Classes

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...
 

Macros

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

Typedefs

using TfAutoMallocTag = TfMallocTag::Auto
 Top-down memory tagging system.
 
using TfAutoMallocTag2 = TfMallocTag::Auto
 Top-down memory tagging system.
 

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 80 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 97 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 163 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

◆ TF_MALLOC_TAG_NEW

#define TF_MALLOC_TAG_NEW (   name1,
  name2 
)

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 {
public:
TF_MALLOC_TAG_NEW("MyBigMesh", "Vertex");
...
}
#define TF_MALLOC_TAG_NEW(name1, name2)
Enable lib/tf memory management.
Definition: mallocTag.h:489

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

class MyBigMesh {
public:
TF_MALLOC_TAG_NEW("MyBigMesh", NULL);
...
}

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.

Remarks
Placed in .h files.

Definition at line 489 of file mallocTag.h.

Typedef Documentation

◆ TfAutoMallocTag

Top-down memory tagging system.

Definition at line 448 of file mallocTag.h.

◆ TfAutoMallocTag2

Top-down memory tagging system.

Definition at line 451 of file mallocTag.h.