Index: trunk/src/kmk/Makefile.kmk
===================================================================
--- trunk/src/kmk/Makefile.kmk	(revision 1924)
+++ trunk/src/kmk/Makefile.kmk	(revision 1925)
@@ -176,7 +176,9 @@
 kmk_DEFS.amd64 = CONFIG_WITH_OPTIMIZATION_HACKS
 kmk_DEFS.win = CONFIG_NEW_WIN32_CTRL_EVENT
+kmk_DEFS.debug = CONFIG_WITH_MAKE_STATS
 
 kmk_SOURCES = \
 	main.c \
+	kbuild.c \
 	read.c \
 	expreval.c \
@@ -202,6 +204,5 @@
 	version.c \
 	vpath.c \
-	remote-stub.c \
-	kbuild.c
+	remote-stub.c
 
 #
Index: trunk/src/kmk/hash.c
===================================================================
--- trunk/src/kmk/hash.c	(revision 1924)
+++ trunk/src/kmk/hash.c	(revision 1925)
@@ -488,8 +488,10 @@
 	   100.0 * (double) ht->ht_fill / (double) ht->ht_size);
   fprintf (out_FILE, _("Rehash=%d, "), ht->ht_rehashes);
+  MAKE_STATS(
   fprintf (out_FILE, _("Collisions=%ld/%ld=%.0f%%"), ht->ht_collisions, ht->ht_lookups,
 	   (ht->ht_lookups
 	    ? (100.0 * (double) ht->ht_collisions / (double) ht->ht_lookups)
 	    : 0));
+  );
 }
 
Index: trunk/src/kmk/make.h
===================================================================
--- trunk/src/kmk/make.h	(revision 1924)
+++ trunk/src/kmk/make.h	(revision 1925)
@@ -196,4 +196,42 @@
 #endif
 
+#ifdef CONFIG_WITH_MAKE_STATS
+extern long make_stats_allocations;
+extern unsigned long make_stats_allocated;
+extern unsigned long make_stats_allocated_sum;
+extern unsigned long make_stats_ht_lookups;
+extern unsigned long make_stats_ht_collisions;
+
+# ifdef __APPLE__
+#  include <malloc/malloc.h>
+#  define SIZE_OF_HEAP_BLOCK(ptr)   malloc_size(ptr)
+
+# elif defined(__linux__) /* glibc */
+#  include <malloc.h>
+#  define SIZE_OF_HEAP_BLOCK(ptr)   malloc_usable_size(ptr)
+
+# elif defined(_MSC_VER) || defined(__OS2__)
+#  define SIZE_OF_HEAP_BLOCK(ptr)   _msize(ptr)
+
+# else
+#  include <stdlib.h>
+#  define SIZE_OF_HEAP_BLOCK(ptr)   0
+#endif
+
+# if defined(CONFIG_WITH_MAKE_STATS) && !defined(ELECTRIC_HEAP)
+#  define free xfree
+extern void xfree (void *);
+# endif
+
+# define MAKE_STATS_3(expr) do { expr; } while (0)
+# define MAKE_STATS_2(expr) do { expr; } while (0)
+# define MAKE_STATS(expr)   do { expr; } while (0)
+#else
+# define MAKE_STATS_3(expr) do { } while (0)
+# define MAKE_STATS_2(expr) do { } while (0)
+# define MAKE_STATS(expr)   do { } while (0)
+#endif
+
+
 #ifndef CHAR_BIT
 # define CHAR_BIT 8
@@ -514,6 +552,7 @@
   struct alloccache_free_ent *free_head;
   unsigned int size;
-  unsigned int alloc_count;
   unsigned int total_count;
+  unsigned long alloc_count;
+  unsigned long free_count;
   const char *name;
   struct alloccache *next;
@@ -545,5 +584,5 @@
   else
     f = alloccache_alloc_grow (cache);
-  cache->alloc_count++;
+  MAKE_STATS(cache->alloc_count++;);
   return f;
 }
@@ -573,5 +612,5 @@
   f->next = cache->free_head;
   cache->free_head = f;
-  cache->alloc_count--;
+  MAKE_STATS(cache->free_count++;);
 }
 
@@ -855,41 +894,4 @@
 #endif /* __EMX__ (bird) */
 
-#ifdef CONFIG_WITH_MAKE_STATS
-extern long make_stats_allocations;
-extern unsigned long make_stats_allocated;
-extern unsigned long make_stats_allocated_sum;
-extern unsigned long make_stats_ht_lookups;
-extern unsigned long make_stats_ht_collisions;
-
-# ifdef __APPLE__
-#  include <malloc/malloc.h>
-#  define SIZE_OF_HEAP_BLOCK(ptr)   malloc_size(ptr)
-
-# elif defined(__linux__) /* glibc */
-#  include <malloc.h>
-#  define SIZE_OF_HEAP_BLOCK(ptr)   malloc_usable_size(ptr)
-
-# elif defined(_MSC_VER) || defined(__OS2__)
-#  define SIZE_OF_HEAP_BLOCK(ptr)   _msize(ptr)
-
-# else
-#  include <stdlib.h>
-#  define SIZE_OF_HEAP_BLOCK(ptr)   0
-#endif
-
-# if defined(CONFIG_WITH_MAKE_STATS) && !defined(ELECTRIC_HEAP)
-#  define free xfree
-extern void xfree (void *);
-# endif
-
-# define MAKE_STATS_3(expr) do { expr; } while (0)
-# define MAKE_STATS_2(expr) do { expr; } while (0)
-# define MAKE_STATS(expr)   do { expr; } while (0)
-#else
-# define MAKE_STATS_3(expr) do { } while (0)
-# define MAKE_STATS_2(expr) do { } while (0)
-# define MAKE_STATS(expr)   do { } while (0)
-#endif
-
 #ifdef CONFIG_WITH_IF_CONDITIONALS
 extern int expr_eval_if_conditionals(char *line, const struct floc *flocp);
