35class EXPCL_PANDA_EXPRESS MemoryUsage :
public MemoryHook {
58#if (defined(WIN32_VC) || defined(WIN64_VC)) && defined(_DEBUG)
59 static int win32_malloc_hook(
int alloc_type,
void *ptr,
60 size_t size,
int block_use,
long request,
61 const unsigned char *filename,
int line);
82 double from,
double to);
85 INLINE
static void freeze();
106 virtual void overflow_heap_size();
109 MemoryUsage(
const MemoryHook ©);
110 INLINE
static MemoryUsage *get_global_ptr();
112 static void init_memory_usage();
115 void ns_record_pointer(
void *ptr,
TypeHandle type);
116 void ns_update_type(
void *ptr,
TypeHandle type);
117 void ns_update_type(
void *ptr,
TypedObject *typed_ptr);
120 void ns_record_void_pointer(
void *ptr,
size_t size);
121 void ns_remove_void_pointer(
void *ptr);
123 size_t ns_get_total_size();
124 int ns_get_num_pointers();
129 double from,
double to);
133 void ns_show_current_types();
134 void ns_show_trend_types();
135 void ns_show_current_ages();
136 void ns_show_trend_ages();
138#ifdef DO_MEMORY_USAGE
139 void consolidate_void_ptr(MemoryInfo *info);
140 void refresh_info_set();
143 static MemoryUsage *_global_ptr;
159 typedef std::map<void *, MemoryInfo *> Table;
164 typedef std::set<MemoryInfo *> InfoSet;
166 bool _info_set_dirty;
170 size_t _current_cpp_size;
171 size_t _total_cpp_size;
174 class TypeHistogram {
176 void add_info(
TypeHandle type, MemoryInfo *info);
182 typedef std::map<TypeHandle, MemoryUsagePointerCounts> Counts;
185 TypeHistogram _trend_types;
190 void add_info(
double age, MemoryInfo *info);
195 int choose_bucket(
double age)
const;
197 enum { num_buckets = 5 };
198 MemoryUsagePointerCounts _counts[num_buckets];
199 static double _cutoff[num_buckets];
201 AgeHistogram _trend_ages;
204 bool _track_memory_usage;
205 bool _startup_track_memory_usage;
206 bool _count_memory_usage;
207 bool _report_memory_usage;
208 double _report_memory_interval;
209 double _last_report_time;
211 static bool _recursion_protect;
virtual void * heap_alloc_array(size_t size)
Allocates a block of memory from the heap, similar to malloc().
virtual void heap_free_array(void *ptr)
Releases a block of memory previously allocated via heap_alloc_array.
virtual void * heap_alloc_single(size_t size)
Allocates a block of memory from the heap, similar to malloc().
virtual void mark_pointer(void *ptr, size_t orig_size, ReferenceCount *ref_ptr)
This special method exists only to provide a callback hook into MemoryUsage.
virtual void heap_free_single(void *ptr)
Releases a block of memory previously allocated via heap_alloc_single.
virtual void * heap_realloc_array(void *ptr, size_t size)
Resizes a block of memory previously returned from heap_alloc_array.
This is a list of pointers returned by a MemoryUsage object in response to some query.
static void show_current_types()
Shows the breakdown of types of all of the active pointers.
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 r...
static void get_pointers(MemoryUsagePointers &result)
Fills the indicated MemoryUsagePointers with the set of all pointers currently active.
get_current_cpp_size
Returns the total number of bytes of allocated memory consumed by C++ objects, not including the memo...
static void show_current_ages()
Shows the breakdown of ages of all of the active pointers.
get_external_size
Returns the total number of bytes of allocated memory in the heap that Panda didn't seem to be respon...
get_panda_mmap_size
Returns the total number of bytes allocated from the virtual memory pool from code within Panda.
static void show_trend_types()
Shows the breakdown of types of all of the pointers allocated and freed since the last call to freeze...
get_panda_heap_array_size
Returns the total number of bytes allocated from the heap from code within Panda, for arrays.
static void record_pointer(ReferenceCount *ptr)
Indicates that the given pointer has been recently allocated.
static void update_type(ReferenceCount *ptr, TypeHandle type)
Associates the indicated type with the given pointer.
get_total_size
Returns the total size of allocated memory consumed by the process, as nearly as can be determined.
static void freeze()
'Freezes' all pointers currently stored so that they are no longer reported; only newly allocate poin...
get_panda_heap_single_size
Returns the total number of bytes allocated from the heap from code within Panda, for individual obje...
static void get_pointers_with_zero_count(MemoryUsagePointers &result)
Fills the indicated MemoryUsagePointers with the set of all currently active pointers (that is,...
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 ...
get_total_cpp_size
Returns the total number of bytes of allocated memory consumed by C++ objects, including the memory p...
is_counting
Returns true if the MemoryUsage object is currently at least counting memory (e.g.
static int get_num_pointers()
Returns the number of pointers currently active.
static bool get_track_memory_usage()
Returns true if the user has Configured the variable 'track-memory-usage' to true,...
static void remove_pointer(ReferenceCount *ptr)
Indicates that the given pointer has been recently freed.
get_panda_heap_overhead
Returns the extra bytes allocated from the system that are not immediately used for holding allocated...
static void show_trend_ages()
Shows the breakdown of ages of all of the pointers allocated and freed since the last call to freeze(...
is_tracking
Returns true if the MemoryUsage object is currently tracking memory (e.g.
A base class for all things that want to be reference-counted.
TypeHandle is the identifier used to differentiate C++ class types.
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.