21#ifndef GCC_MEM_STATS_H
22#define GCC_MEM_STATS_H
25template<
typename Key,
typename Value,
30#define LOCATION_LINE_EXTRA_SPACE 30
31#define LOCATION_LINE_WIDTH 48
44 const char *filename =
NULL,
int line = 0,
47 (origin),
m_ggc (ggc) {}
86 while ((s2 = strstr (s1,
"gcc/")))
98 char *s = XNEWVEC (
char, l);
134 mem_usage (
size_t allocated,
size_t times,
size_t peak,
size_t instances = 0):
191 compare (
const void *first,
const void *second)
193 typedef std::pair<mem_location *, mem_usage *> mem_pair_t;
195 const mem_pair_t f = *(
const mem_pair_t *)first;
196 const mem_pair_t s = *(
const mem_pair_t *)second;
198 if (*f.second == *s.second)
201 return *f.second < *s.second ? 1 : -1;
208 char *location_string = loc->
to_string ();
210 fprintf (stderr,
"%-48s " PRsa (9)
":%5.1f%%"
217 free (location_string);
224 fprintf (stderr,
"%s" PRsa (53)
PRsa (26)
"\n",
"Total",
232 return denominator == 0 ? 0.0f : nominator * 100.0 / denominator;
241 fputc (
'\n', stderr);
248 fprintf (stderr,
"%-48s %11s%16s%10s%17s\n", name,
"Leak",
"Peak",
291 return hstate.
end ();
330 bool ggc,
const char *name,
int line,
346 bool remove_from_map =
false);
377 int line,
const char *
function,
const void *ptr);
395 return m_reverse_map->
get (ptr);
404 return m_reverse_map->get (ptr) ? (*m_reverse_map->get (ptr)).usage :
NULL;
417 T **
slot = m_map->get (location);
422 usage->m_instances++;
427 m_map->put (location,
usage);
430 if (!m_reverse_map->get (ptr))
446 const char *filename,
451 return register_descriptor (ptr, l);
462 mem_usage_pair <T> *
slot = m_reverse_map->get (ptr);
469 T *
usage = (*slot).usage;
470 usage->register_overhead (size);
486 m_reverse_object_map->put (ptr, std::pair<T *, size_t> (
usage, size));
496 const char *filename,
501 T *
usage = register_descriptor (ptr, origin, filename, line,
function);
502 usage->register_overhead (size);
512 bool remove_from_map)
522 T *
usage = (*slot).usage;
523 usage->release_overhead (size);
526 m_reverse_map->remove (ptr);
537 std::pair <T *, size_t> *entry = m_reverse_object_map->get (ptr);
538 entry->first->release_overhead (entry->second);
539 m_reverse_object_map->remove (ptr);
550 m_reverse_map->remove (ptr);
559 m_map =
new mem_map_t (13,
false,
false,
false);
578 delete m_reverse_map;
579 delete m_reverse_object_map;
600 if ((*it).first->m_origin == origin)
601 list[
i++] = std::pair<mem_location*, T*> (*it);
603 qsort (list,
i, element_size, T::compare);
616 mem_list_t *list = get_list (origin, &length);
619 for (
unsigned i = 0;
i < length;
i++)
620 sum = sum + *list[
i].second;
636 fprintf (stderr,
"\n");
638 mem_list_t *list = get_list (origin, &length);
639 T total = get_sum (origin);
641 T::print_dash_line ();
643 T::print_dash_line ();
644 for (
int i = length - 1;
i >= 0;
i--)
645 list[
i].second->dump (list[
i].first, total);
646 T::print_dash_line ();
649 T::print_dash_line ();
650 total.dump_footer ();
651 T::print_dash_line ();
655 fprintf (stderr,
"\n");
Definition hash-map.h:255
Value * get(const Key &k)
Definition hash-map.h:189
void add_int(unsigned v)
Definition inchash.h:55
hashval_t end() const
Definition inchash.h:49
void add_ptr(const void *ptr)
Definition inchash.h:94
Definition mem-stats.h:278
hash_map< const void *, std::pair< T *, size_t > > reverse_object_map_t
Definition mem-stats.h:306
T get_sum(mem_alloc_origin origin)
Definition mem-stats.h:613
void dump(mem_alloc_origin origin)
Definition mem-stats.h:632
hash_map< const void *, mem_usage_pair< T > > reverse_mem_map_t
Definition mem-stats.h:305
void register_object_overhead(T *usage, size_t size, const void *ptr)
Definition mem-stats.h:481
T * register_descriptor(const void *ptr, mem_location *location)
Definition mem-stats.h:412
~mem_alloc_description()
Definition mem-stats.h:568
void unregister_descriptor(void *ptr)
Definition mem-stats.h:548
reverse_object_map_t * m_reverse_object_map
Definition mem-stats.h:371
mem_location m_location
Definition mem-stats.h:380
reverse_mem_map_t * m_reverse_map
Definition mem-stats.h:386
T * register_overhead(size_t size, mem_alloc_origin origin, const char *name, int line, const char *function, const void *ptr)
Definition mem-stats.h:494
hash_map< mem_location_hash, T * > mem_map_t
Definition mem-stats.h:304
T * register_instance_overhead(size_t size, const void *ptr)
Definition mem-stats.h:459
void release_object_overhead(void *ptr)
Definition mem-stats.h:535
bool contains_descriptor_for_instance(const void *ptr)
Definition mem-stats.h:393
T * release_instance_overhead(void *ptr, size_t size, bool remove_from_map=false)
Definition mem-stats.h:511
mem_map_t * m_map
Definition mem-stats.h:383
std::pair< mem_location *, T * > mem_list_t
Definition mem-stats.h:307
mem_alloc_description()
Definition mem-stats.h:557
mem_list_t * get_list(mem_alloc_origin origin, unsigned *length)
Definition mem-stats.h:590
T * get_descriptor_for_instance(const void *ptr)
Definition mem-stats.h:402
Definition mem-stats.h:35
char * to_string()
Definition mem-stats.h:93
const char * m_filename
Definition mem-stats.h:115
int equal(const mem_location &other)
Definition mem-stats.h:73
int m_line
Definition mem-stats.h:119
static const char * get_origin_name(mem_alloc_origin origin)
Definition mem-stats.h:109
mem_location()
Definition mem-stats.h:39
mem_location(mem_location &other)
Definition mem-stats.h:51
hashval_t hash()
Definition mem-stats.h:60
mem_alloc_origin m_origin
Definition mem-stats.h:121
bool m_ggc
Definition mem-stats.h:123
const char * m_function
Definition mem-stats.h:117
const char * get_trimmed_filename()
Definition mem-stats.h:81
mem_location(mem_alloc_origin origin, bool ggc, const char *filename=NULL, int line=0, const char *function=NULL)
Definition mem-stats.h:43
Definition mem-stats.h:266
size_t allocated
Definition mem-stats.h:272
T * usage
Definition mem-stats.h:271
mem_usage_pair(T *usage_, size_t allocated_)
Definition mem-stats.h:268
Definition mem-stats.h:128
mem_usage(size_t allocated, size_t times, size_t peak, size_t instances=0)
Definition mem-stats.h:134
static void dump_header(const char *name)
Definition mem-stats.h:246
bool operator==(const mem_usage &second) const
Definition mem-stats.h:170
static void print_dash_line(size_t count=140)
Definition mem-stats.h:237
void dump_footer() const
Definition mem-stats.h:222
void register_overhead(size_t size)
Definition mem-stats.h:140
static int compare(const void *first, const void *second)
Definition mem-stats.h:191
mem_usage()
Definition mem-stats.h:131
size_t m_allocated
Definition mem-stats.h:253
size_t m_peak
Definition mem-stats.h:257
mem_usage operator+(const mem_usage &second)
Definition mem-stats.h:160
bool operator<(const mem_usage &second) const
Definition mem-stats.h:179
size_t m_instances
Definition mem-stats.h:259
void dump(mem_location *loc, const mem_usage &total) const
Definition mem-stats.h:206
size_t m_times
Definition mem-stats.h:255
void release_overhead(size_t size)
Definition mem-stats.h:151
static float get_percent(size_t nominator, size_t denominator)
Definition mem-stats.h:230
Definition lra-spills.cc:101
static unsigned int count[debug_counter_number_of_counters]
Definition dbgcnt.cc:50
static void usage(void)
Definition gencheck.cc:39
static struct token T
Definition gengtype-parse.cc:45
mem_alloc_origin
Definition mem-stats-traits.h:26
static const char * mem_alloc_origin_names[]
Definition mem-stats-traits.h:38
#define LOCATION_LINE_EXTRA_SPACE
Definition mem-stats.h:30
#define LOCATION_LINE_WIDTH
Definition mem-stats.h:31
i
Definition poly-int.h:776
Definition function.h:249
Definition mem-stats.h:281
static hashval_t hash(value_type l)
Definition mem-stats.h:283
static bool equal(value_type l1, value_type l2)
Definition mem-stats.h:295
Definition hash-traits.h:303
Definition hash-map-traits.h:33
#define NULL
Definition system.h:50
#define gcc_assert(EXPR)
Definition system.h:821
#define qsort(...)
Definition system.h:1264
#define SIZE_AMOUNT(size)
Definition system.h:1290
#define MIN(X, Y)
Definition system.h:392
#define PRsa(n)
Definition system.h:1294