]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- fixed HTTP header statistics that was broken after the introduction of
authorrousskov <>
Sat, 6 Jun 1998 01:45:16 +0000 (01:45 +0000)
committerrousskov <>
Sat, 6 Jun 1998 01:45:16 +0000 (01:45 +0000)
  request headers

src/HttpHdrCc.cc
src/HttpHeader.cc
src/structs.h
src/typedefs.h
src/url.cc

index afc93f517994056572cdcd23e2bd6dbd86931372..143bc917ffb6bd34f76c0879f3a8f7d0fac53049 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHdrCc.cc,v 1.11 1998/05/22 23:43:50 wessels Exp $
+ * $Id: HttpHdrCc.cc,v 1.12 1998/06/05 19:45:16 rousskov Exp $
  *
  * DEBUG: section 65    HTTP Cache Control Header
  * AUTHOR: Alex Rousskov
@@ -47,9 +47,6 @@ static const HttpHeaderFieldAttrs CcAttrs[CC_ENUM_END] =
 };
 HttpHeaderFieldInfo *CcFieldsInfo = NULL;
 
-/* counters */
-static int CcParsedCount = 0;
-
 /* local prototypes */
 static int httpHdrCcParseInit(HttpHdrCc * cc, const String * str);
 
@@ -102,7 +99,6 @@ httpHdrCcParseInit(HttpHdrCc * cc, const String * str)
     int ilen;
     assert(cc && str);
 
-    CcParsedCount++;
     /* iterate through comma separated list */
     while (strListGetItem(str, ',', &item, &ilen, &pos)) {
        /* strip '=' statements @?@ */
@@ -209,10 +205,11 @@ httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist)
 void
 httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int count)
 {
+    extern const HttpHeaderStat *dump_stat; /* argh! */
     const int id = (int) val;
     const int valid_id = id >= 0 && id < CC_ENUM_END;
     const char *name = valid_id ? strBuf(CcFieldsInfo[id].name) : "INVALID";
     if (count || valid_id)
        storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\n",
-           id, name, count, xdiv(count, CcParsedCount));
+           id, name, count, xdiv(count, dump_stat->ccParsedCount));
 }
index ee456cd34b60a33509e247f7b769553fb841f734..4feb615f7aa4322e955b34b0ae126ef9dd68d33e 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHeader.cc,v 1.43 1998/06/03 22:32:58 rousskov Exp $
+ * $Id: HttpHeader.cc,v 1.44 1998/06/05 19:45:17 rousskov Exp $
  *
  * DEBUG: section 55    HTTP Header
  * AUTHOR: Alex Rousskov
  */
 
 
-/*
- * local types
- */
-
-/* per header statistics */
-typedef struct {
-    const char *label;
-    StatHist hdrUCountDistr;
-    StatHist fieldTypeDistr;
-    StatHist ccTypeDistr;
-} HttpHeaderStat;
-
-
 /*
  * local constants and vars
  */
@@ -208,10 +195,6 @@ static HttpHeaderStat HttpHeaderStats[] =
 };
 static int HttpHeaderStatCount = countof(HttpHeaderStats);
 
-/* global counters */
-static int HeaderParsedCount = 0;
-static int HeaderDestroyedCount = 0;
-static int NonEmptyHeaderDestroyedCount = 0;
 static int HeaderEntryParsedCount = 0;
 
 /*
@@ -255,7 +238,11 @@ httpHeaderInitModule()
     /* init header stats */
     for (i = 0; i < HttpHeaderStatCount; i++)
        httpHeaderStatInit(HttpHeaderStats + i, HttpHeaderStats[i].label);
+    HttpHeaderStats[hoRequest].owner_mask = &RequestHeadersMask;
+    HttpHeaderStats[hoReply].owner_mask = &ReplyHeadersMask;
+    /* init dependent modules */
     httpHdrCcInitModule();
+    /* register with cache manager */
     cachemgrRegister("http_headers",
        "HTTP Header Statistics", httpHeaderStoreReport, 0);
 }
