Wed Mar 4 16:50:18 1998 Jason Molenda (crash@bugshack.cygnus.com)
[deliverable/binutils-gdb.git] / gdb / bcache.c
index af80afbbdd8a14c0f4840866a70f8d67e710fc6f..377355b203c67839395c7eaeae54f64e5dfe5d20 100644 (file)
@@ -21,6 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "defs.h"
 #include "obstack.h"
 #include "bcache.h"
+#include "gdb_string.h"                /* For memcpy declaration */
+
+static unsigned int hash PARAMS ((void *, int));
+static void *lookup_cache PARAMS ((void *, int, int, struct bcache *));
 
 /* FIXME:  Incredibly simplistic hash generator.  Probably way too expensive
  (consider long strings) and unlikely to have good distribution across hash
@@ -67,9 +71,9 @@ lookup_cache (bytes, count, hashval, bcachep)
       linkp = hashtablep[hashval];
       while (linkp != NULL)
        {
-         if (memcmp (linkp -> data, bytes, count) == 0)
+         if (memcmp (BCACHE_DATA (linkp), bytes, count) == 0)
            {
-             location = linkp -> data;
+             location = BCACHE_DATA (linkp);
              break;
            }
          linkp = linkp -> next;
@@ -90,7 +94,7 @@ bcache (bytes, count, bcachep)
   struct hashlink **linkpp;
   struct hashlink ***hashtablepp;
 
-  if (count > BCACHE_MAXLENGTH)
+  if (count >= BCACHE_MAXLENGTH)
     {
       /* Rare enough to just stash unique copies */
       location = (void *) obstack_alloc (&bcachep->cache, count);
@@ -115,17 +119,17 @@ bcache (bytes, count, bcachep)
            {
              *hashtablepp = (struct hashlink **)
                obstack_alloc (&bcachep->cache, BCACHE_HASHSIZE * sizeof (struct hashlink *));
-             bcachep -> cache_bytes += sizeof (struct hashlink *);
+             bcachep -> cache_bytes += BCACHE_HASHSIZE * sizeof (struct hashlink *);
              memset (*hashtablepp, 0, BCACHE_HASHSIZE * sizeof (struct hashlink *));
            }
          linkpp = &(*hashtablepp)[hashval];
          newlink = (struct hashlink *)
-           obstack_alloc (&bcachep->cache, sizeof (struct hashlink *) + count);
-         bcachep -> cache_bytes += sizeof (struct hashlink *) + count;
-         memcpy (newlink -> data, bytes, count);
+           obstack_alloc (&bcachep->cache, BCACHE_DATA_ALIGNMENT + count);
+         bcachep -> cache_bytes += BCACHE_DATA_ALIGNMENT + count;
+         memcpy (BCACHE_DATA (newlink), bytes, count);
          newlink -> next = *linkpp;
          *linkpp = newlink;
-         location = newlink -> data;
+         location = BCACHE_DATA (newlink);
        }
     }
   return (location);
@@ -172,16 +176,40 @@ print_bcache_statistics (bcachep, id)
   printf_filtered ("  Cached '%s' statistics:\n", id);
   printf_filtered ("    Cache hits: %d\n", bcachep -> cache_hits);
   printf_filtered ("    Cache misses: %d\n", bcachep -> cache_misses);
-  printf_filtered ("    Cache hit ratio: %d%%\n", ((bcachep -> cache_hits) * 100) /  (bcachep -> cache_hits + bcachep -> cache_misses));
+  printf_filtered ("    Cache hit ratio: ");
+  if (bcachep -> cache_hits + bcachep -> cache_misses > 0)
+    {
+      printf_filtered ("%d%%\n", ((bcachep -> cache_hits) * 100) /
+                      (bcachep -> cache_hits + bcachep -> cache_misses));
+    }
+  else
+    {
+      printf_filtered ("(not applicable)\n");
+    }
   printf_filtered ("    Space used for caching: %d\n", bcachep -> cache_bytes);
   printf_filtered ("    Space saved by cache hits: %d\n", bcachep -> cache_savings);
   printf_filtered ("    Number of bcache overflows: %d\n", bcachep -> bcache_overflows);
   printf_filtered ("    Number of index buckets used: %d\n", tcount);
   printf_filtered ("    Number of hash table buckets used: %d\n", hcount);
   printf_filtered ("    Number of chained items: %d\n", lcount);
-  printf_filtered ("    Average hash table population: %d%%\n",
-                  (hcount * 100) / (tcount * BCACHE_HASHSIZE));
-  printf_filtered ("    Average chain length %d\n", lcount / hcount);
+  printf_filtered ("    Average hash table population: ");
+  if (tcount > 0)
+    {
+      printf_filtered ("%d%%\n", (hcount * 100) / (tcount * BCACHE_HASHSIZE));
+    }
+  else
+    {
+      printf_filtered ("(not applicable)\n");
+    }
+  printf_filtered ("    Average chain length ");
+  if (hcount > 0)
+    {
+      printf_filtered ("%d\n", lcount / hcount);
+    }
+  else
+    {
+      printf_filtered ("(not applicable)\n");
+    }
   printf_filtered ("    Maximum chain length %d at %d:%d\n", lmax, lmaxt, lmaxh);
 }
 
This page took 0.025692 seconds and 4 git commands to generate.