From fcd2d3ef364ba7af3e966a88cd284abcfa893ceb Mon Sep 17 00:00:00 2001 From: rousskov <> Date: Sat, 6 Jun 1998 01:45:16 +0000 Subject: [PATCH] - fixed HTTP header statistics that was broken after the introduction of request headers --- src/HttpHdrCc.cc | 9 ++---- src/HttpHeader.cc | 70 ++++++++++++++++++++++++++--------------------- src/structs.h | 30 +++++++++++++++----- src/typedefs.h | 1 + src/url.cc | 7 +++-- 5 files changed, 70 insertions(+), 47 deletions(-) diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index afc93f5179..143bc917ff 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -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)); } diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index ee456cd34b..4feb615f7a 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -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 @@ -51,19 +51,6 @@ */ -/* - * 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 ":[ws]" lines delimited by */ 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

Header Stats: %s

\n", hs->label); storeAppendPrintf(e, "

Field type distribution

\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", "
"); @@ -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); } diff --git a/src/structs.h b/src/structs.h index 98b55e307d..45e1208228 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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; diff --git a/src/typedefs.h b/src/typedefs.h index a82a2ae3d7..423b22f21d 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -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; diff --git a/src/url.cc b/src/url.cc index 86c43e2150..41fe1ba85e 100644 --- a/src/url.cc +++ b/src/url.cc @@ -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; } -- 2.47.3