@@ -273,6 +260,7 @@ httpHeaderStatInit(HttpHeaderStat * hs, const char *label)
 {
     assert(hs);
     assert(label);
+    memset(hs, 0, sizeof(HttpHeaderStat));
     hs->label = label;
     statHistEnumInit(&hs->hdrUCountDistr, 32); /* not a real enum */
     statHistEnumInit(&hs->fieldTypeDistr, HDR_ENUM_END);
@@ -302,12 +290,10 @@ httpHeaderClean(HttpHeader * hdr)
     assert(hdr && (hdr->owner == hoRequest || hdr->owner == hoReply));
     debug(55, 7) ("cleaning hdr: %p owner: %d\n", hdr, hdr->owner);
 
-    statHistCount(&HttpHeaderStats[0].hdrUCountDistr, hdr->entries.count);
     statHistCount(&HttpHeaderStats[hdr->owner].hdrUCountDistr, hdr->entries.count);
-    HeaderDestroyedCount++;
-    NonEmptyHeaderDestroyedCount += hdr->entries.count > 0;
+    HttpHeaderStats[hdr->owner].destroyedCount++;
+    HttpHeaderStats[hdr->owner].busyDestroyedCount += hdr->entries.count > 0;
     while ((e = httpHeaderGetEntry(hdr, &pos))) {
-       statHistCount(&HttpHeaderStats[0].fieldTypeDistr, e->id);
        statHistCount(&HttpHeaderStats[hdr->owner].fieldTypeDistr, e->id);
        /* tmp hack to avoid coredumps */
        if (e->id < 0 || e->id >= HDR_ENUM_END)
@@ -376,7 +362,7 @@ httpHeaderParse(HttpHeader * hdr, const char *header_start, const char *header_e
     assert(hdr);
     assert(header_start && header_end);
     debug(55, 7) ("parsing hdr: (%p)\n%s\n", hdr, getStringPrefix(header_start, header_end));
-    HeaderParsedCount++;
+    HttpHeaderStats[hdr->owner].parsedCount++;
     /* commonn format headers are "<name>:[ws]<value>" lines delimited by <CRLF> */
     while (field_start < header_end) {
        const char *field_end = field_start + strcspn(field_start, "\r\n");
@@ -769,10 +755,9 @@ httpHeaderGetCc(const HttpHeader * hdr)
        return NULL;
     s = httpHeaderGetList(hdr, HDR_CACHE_CONTROL);
     cc = httpHdrCcParseCreate(&s);
-    if (cc) {
-       httpHdrCcUpdateStats(cc, &HttpHeaderStats[0].ccTypeDistr);
+    HttpHeaderStats[hdr->owner].ccParsedCount++;
+    if (cc)
        httpHdrCcUpdateStats(cc, &HttpHeaderStats[hdr->owner].ccTypeDistr);
-    }
     httpHeaderNoteParsedEntry(HDR_CACHE_CONTROL, s, !cc);
     stringClean(&s);
     return cc;
@@ -969,15 +954,24 @@ httpHeaderNoteParsedEntry(http_hdr_type id, String context, int error)
  * Reports
  */
 
+/* tmp variable used to pass stat info to dumpers */
+extern const HttpHeaderStat *dump_stat; /* argh! */
+const HttpHeaderStat *dump_stat = NULL;
+
 static void
 httpHeaderFieldStatDumper(StoreEntry * sentry, int idx, double val, double size, int count)
 {
     const int id = (int) val;
     const int valid_id = id >= 0 && id < HDR_ENUM_END;
     const char *name = valid_id ? strBuf(Headers[id].name) : "INVALID";
-    if (count || valid_id)
-       storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\n",
-           id, name, count, xdiv(count, NonEmptyHeaderDestroyedCount));
+    int visible = count > 0;
+    /* for entries with zero count, list only those that belong to current type of message */
+    if (!visible && valid_id && dump_stat->owner_mask)
+       visible = CBIT_TEST(*dump_stat->owner_mask, id);
+    if (visible)
+       storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\t %d\n",
+           id, name, count, xdiv(count, dump_stat->busyDestroyedCount),
+           visible);
 }
 
 static void
@@ -986,7 +980,7 @@ httpHeaderFldsPerHdrDumper(StoreEntry * sentry, int idx, double val, double size
     if (count)
        storeAppendPrintf(sentry, "%2d\t %5d\t %5d\t %6.2f\n",
            idx, (int) val, count,
-           xpercent(count, HeaderDestroyedCount));
+           xpercent(count, dump_stat->destroyedCount));
 }
 
 
@@ -995,6 +989,7 @@ httpHeaderStatDump(const HttpHeaderStat * hs, StoreEntry * e)
 {
     assert(hs && e);
 
+    dump_stat = hs;
     storeAppendPrintf(e, "\n<h3>Header Stats: %s</h3>\n", hs->label);
     storeAppendPrintf(e, "<h3>Field type distribution</h3>\n");
     storeAppendPrintf(e, "%2s\t %-20s\t %5s\t %6s\n",
@@ -1008,6 +1003,7 @@ httpHeaderStatDump(const HttpHeaderStat * hs, StoreEntry * e)
     storeAppendPrintf(e, "%2s\t %-5s\t %5s\t %6s\n",
        "id", "#flds", "count", "%total");
     statHistDump(&hs->hdrUCountDistr, e, httpHeaderFldsPerHdrDumper);
+    dump_stat = NULL;
 }
 
 void
@@ -1017,6 +1013,15 @@ httpHeaderStoreReport(StoreEntry * e)
     http_hdr_type ht;
     assert(e);
 
+    HttpHeaderStats[0].parsedCount =
+       HttpHeaderStats[hoRequest].parsedCount + HttpHeaderStats[hoReply].parsedCount;
+    HttpHeaderStats[0].ccParsedCount =
+       HttpHeaderStats[hoRequest].ccParsedCount + HttpHeaderStats[hoReply].ccParsedCount;
+    HttpHeaderStats[0].destroyedCount =
+       HttpHeaderStats[hoRequest].destroyedCount + HttpHeaderStats[hoReply].destroyedCount;
+    HttpHeaderStats[0].busyDestroyedCount =
+       HttpHeaderStats[hoRequest].busyDestroyedCount + HttpHeaderStats[hoReply].busyDestroyedCount;
+
     for (i = 1; i < HttpHeaderStatCount; i++) {
        httpHeaderStatDump(HttpHeaderStats + i, e);
        storeAppendPrintf(e, "%s\n", "<br>");
@@ -1032,6 +1037,9 @@ httpHeaderStoreReport(StoreEntry * e)
            xpercent(f->stat.errCount, f->stat.parsCount),
            xpercent(f->stat.repCount, f->stat.seenCount));
     }
-    storeAppendPrintf(e, "Headers Parsed: %d\n", HeaderParsedCount);
+    storeAppendPrintf(e, "Headers Parsed: %d + %d = %d\n",
+       HttpHeaderStats[hoRequest].parsedCount,
+       HttpHeaderStats[hoReply].parsedCount,
+       HttpHeaderStats[0].parsedCount);
     storeAppendPrintf(e, "Hdr Fields Parsed: %d\n", HeaderEntryParsedCount);
 }
