18 #include "pandabase.h" 20 #ifdef DO_MEMORY_USAGE 22 #include "typedObject.h" 23 #include "memoryInfo.h" 24 #include "memoryUsagePointerCounts.h" 26 #include "memoryHook.h" 29 class MemoryUsagePointers;
41 class EXPCL_PANDAEXPRESS MemoryUsage :
public MemoryHook {
43 INLINE
static bool get_track_memory_usage();
60 #if (defined(WIN32_VC) || defined(WIN64_VC)) && defined(_DEBUG) 61 static int win32_malloc_hook(
int alloc_type,
void *ptr,
62 size_t size,
int block_use,
long request,
63 const unsigned char *filename,
int line);
67 INLINE
static bool is_tracking();
68 INLINE
static bool is_counting();
69 INLINE
static size_t get_current_cpp_size();
70 INLINE
static size_t get_total_cpp_size();
72 INLINE
static size_t get_panda_heap_single_size();
73 INLINE
static size_t get_panda_heap_array_size();
74 INLINE
static size_t get_panda_heap_overhead();
75 INLINE
static size_t get_panda_mmap_size();
76 INLINE
static size_t get_external_size();
77 INLINE
static size_t get_total_size();
79 INLINE
static int get_num_pointers();
80 INLINE
static void get_pointers(MemoryUsagePointers &result);
81 INLINE
static void get_pointers_of_type(MemoryUsagePointers &result,
83 INLINE
static void get_pointers_of_age(MemoryUsagePointers &result,
84 double from,
double to);
85 INLINE
static void get_pointers_with_zero_count(MemoryUsagePointers &result);
87 INLINE
static void freeze();
89 INLINE
static void show_current_types();
90 INLINE
static void show_trend_types();
91 INLINE
static void show_current_ages();
92 INLINE
static void show_trend_ages();
95 virtual void overflow_heap_size();
99 INLINE
static MemoryUsage *get_global_ptr();
106 void ns_record_void_pointer(
void *ptr,
size_t size);
107 void ns_remove_void_pointer(
void *ptr);
109 size_t ns_get_total_size();
110 int ns_get_num_pointers();
111 void ns_get_pointers(MemoryUsagePointers &result);
112 void ns_get_pointers_of_type(MemoryUsagePointers &result,
114 void ns_get_pointers_of_age(MemoryUsagePointers &result,
115 double from,
double to);
116 void ns_get_pointers_with_zero_count(MemoryUsagePointers &result);
119 void ns_show_current_types();
120 void ns_show_trend_types();
121 void ns_show_current_ages();
122 void ns_show_trend_ages();
124 void consolidate_void_ptr(MemoryInfo *info);
125 void refresh_info_set();
127 static MemoryUsage *_global_ptr;
142 typedef map<void *, MemoryInfo *> Table;
147 typedef set<MemoryInfo *> InfoSet;
149 bool _info_set_dirty;
153 size_t _current_cpp_size;
154 size_t _total_cpp_size;
157 class TypeHistogram {
159 void add_info(
TypeHandle type, MemoryInfo *info);
165 typedef map<TypeHandle, MemoryUsagePointerCounts> Counts;
168 TypeHistogram _trend_types;
173 void add_info(
double age, MemoryInfo *info);
178 int choose_bucket(
double age)
const;
180 enum { num_buckets = 5 };
181 MemoryUsagePointerCounts _counts[num_buckets];
182 static double _cutoff[num_buckets];
184 AgeHistogram _trend_ages;
187 bool _track_memory_usage;
188 bool _startup_track_memory_usage;
189 bool _count_memory_usage;
190 bool _report_memory_usage;
191 double _report_memory_interval;
192 double _last_report_time;
194 static bool _recursion_protect;
197 #include "memoryUsage.I" 199 #endif // DO_MEMORY_USAGE 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.
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
virtual void heap_free_single(void *ptr)
Releases a block of memory previously allocated via heap_alloc_single.
A base class for all things that want to be reference-counted.
virtual void * heap_alloc_array(size_t size)
Allocates a block of memory from the heap, similar to malloc().
This class provides a wrapper around the various possible malloc schemes Panda might employ...
virtual void * heap_realloc_array(void *ptr, size_t size)
Resizes a block of memory previously returned from heap_alloc_array.
TypeHandle is the identifier used to differentiate C++ class types.