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

#include "memoryUsage.h"

Inheritance diagram for MemoryUsage:
MemoryHook

Static Public Member Functions

static void 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 size_t get_current_cpp_size ()
 
static size_t get_external_size ()
 
static int get_num_pointers ()
 Returns the number of pointers currently active. More...
 
static size_t get_panda_heap_array_size ()
 
static size_t get_panda_heap_overhead ()
 
static size_t get_panda_heap_single_size ()
 
static size_t get_panda_mmap_size ()
 
static void get_pointers (MemoryUsagePointers &result)
 Fills the indicated MemoryUsagePointers with the set of all pointers currently active. More...
 
static void get_pointers_of_age (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 void get_pointers_of_type (MemoryUsagePointers &result, TypeHandle type)
 Fills the indicated MemoryUsagePointers with the set of all pointers of the indicated type currently active. More...
 
static void get_pointers_with_zero_count (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 size_t get_total_cpp_size ()
 
static size_t get_total_size ()
 
static bool get_track_memory_usage ()
 Returns true if the user has Configured the variable 'track-memory-usage' to true, indicating that this class will be in effect. More...
 
static bool is_counting ()
 
static bool is_tracking ()
 
static void record_pointer (ReferenceCount *ptr)
 Indicates that the given pointer has been recently allocated. More...
 
static void record_pointer (void *ptr, TypeHandle type)
 Indicates that the given pointer has been recently allocated. More...
 
static void remove_pointer (ReferenceCount *ptr)
 Indicates that the given pointer has been recently freed. More...
 
static void show_current_ages ()
 Shows the breakdown of ages of all of the active pointers. More...
 
static void show_current_types ()
 Shows the breakdown of types of all of the active pointers. More...
 
static void show_trend_ages ()
 Shows the breakdown of ages of all of the pointers allocated and freed since the last call to freeze(). More...
 
static void show_trend_types ()
 Shows the breakdown of types of all of the pointers allocated and freed since the last call to freeze(). More...
 
static void update_type (ReferenceCount *ptr, TypeHandle type)
 Associates the indicated type with the given pointer. More...
 
static void update_type (ReferenceCount *ptr, TypedObject *typed_ptr)
 Associates the indicated type with the given pointer. More...
 
static void update_type (void *ptr, TypeHandle type)
 Associates the indicated type with the given pointer. More...
 
- Static Public Member Functions inherited from MemoryHook
static constexpr size_t get_memory_alignment ()
 
static size_t get_ptr_size (void *ptr)
 Given a pointer that was returned by a MemoryHook allocation, returns the number of bytes that were allocated for it. More...
 

Public Attributes

 get_current_cpp_size
 Returns the total number of bytes of allocated memory consumed by C++ objects, not including the memory previously frozen. More...
 
 get_external_size
 Returns the total number of bytes of allocated memory in the heap that Panda didn't seem to be responsible for. More...
 
 get_panda_heap_array_size
 Returns the total number of bytes allocated from the heap from code within Panda, for arrays. More...
 
 get_panda_heap_overhead
 Returns the extra bytes allocated from the system that are not immediately used for holding allocated objects. More...
 
 get_panda_heap_single_size
 Returns the total number of bytes allocated from the heap from code within Panda, for individual objects. More...
 
 get_panda_mmap_size
 Returns the total number of bytes allocated from the virtual memory pool from code within Panda. More...
 
 get_total_cpp_size
 Returns the total number of bytes of allocated memory consumed by C++ objects, including the memory previously frozen. More...
 
 get_total_size
 Returns the total size of allocated memory consumed by the process, as nearly as can be determined. More...
 
 is_counting
 Returns true if the MemoryUsage object is currently at least counting memory (e.g. More...
 
 is_tracking
 Returns true if the MemoryUsage object is currently tracking memory (e.g. More...
 

Additional Inherited Members

- Public Member Functions inherited from MemoryHook
 MemoryHook (const MemoryHook &copy)
 
virtual void alloc_fail (size_t attempted_size)
 This callback method is called whenever a low-level call to call_malloc() has returned NULL, indicating failure. More...
 
void dec_heap (size_t size)
 Called by our alternative malloc implementations (dlmalloc and ptmalloc2) to indicate they have returned size bytes to the system from the heap. More...
 
DeletedBufferChainget_deleted_chain (size_t buffer_size)
 Returns a pointer to a global DeletedBufferChain object suitable for allocating arrays of the indicated size. More...
 
size_t get_page_size () const
 Returns the operating system page size. More...
 
bool heap_trim (size_t pad)
 Attempts to release memory back to the system, if possible. More...
 
void inc_heap (size_t size)
 Called by our alternative malloc implementations (dlmalloc and ptmalloc2) to indicate they have requested size bytes from the system for the heap. More...
 
virtual void * mmap_alloc (size_t size, bool allow_exec)
 Allocates a raw page or pages of memory directly from the OS. More...
 
virtual void mmap_free (void *ptr, size_t size)
 Frees a block of memory previously allocated via mmap_alloc(). More...
 
size_t round_up_to_page_size (size_t size) const
 Rounds the indicated size request up to the next larger multiple of page_size, to qualify it for a call to mmap_alloc(). 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.

Definition at line 35 of file memoryUsage.h.

Member Function Documentation

◆ freeze()

void MemoryUsage::freeze ( )
inlinestatic

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

Definition at line 337 of file memoryUsage.I.

◆ get_num_pointers()

int MemoryUsage::get_num_pointers ( )
inlinestatic

Returns the number of pointers currently active.

Definition at line 266 of file memoryUsage.I.

◆ get_pointers()

void MemoryUsage::get_pointers ( MemoryUsagePointers result)
inlinestatic

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

Definition at line 279 of file memoryUsage.I.

◆ get_pointers_of_age()

void MemoryUsage::get_pointers_of_age ( MemoryUsagePointers result,
double  from,
double  to 
)
inlinestatic

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

Definition at line 301 of file memoryUsage.I.

◆ get_pointers_of_type()

void MemoryUsage::get_pointers_of_type ( MemoryUsagePointers result,
TypeHandle  type 
)
inlinestatic

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

Definition at line 290 of file memoryUsage.I.

◆ get_pointers_with_zero_count()

void MemoryUsage::get_pointers_with_zero_count ( MemoryUsagePointers result)
inlinestatic

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.

Definition at line 324 of file memoryUsage.I.

◆ get_track_memory_usage()

bool MemoryUsage::get_track_memory_usage ( )
inlinestatic

Returns true if the user has Configured the variable 'track-memory-usage' to true, indicating that this class will be in effect.

If this returns false, the user has indicated not to do any of this.

Definition at line 20 of file memoryUsage.I.

◆ record_pointer() [1/2]

void MemoryUsage::record_pointer ( ReferenceCount ptr)
inlinestatic

Indicates that the given pointer has been recently allocated.

Definition at line 32 of file memoryUsage.I.

Referenced by CullableObject::CullableObject().

◆ record_pointer() [2/2]

void MemoryUsage::record_pointer ( void *  ptr,
TypeHandle  type 
)
inlinestatic

Indicates that the given pointer has been recently allocated.

Definition at line 42 of file memoryUsage.I.

◆ remove_pointer()

void MemoryUsage::remove_pointer ( ReferenceCount ptr)
inlinestatic

Indicates that the given pointer has been recently freed.

Definition at line 90 of file memoryUsage.I.

◆ show_current_ages()

void MemoryUsage::show_current_ages ( )
inlinestatic

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

Definition at line 368 of file memoryUsage.I.

◆ show_current_types()

void MemoryUsage::show_current_types ( )
inlinestatic

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

Definition at line 347 of file memoryUsage.I.

◆ show_trend_ages()

void MemoryUsage::show_trend_ages ( )
inlinestatic

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

Definition at line 379 of file memoryUsage.I.

◆ show_trend_types()

void MemoryUsage::show_trend_types ( )
inlinestatic

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

Definition at line 358 of file memoryUsage.I.

◆ update_type() [1/3]

void MemoryUsage::update_type ( ReferenceCount ptr,
TypeHandle  type 
)
inlinestatic

Associates the indicated type with the given pointer.

This should be called by functions (e.g. the constructor) that know more specifically what type of thing we've got; otherwise, the MemoryUsage database will know only that it's a "ReferenceCount".

Definition at line 55 of file memoryUsage.I.

Referenced by AnimControl::AnimControl(), GraphicsDevice::GraphicsDevice(), and ParasiteBuffer::ParasiteBuffer().

◆ update_type() [2/3]

void MemoryUsage::update_type ( ReferenceCount ptr,
TypedObject typed_ptr 
)
inlinestatic

Associates the indicated type with the given pointer.

This flavor of update_type() also passes in the pointer as a TypedObject, and useful for objects that are, in fact, TypedObjects. Once the MemoryUsage database has the pointer as a TypedObject it doesn't need any more help.

Definition at line 68 of file memoryUsage.I.

◆ update_type() [3/3]

void MemoryUsage::update_type ( void *  ptr,
TypeHandle  type 
)
inlinestatic

Associates the indicated type with the given pointer.

This should be called by functions (e.g. the constructor) that know more specifically what type of thing we've got.

Definition at line 80 of file memoryUsage.I.

Member Data Documentation

◆ get_current_cpp_size

size_t MemoryUsage::get_current_cpp_size
inline

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

Definition at line 95 of file memoryUsage.h.

◆ get_external_size

size_t MemoryUsage::get_external_size
inline

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.

Definition at line 102 of file memoryUsage.h.

◆ get_panda_heap_array_size

size_t MemoryUsage::get_panda_heap_array_size
inline

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

Definition at line 99 of file memoryUsage.h.

◆ get_panda_heap_overhead

size_t MemoryUsage::get_panda_heap_overhead
inline

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.

Definition at line 100 of file memoryUsage.h.

◆ get_panda_heap_single_size

size_t MemoryUsage::get_panda_heap_single_size
inline

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

Definition at line 98 of file memoryUsage.h.

◆ get_panda_mmap_size

size_t MemoryUsage::get_panda_mmap_size
inline

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

Definition at line 101 of file memoryUsage.h.

◆ get_total_cpp_size

size_t MemoryUsage::get_total_cpp_size
inline

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

Definition at line 96 of file memoryUsage.h.

◆ get_total_size

size_t MemoryUsage::get_total_size
inline

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

Definition at line 103 of file memoryUsage.h.

◆ is_counting

bool MemoryUsage::is_counting
inline

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.

Definition at line 94 of file memoryUsage.h.

◆ is_tracking

bool MemoryUsage::is_tracking
inline

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

track-memory-usage is configured #t).

Definition at line 93 of file memoryUsage.h.


The documentation for this class was generated from the following files: