Panda3D
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
MemoryUsage Class Reference

This class is used strictly for debugging purposes, specifically for tracking memory leaks of reference-counted objects: it keeps a record of every such object currently allocated. More...

Inheritance diagram for MemoryUsage:

Public Member Functions

 __init__ (const MemoryUsage)
 

Static Public Member Functions

static freeze ()
 'Freezes' all pointers currently stored so that they are no longer reported; only newly allocate pointers from this point on will appear in future information requests. More...
 
static int getCurrentCppSize ()
 Returns the total number of bytes of allocated memory consumed by C++ objects, not including the memory previously frozen. More...
 
static int getExternalSize ()
 Returns the total number of bytes of allocated memory in the heap that Panda didn't seem to be responsible for. More...
 
static int getNumPointers ()
 Returns the number of pointers currently active. More...
 
static int getPandaHeapArraySize ()
 Returns the total number of bytes allocated from the heap from code within Panda, for arrays. More...
 
static int getPandaHeapOverhead ()
 Returns the extra bytes allocated from the system that are not immediately used for holding allocated objects. More...
 
static int getPandaHeapSingleSize ()
 Returns the total number of bytes allocated from the heap from code within Panda, for individual objects. More...
 
static int getPandaMmapSize ()
 Returns the total number of bytes allocated from the virtual memory pool from code within Panda. More...
 
static getPointers (MemoryUsagePointers result)
 Fills the indicated MemoryUsagePointers with the set of all pointers currently active. More...
 
static getPointersOfAge (MemoryUsagePointers result, double from, double to)
 Fills the indicated MemoryUsagePointers with the set of all pointers that were allocated within the range of the indicated number of seconds ago. More...
 
static getPointersOfType (MemoryUsagePointers result, TypeHandle type)
 Fills the indicated MemoryUsagePointers with the set of all pointers of the indicated type currently active. More...
 
static getPointersWithZeroCount (MemoryUsagePointers result)
 Fills the indicated MemoryUsagePointers with the set of all currently active pointers (that is, pointers allocated since the last call to freeze(), and not yet freed) that have a zero reference count. More...
 
static int getTotalCppSize ()
 Returns the total number of bytes of allocated memory consumed by C++ objects, including the memory previously frozen. More...
 
static int getTotalSize ()
 Returns the total size of allocated memory consumed by the process, as nearly as can be determined. More...
 