Index: trunk/src/kmk/misc.c
===================================================================
--- trunk/src/kmk/misc.c	(revision 1924)
+++ trunk/src/kmk/misc.c	(revision 1925)
@@ -1224,6 +1224,7 @@
   cache->free_head   = NULL;
   cache->size        = act_size;
+  cache->total_count = 0;
   cache->alloc_count = 0;
-  cache->total_count = 0;
+  cache->free_count  = 0;
   cache->name        = name;
   cache->grow_arg    = grow_arg;
@@ -1257,7 +1258,9 @@
   if (eat->free_head)
     {
+     unsigned int eat_in_use = eat->alloc_count - eat->free_count;
+     unsigned int dst_in_use = cache->alloc_count - cache->free_count;
      if (!cache->free_head)
        cache->free_head = eat->free_head;
-     else if (eat->total_count - eat->alloc_count < cache->total_count - cache->alloc_count)
+     else if (eat->total_count - eat_in_use < cache->total_count - dst_ins_use)
        {
          struct alloccache_free_ent *last = eat->free_head;
@@ -1287,10 +1290,11 @@
   /* and statistics */
   cache->alloc_count += eat->alloc_count;
-  cache->total_count += eat->total_count;
+  cache->free_count  += eat->free_count;
 #else
   /* and statistics */
   cache->alloc_count += eat->alloc_count;
-  cache->total_count += eat->alloc_count;
-#endif
+  cache->free_count  += eat->free_count;
+#endif
+  cache->total_count += eat->total_count;
 
   /* unlink and disable the eat cache */
@@ -1316,6 +1320,11 @@
 {
   printf (_("\n# Alloc Cache: %s\n"
-              "#  Items: size = %-3u  in-use = %-6d  total = %-6u\n"),
-          cache->name, cache->size, (int)cache->alloc_count, cache->total_count);
+              "#  Items: size = %-3u  total = %-6u"),
+          cache->name, cache->size, cache->total_count);
+  MAKE_STATS(printf (_("  in-use = %-6lu"),
+                     cache->alloc_count - cache->free_count););
+  MAKE_STATS(printf (_("\n#         alloc calls = %-7lu  free calls = %-7lu"),
+                     cache->alloc_count, cache->free_count););
+  printf ("\n");
 }
 
Index: trunk/src/kmk/strcache2.c
===================================================================
--- trunk/src/kmk/strcache2.c	(revision 1924)
+++ trunk/src/kmk/strcache2.c	(revision 1925)
@@ -1266,17 +1266,19 @@
 
 #ifdef STRCACHE2_USE_MASK
-  printf (_("%s  hash size = %u  mask = %#x  rehashed %u times  lookups = %lu\n"),
-          prefix, cache->hash_size, cache->hash_mask, rehashes, cache->lookup_count);
+  printf (_("%s  hash size = %u  mask = %#x  rehashed %u times"),
+          prefix, cache->hash_size, cache->hash_mask, rehashes);
 #else
-  printf (_("%s  hash size = %u  div = %#x  rehashed %u times  lookups = %lu\n"),
-          prefix, cache->hash_size, cache->hash_div, rehashes, cache->lookup_count);
+  printf (_("%s  hash size = %u  div = %#x  rehashed %u times"),
+          prefix, cache->hash_size, cache->hash_div, rehashes);
 #endif
   if (cache->lookup_count)
-    printf (_("%s  hash collisions 1st = %lu (%u%%)  2nd = %lu (%u%%)  3rd = %lu (%u%%)\n"),
+    printf (_("%s  lookups = %lu\n"
+              "%s  hash collisions 1st = %lu (%u%%)  2nd = %lu (%u%%)  3rd = %lu (%u%%)"),
+            prefix, cache->lookup_count,
             prefix,
             cache->collision_1st_count,  (unsigned int)((100.0 * cache->collision_1st_count) / cache->lookup_count),
             cache->collision_2nd_count,  (unsigned int)((100.0 * cache->collision_2nd_count) / cache->lookup_count),
             cache->collision_3rd_count,  (unsigned int)((100.0 * cache->collision_3rd_count) / cache->lookup_count));
-  printf (_("%s  hash insert collisions = %u (%u%%)\n"),
+  printf (_("\n%s  hash insert collisions = %u (%u%%)\n"),
           prefix, cache->collision_count,(unsigned int)((100.0 * cache->collision_count) / cache->count));
   printf (_("%s  %5u (%u%%) empty hash table slots\n"),
