]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- better stats
authorrousskov <>
Wed, 1 Apr 1998 13:22:03 +0000 (13:22 +0000)
committerrousskov <>
Wed, 1 Apr 1998 13:22:03 +0000 (13:22 +0000)
- minor fixes

src/CacheDigest.cc
src/protos.h
src/test_cache_digest.cc

index 8462f86d8fe2fa7ad3545af99651b7a591ee661a..59042a58cb3544cec8fd0405cd0b7af023f3c8fd 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: CacheDigest.cc,v 1.3 1998/04/01 00:14:00 rousskov Exp $
+ * $Id: CacheDigest.cc,v 1.4 1998/04/01 06:22:03 rousskov Exp $
  *
  * DEBUG: section ??    Cache Digest
  * AUTHOR: Alex Rousskov
@@ -66,24 +66,11 @@ cacheDigestClone(const CacheDigest * cd)
     CacheDigest *clone;
     assert(cd);
     clone = cacheDigestCreate(cd->capacity);
+    clone->count = cd->count;
     xmemcpy(clone->mask, cd->mask, cd->mask_size);
     return clone;
 }
 
-void
-cacheDigestAdd(CacheDigest * cd, const cache_key * key)
-{
-    assert(cd && key);
-    /* hash */
-    cacheDigestHashKey(cd->capacity * BitsPerEntry, key);
-    /* turn on corresponding bits */
-    CBIT_SET(cd->mask, hashed_keys[0]);
-    CBIT_SET(cd->mask, hashed_keys[1]);
-    CBIT_SET(cd->mask, hashed_keys[2]);
-    CBIT_SET(cd->mask, hashed_keys[3]);
-    cd->count++;
-}
-
 /* returns true if the key belongs to the digest */
 int
 cacheDigestTest(const CacheDigest * cd, const cache_key * key)
@@ -99,6 +86,20 @@ cacheDigestTest(const CacheDigest * cd, const cache_key * key)
        CBIT_TEST(cd->mask, hashed_keys[3]);
 }
 
+void
+cacheDigestAdd(CacheDigest * cd, const cache_key * key)
+{
+    assert(cd && key);
+    /* hash */
+    cacheDigestHashKey(cd->capacity * BitsPerEntry, key);
+    /* turn on corresponding bits */
+    CBIT_SET(cd->mask, hashed_keys[0]);
+    CBIT_SET(cd->mask, hashed_keys[1]);
+    CBIT_SET(cd->mask, hashed_keys[2]);
+    CBIT_SET(cd->mask, hashed_keys[3]);
+    cd->count++;
+}
+
 void
 cacheDigestDel(CacheDigest * cd, const cache_key * key)
 {
@@ -107,6 +108,23 @@ cacheDigestDel(CacheDigest * cd, const cache_key * key)
     /* we do not support deletions from the digest */
 }
 
+/* returns mask utilization parameters */
+double
+cacheDigestUtil(const CacheDigest * cd, int *bit_cnt_p, int *on_cnt_p)
+{
+    const int bit_count = cd->capacity * BitsPerEntry;
+    int pos = bit_count;
+    int on_count = 0;
+    while (pos-- > 0) {
+       if (CBIT_TEST(cd->mask, pos))
+           on_count++;
+    }
+    if (bit_cnt_p)
+       *bit_cnt_p = bit_count;
+    if (on_cnt_p)
+       *on_cnt_p = on_count;
+    return xpercent(on_count, bit_count);
+}
 
 static void
 cacheDigestHashKey(int bit_count, const char *key)
index bf6b821fc6dc00514361df47a79733bd5033dada..7426bac36f3b5145f7de8fee605ee24e6d02b702 100644 (file)
@@ -899,6 +899,7 @@ extern CacheDigest *cacheDigestClone(const CacheDigest * cd);
 extern int cacheDigestTest(const CacheDigest * cd, const cache_key * key);
 extern void cacheDigestAdd(CacheDigest * cd, const cache_key * key);
 extern void cacheDigestDel(CacheDigest * cd, const cache_key * key);