index 98b55e307d0f03e49366997efad8ad4433dfafea..45e120822832f4cc73f4da9cbdedf882068f6e19 100644 (file)
@@ -550,6 +550,13 @@ struct _HttpHdrRangeIter  {
     String boundary;    /* boundary for multipart responses */
 };
 
+/* constant attributes of http header fields */
+struct _HttpHeaderFieldAttrs {
+    const char *name;
+    http_hdr_type id;
+    field_type type;
+};
+
 /* per field statistics */
 struct _HttpHeaderFieldStat {
     int aliveCount;            /* created but not destroyed (count) */
@@ -559,13 +566,6 @@ struct _HttpHeaderFieldStat {
     int repCount;              /* #repetitons */
 };
 
-/* constant attributes of http header fields */
-struct _HttpHeaderFieldAttrs {
-    const char *name;
-    http_hdr_type id;
-    field_type type;
-};
-
 /* compiled version of HttpHeaderFieldAttrs plus stats */
 struct _HttpHeaderFieldInfo {
     http_hdr_type id;
@@ -1280,6 +1280,22 @@ struct _StatCounters {
     StatHist comm_incoming;
 };
 
+/* per header statistics */
+struct _HttpHeaderStat {
+    const char *label;
+    HttpHeaderMask *owner_mask;
+
+    StatHist hdrUCountDistr;
+    StatHist fieldTypeDistr;
+    StatHist ccTypeDistr;
+
+    int parsedCount;
+    int ccParsedCount;
+    int destroyedCount;
+    int busyDestroyedCount;
+};
+
+
 struct _tlv {
     char type;
     int length;
index a82a2ae3d756828afbbf3e08c0026d67eee3a403..423b22f21d6dc413bb22f95491827a870ef30bd2 100644 (file)
@@ -64,6 +64,7 @@ typedef struct _HttpHdrContRange HttpHdrContRange;
 typedef struct _TimeOrTag TimeOrTag;
 typedef struct _HttpHeaderEntry HttpHeaderEntry;
 typedef struct _HttpHeaderFieldStat HttpHeaderFieldStat;
+typedef struct _HttpHeaderStat HttpHeaderStat;
 typedef struct _HttpBody HttpBody;
 typedef struct _HttpReply HttpReply;
 typedef struct _HttpStateData HttpStateData;
index 86c43e215058655f0b60a56b0803f77b9bb5210c..41fe1ba85e629e2e9c748272c79fe0b075805128 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: url.cc,v 1.95 1998/06/05 00:25:58 wessels Exp $
+ * $Id: url.cc,v 1.96 1998/06/05 19:45:20 rousskov Exp $
  *
  * DEBUG: section 23    URL Parsing
  * AUTHOR: Duane Wessels
@@ -161,10 +161,13 @@ urlParseMethod(const char *s)
 protocol_t
 urlParseProtocol(const char *s)
 {
+    /* test common stuff first */
     if (strcasecmp(s, "http") == 0)
        return PROTO_HTTP;
     if (strcasecmp(s, "ftp") == 0)
        return PROTO_FTP;
+    if (strcasecmp(s, "https") == 0)
+       return PROTO_HTTPS;
     if (strcasecmp(s, "file") == 0)
        return PROTO_FTP;
     if (strcasecmp(s, "gopher") == 0)
@@ -179,8 +182,6 @@ urlParseProtocol(const char *s)
        return PROTO_WHOIS;
     if (strcasecmp(s, "internal") == 0)
        return PROTO_INTERNAL;
-    if (strcasecmp(s, "https") == 0)
-       return PROTO_HTTPS;
     return PROTO_NONE;
 }