]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - stat.c
Smaller memory footprint, 4/8 bytes vs 12/24 for individual token lex_ctx's. Use...
[xonotic/gmqcc.git] / stat.c
diff --git a/stat.c b/stat.c
index 137b37010eeb68d92caedc1e1b818b934fbf44c9..869a11fcdcc9107a7dc11b4ed4508c93e34525b3 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -24,7 +24,6 @@
 
 #include <string.h>
 #include <stdlib.h>
-#include <ctype.h>
 
 #include "gmqcc.h"
 
@@ -56,6 +55,7 @@ static uint64_t          stat_mem_allocated_total   = 0;
 static uint64_t          stat_mem_deallocated_total = 0;
 static uint64_t          stat_mem_high              = 0;
 static uint64_t          stat_mem_peak              = 0;
+static uint64_t          stat_mem_strdups           = 0;
 static uint64_t          stat_used_strdups          = 0;
 static uint64_t          stat_used_vectors          = 0;
 static uint64_t          stat_used_hashtables       = 0;
@@ -72,8 +72,8 @@ static stat_mem_block_t *stat_mem_block_root        = NULL;
  */
 static stat_size_table_t stat_size_new(void) {
     return (stat_size_table_t)memset(
-        mem_a(sizeof(stat_size_entry_t) * ST_SIZE),
-        0, ST_SIZE * sizeof(stat_size_entry_t)
+        mem_a(sizeof(stat_size_entry_t*) * ST_SIZE),
+        0, ST_SIZE * sizeof(stat_size_entry_t*)
     );
 }
 
@@ -224,6 +224,7 @@ char *stat_mem_strdup(const char *src, size_t line, const char *file, bool empty
     }
 
     stat_used_strdups ++;
+    stat_mem_strdups  += len;
     return ptr;
 }
 
@@ -290,7 +291,7 @@ typedef struct hash_node_t {
  * }
  * 
  * The two u32s that form the key are the same value x (pulled from data)
- * this premix stage will be perform the same results for both. Unrolled
+ * this premix stage will perform the same results for both values. Unrolled
  * this produces just:
  *  x *= m;
  *  x ^= x >> r;
@@ -301,7 +302,7 @@ typedef struct hash_node_t {
  *  h *= m;
  *  h ^= x;
  * 
- * This appears to be fine, except what happens when m == 1, well x
+ * This appears to be fine, except what happens when m == 1? well x
  * cancels out entierly, leaving just:
  *  x ^= x >> r;
  *  h ^= x;
@@ -613,7 +614,7 @@ static void stat_dump_mem_contents(stat_mem_block_t *memory, uint16_t cols) {
                 con_out("%c",
                     (j >= memory->size)
                         ? ' '
-                        : (isprint(((unsigned char*)(memory + 1))[j]))
+                        : (util_isprint(((unsigned char*)(memory + 1))[j]))
                             ? 0xFF & ((unsigned char*)(memory + 1)) [j]
                             : '.'
                 );
@@ -680,12 +681,14 @@ void stat_info() {
         uint64_t mem = 0;
 
         con_out("Memory Statistics:\n\
-    Total vectors allocated:    %llu\n\
-    Total string duplicates:    %llu\n\
-    Total hashtables allocated: %llu\n\
-    Total unique vector sizes:  %llu\n",
+    Total vectors allocated:       %llu\n\
+    Total string duplicates:       %llu\n\
+    Total string duplicate memory: %f (MB)\n\
+    Total hashtables allocated:    %llu\n\
+    Total unique vector sizes:     %llu\n",
             stat_used_vectors,
             stat_used_strdups,
+            (float)(stat_mem_strdups) / 1048576.0f,
             stat_used_hashtables,
             stat_type_vectors
         );