+extern double cacheDigestUtil(const CacheDigest * cd, int *bit_cnt_p, int *on_cnt_p);
 
 /*
  * prototypes for system functions missing from system includes
index 3042d7708f318440107f2dc4577acedc82fb12f9..e850898bcca5951b0d146252be6423476ef7947f 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: test_cache_digest.cc,v 1.8 1998/04/01 05:02:21 rousskov Exp $
+ * $Id: test_cache_digest.cc,v 1.9 1998/04/01 06:22:04 rousskov Exp $
  *
  * AUTHOR: Alex Rousskov
  *
@@ -50,6 +50,7 @@ struct _Cache {
     Cache *peer;
     CacheQueryStats qstats;
     int count;                 /* #currently cached entries */
+    int req_count;              /* #requests to this cache */
     int bad_add_count;         /* #duplicate adds */
     int bad_del_count;         /* #dels with no prior add */
 };
@@ -320,7 +321,10 @@ cacheQueryPeer(Cache * cache, const cache_key * key)
 static void
 cacheQueryReport(Cache * cache, CacheQueryStats *stats)
 {
-    fprintf(stdout, "%s: icp: %d\n", cache->name, stats->query_count);
+    fprintf(stdout, "%s: peer queries: %d (%d%%)\n", 
+       cache->name, 
+       stats->query_count, xpercentInt(stats->query_count, cache->req_count)
+       );
     fprintf(stdout, "%s: t-hit: %d (%d%%) t-miss: %d (%d%%) t-*: %d (%d%%)\n",
        cache->name, 
        stats->true_hit_count, xpercentInt(stats->true_hit_count, stats->query_count),
@@ -337,10 +341,35 @@ cacheQueryReport(Cache * cache, CacheQueryStats *stats)
        );
 }
 
+static void
+cacheReport(Cache * cache)
+{
+    fprintf(stdout, "%s: entries: %d reqs: %d bad-add: %d bad-del: %d\n", 
+       cache->name, cache->count, cache->req_count,
+       cache->bad_add_count, cache->bad_del_count);
+
+    if (cache->digest) {
+       int bit_count, on_count;
+       cacheDigestUtil(cache->digest, &bit_count, &on_count);
+       fprintf(stdout, "%s: digest entries: cnt: %d cap: %d util: %d%% size: %d b\n", 
+           cache->name, 
+           cache->digest->count, cache->digest->capacity,
+           xpercentInt(cache->digest->count, cache->digest->capacity),
+           bit_count*8
+       );
+       fprintf(stdout, "%s: digest bits: on: %d cap: %d util: %d%%\n", 
+           cache->name,
+           on_count, bit_count,
+           xpercentInt(on_count, bit_count)
+       );
+    }
+}
+
 static void
 cacheFetch(Cache *cache, const RawAccessLogEntry *e)
 {
     assert(e);
+    cache->req_count++;
     if (e->use_icp)
        cacheQueryPeer(cache, e->key);
 }
@@ -420,8 +449,6 @@ accessLogReader(FileIterator * fi)
        strcmp(hier, "PASSTHROUGH_PARENT") &&
        strcmp(hier, "SSL_PARENT_MISS") &&
        strcmp(hier, "DEFAULT_PARENT");
-    if (!entry->use_icp)
-       return frMore;
     memcpy(entry->key, storeKeyPublic(url, method_id), sizeof(entry->key));
     /*fprintf(stdout, "%s:%d: %s %s %s %s\n",
        fname, count, method, storeKeyText(entry->key), url, hier); */
@@ -504,6 +531,7 @@ main(int argc, char *argv[])
     fis[0] = fileIteratorCreate(argv[1], accessLogReader);
     for (i = 2; i < argc; ++i) {
        fis[i-1] = fileIteratorCreate(argv[i], swapStateReader);
+       if (!fis[i-1]) return -2;
     }
     /* read prefix to get start-up contents of the peer cache */
     ready_time = -1;
@@ -547,12 +575,14 @@ main(int argc, char *argv[])
            if (next_i == 0)
                cacheFetch(us, fis[next_i]->entry);
            else
-               cacheUpdateStore(them, fis[next_i]->entry, 0);
+               cacheUpdateStore(them, fis[next_i]->entry, 1);
            fileIteratorAdvance(fis[next_i]);
        }
     } while (active_fi_count);
 
     /* report */
+    cacheReport(them);
+    cacheReport(us);
     cacheQueryReport(us, &us->qstats);
 
     /* clean */