-
-/*
- * The following functions below implement printing / dumping of statistical
- * information.
- */
-static void stat_dump_mem_contents(stat_mem_block_t *memory, uint16_t cols) {
- uint32_t i, j;
- for (i = 0; i < memory->size + ((memory->size % cols) ? (cols - memory->size % cols) : 0); i++) {
- if (i % cols == 0) con_out(" 0x%06X: ", i);
- if (i < memory->size) con_out("%02X " , 0xFF & ((unsigned char*)(memory + 1))[i]);
- else con_out(" ");
-
- if ((uint16_t)(i % cols) == (cols - 1)) {
- for (j = i - (cols - 1); j <= i; j++) {
- con_out("%c",
- (j >= memory->size)
- ? ' '
- : (isprint(((unsigned char*)(memory + 1))[j]))
- ? 0xFF & ((unsigned char*)(memory + 1)) [j]
- : '.'
- );
- }
- con_out("\n");
- }
- }
-}
-
-static void stat_dump_mem_leaks() {
- stat_mem_block_t *info;
- for (info = stat_mem_block_root; info; info = info->next) {
- con_out("lost: %u (bytes) at %s:%u\n",
- info->size,
- info->file,
- info->line
- );
-
- stat_dump_mem_contents(info, OPTS_OPTION_U16(OPTION_MEMDUMPCOLS));
- }
-}
-
-static void stat_dump_mem_info() {
- con_out("Memory information:\n\
- Total allocations: %llu\n\
- Total deallocations: %llu\n\
- Total allocated: %f (MB)\n\
- Total deallocated: %f (MB)\n\
- Total peak memory: %f (MB)\n\
- Total leaked memory: %f (MB) in %llu allocations\n",
- stat_mem_allocated_total,
- stat_mem_deallocated_total,
- (float)(stat_mem_allocated) / 1048576.0f,
- (float)(stat_mem_deallocated) / 1048576.0f,
- (float)(stat_mem_peak) / 1048576.0f,
- (float)(stat_mem_allocated - stat_mem_deallocated) / 1048576.0f,
- stat_mem_allocated_total - stat_mem_deallocated_total
- );
-}
-
-static void stat_dump_stats_table(stat_size_table_t table, const char *string, uint64_t *size) {
- size_t i,j;
-
- if (!table)
- return;
-
- for (i = 0, j = 0; i < ST_SIZE; i++) {
- stat_size_entry_t *entry;
-
- if (!(entry = table[i]))
- continue;
-
- con_out(string, (unsigned)j, (unsigned)entry->key, (unsigned)entry->value);
- j++;
-
- if (size)
- *size += entry->key * entry->value;
- }
-}
-
-void stat_info() {
- if (OPTS_OPTION_BOOL(OPTION_DEBUG))
- stat_dump_mem_leaks();
-
- if (OPTS_OPTION_BOOL(OPTION_DEBUG) ||
- OPTS_OPTION_BOOL(OPTION_MEMCHK))
- stat_dump_mem_info();
-
- if (OPTS_OPTION_BOOL(OPTION_MEMCHK) ||
- OPTS_OPTION_BOOL(OPTION_STATISTICS)) {
- uint64_t mem = 0;
-
- con_out("\nAdditional Statistics:\n\
- Total vectors allocated: %llu\n\
- Total string duplicates: %llu\n\
- Total hashtables allocated: %llu\n\
- Total unique vector sizes: %llu\n",
- stat_used_vectors,
- stat_used_strdups,
- stat_used_hashtables,
- stat_type_vectors
- );
-
- stat_dump_stats_table (
- stat_size_vectors,
- " %2u| # of %4u byte vectors: %u\n",
- &mem
- );
-
- con_out (
- " Total unique hashtable sizes: %llu\n",
- stat_type_hashtables
- );
-
- stat_dump_stats_table (
- stat_size_hashtables,
- " %2u| # of %4u element hashtables: %u\n",
- NULL
- );
-
- con_out (
- " Total vector memory: %f (MB)\n",
- (float)(mem) / 1048576.0f
- );
- }
-
- if (stat_size_vectors)
- stat_size_del(stat_size_vectors);
- if (stat_size_hashtables)
- stat_size_del(stat_size_hashtables);
-}
-#undef ST_SIZE