static bool isCounting ()
 Returns true if the MemoryUsage object is currently at least counting memory (e.g. More...
 
static bool isTracking ()
 Returns true if the MemoryUsage object is currently tracking memory (e.g. More...
 
static showCurrentAges ()
 Shows the breakdown of ages of all of the active pointers. More...
 
static showCurrentTypes ()
 Shows the breakdown of types of all of the active pointers. More...
 
static showTrendAges ()
 Shows the breakdown of ages of all of the pointers allocated and freed since the last call to freeze(). More...
 
static showTrendTypes ()
 Shows the breakdown of types of all of the pointers allocated and freed since the last call to freeze(). More...
 

Public Attributes

bool counting
 Returns true if the MemoryUsage object is currently at least counting memory (e.g. More...
 
int current_cpp_size
 Returns the total number of bytes of allocated memory consumed by C++ objects, not including the memory previously frozen. More...
 
int external_size
 Returns the total number of bytes of allocated memory in the heap that Panda didn't seem to be responsible for. More...
 
int panda_heap_array_size
 Returns the total number of bytes allocated from the heap from code within Panda, for arrays. More...
 
int panda_heap_overhead
 Returns the extra bytes allocated from the system that are not immediately used for holding allocated objects. More...
 
int panda_heap_single_size
 Returns the total number of bytes allocated from the heap from code within Panda, for individual objects. More...
 
int panda_mmap_size
 Returns the total number of bytes allocated from the virtual memory pool from code within Panda. More...
 
int total_cpp_size
 Returns the total number of bytes of allocated memory consumed by C++ objects, including the memory previously frozen. More...
 
int total_size
 Returns the total size of allocated memory consumed by the process, as nearly as can be determined. More...
 
bool tracking
 Returns true if the MemoryUsage object is currently tracking memory (e.g. More...
 

Detailed Description

This class is used strictly for debugging purposes, specifically for tracking memory leaks of reference-counted objects: it keeps a record of every such object currently allocated.

When compiled with NDEBUG set, this entire class does nothing and compiles to a stub.

Member Function Documentation

◆ __init__()

__init__ ( const  MemoryUsage)

◆ freeze()

static freeze ( )
static

'Freezes' all pointers currently stored so that they are no longer reported; only newly allocate pointers from this point on will appear in future information requests.

This makes it easier to differentiate between continuous leaks and one-time memory allocations.

◆ getCurrentCppSize()

static int getCurrentCppSize ( )
static

Returns the total number of bytes of allocated memory consumed by C++ objects, not including the memory previously frozen.

◆ getExternalSize()

static int getExternalSize ( )
static

Returns the total number of bytes of allocated memory in the heap that Panda didn't seem to be responsible for.

This includes a few bytes for very low-level objects (like ConfigVariables) that cannot use Panda memory tracking because they are so very low-level.

This also includes all of the memory that might have been allocated by a high-level interpreter, like Python.

This number is only available if Panda is able to hook into the actual heap callback.

◆ getNumPointers()

static int getNumPointers ( )
static

Returns the number of pointers currently active.

◆ getPandaHeapArraySize()

static int getPandaHeapArraySize ( )
static

Returns the total number of bytes allocated from the heap from code within Panda, for arrays.

◆ getPandaHeapOverhead()

static int getPandaHeapOverhead ( )
static

Returns the extra bytes allocated from the system that are not immediately used for holding allocated objects.

This can only be determined if ALTERNATIVE_MALLOC is enabled.

◆ getPandaHeapSingleSize()

static int getPandaHeapSingleSize ( )
static

Returns the total number of bytes allocated from the heap from code within Panda, for individual objects.

◆ getPandaMmapSize()

static int getPandaMmapSize ( )
static

Returns the total number of bytes allocated from the virtual memory pool from code within Panda.

◆ getPointers()

static getPointers ( MemoryUsagePointers  result)
static

Fills the indicated MemoryUsagePointers with the set of all pointers currently active.

◆ getPointersOfAge()

static getPointersOfAge ( MemoryUsagePointers  result,
double  from,
double  to 
)
static

Fills the indicated MemoryUsagePointers with the set of all pointers that were allocated within the range of the indicated number of seconds ago.

◆ getPointersOfType()

static getPointersOfType ( MemoryUsagePointers  result,
TypeHandle  type 
)
static

Fills the indicated MemoryUsagePointers with the set of all pointers of the indicated type currently active.

◆ getPointersWithZeroCount()

static getPointersWithZeroCount ( MemoryUsagePointers  result)
static

Fills the indicated MemoryUsagePointers with the set of all currently active pointers (that is, pointers allocated since the last call to freeze(), and not yet freed) that have a zero reference count.

Generally, an undeleted pointer with a zero reference count means its reference count has never been incremented beyond zero (since once it has been incremented, the only way it can return to zero would free the pointer). This may include objects that are allocated statically or on the stack, which are never intended to be deleted. Or, it might represent a programmer or compiler error.

This function has the side-effect of incrementing each of their reference counts by one, thus preventing them from ever being freed–but since they hadn't been freed anyway, probably no additional harm is done.

◆ getTotalCppSize()

static int getTotalCppSize ( )
static

Returns the total number of bytes of allocated memory consumed by C++ objects, including the memory previously frozen.

◆ getTotalSize()

static int getTotalSize ( )
static

Returns the total size of allocated memory consumed by the process, as nearly as can be determined.

◆ isCounting()

static bool isCounting ( )
static

Returns true if the MemoryUsage object is currently at least counting memory (e.g.

this is a Windows debug build), even if it's not fully tracking it.

◆ isTracking()

static bool isTracking ( )
static

Returns true if the MemoryUsage object is currently tracking memory (e.g.

track-memory-usage is configured #t).

◆ showCurrentAges()

static showCurrentAges ( )
static

Shows the breakdown of ages of all of the active pointers.

◆ showCurrentTypes()

static showCurrentTypes ( )
static

Shows the breakdown of types of all of the active pointers.

◆ showTrendAges()

static showTrendAges ( )
static

Shows the breakdown of ages of all of the pointers allocated and freed since the last call to freeze().

◆ showTrendTypes()

static showTrendTypes ( )
static

Shows the breakdown of types of all of the pointers allocated and freed since the last call to freeze().

Member Data Documentation

◆ counting

bool counting

Returns true if the MemoryUsage object is currently at least counting memory (e.g.

this is a Windows debug build), even if it's not fully tracking it.

◆ current_cpp_size

int current_cpp_size

Returns the total number of bytes of allocated memory consumed by C++ objects, not including the memory previously frozen.

◆ external_size

int external_size

Returns the total number of bytes of allocated memory in the heap that Panda didn't seem to be responsible for.

This includes a few bytes for very low-level objects (like ConfigVariables) that cannot use Panda memory tracking because they are so very low-level.

This also includes all of the memory that might have been allocated by a high-level interpreter, like Python.

This number is only available if Panda is able to hook into the actual heap callback.

◆ panda_heap_array_size

int panda_heap_array_size

Returns the total number of bytes allocated from the heap from code within Panda, for arrays.

◆ panda_heap_overhead

int panda_heap_overhead

Returns the extra bytes allocated from the system that are not immediately used for holding allocated objects.

This can only be determined if ALTERNATIVE_MALLOC is enabled.

◆ panda_heap_single_size

int panda_heap_single_size

Returns the total number of bytes allocated from the heap from code within Panda, for individual objects.

◆ panda_mmap_size

int panda_mmap_size

Returns the total number of bytes allocated from the virtual memory pool from code within Panda.

◆ total_cpp_size

int total_cpp_size

Returns the total number of bytes of allocated memory consumed by C++ objects, including the memory previously frozen.

◆ total_size

int total_size

Returns the total size of allocated memory consumed by the process, as nearly as can be determined.

◆ tracking

bool tracking

Returns true if the MemoryUsage object is currently tracking memory (e.g.

track-memory-usage is configured #t).