From: wessels <> Date: Sat, 15 Nov 1997 07:14:46 +0000 (+0000) Subject: New averaging counter stuff X-Git-Tag: SQUID_3_0_PRE1~4527 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f29084972801ac4f9be3bcd7b0d0ed32264630fa;p=thirdparty%2Fsquid.git New averaging counter stuff --- diff --git a/src/client_side.cc b/src/client_side.cc index 727a03bcf2..bbd59abc2e 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.151 1997/11/14 17:20:13 wessels Exp $ + * $Id: client_side.cc,v 1.152 1997/11/15 00:14:46 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1549,6 +1549,7 @@ clientReadRequest(int fd, void *data) for (H = &conn->chr; *H; H = &(*H)->next); *H = http; conn->nrequests++; + Counter.client_http.requests++; commSetTimeout(fd, Config.Timeout.lifetime, NULL, NULL); if ((request = urlParse(method, http->url)) == NULL) { debug(12, 5) ("Invalid URL: %s\n", http->url); @@ -1624,6 +1625,7 @@ clientReadRequest(int fd, void *data) break; } else { /* parser returned -1 */ + Counter.client_http.requests++; debug(12, 1) ("clientReadRequest: FD %d Invalid Request\n", fd); err = errorCon(ERR_INVALID_REQ, HTTP_BAD_REQUEST); err->callback = clientErrorComplete; @@ -1680,7 +1682,6 @@ httpAccept(int sock, void *notused) sock, xstrerror()); return; } - ntcpconn++; debug(12, 4) ("httpAccept: FD %d: accepted\n", fd); connState = xcalloc(1, sizeof(ConnStateData)); connState->peer = peer; diff --git a/src/comm.cc b/src/comm.cc index bc14d01dd8..12a54b9f95 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.204 1997/11/14 17:21:15 wessels Exp $ + * $Id: comm.cc,v 1.205 1997/11/15 00:14:47 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -869,7 +869,7 @@ comm_poll(time_t sec) #endif for (;;) { num = poll(pfds, nfds, poll_time); - select_loops++; + Counter.select_loops++; if (num >= 0) break; if (errno == EINTR) @@ -1016,7 +1016,7 @@ comm_select(time_t sec) poll_time.tv_sec = sec > 0 ? 1 : 0; poll_time.tv_usec = 0; num = select(maxfd, &readfds, &writefds, NULL, &poll_time); - select_loops++; + Counter.select_loops++; if (num >= 0) break; if (errno == EINTR) diff --git a/src/globals.h b/src/globals.h index f3bc8810e1..37892dbe5e 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.17 1997/11/05 05:29:25 wessels Exp $ + * $Id: globals.h,v 1.18 1997/11/15 00:14:48 wessels Exp $ */ extern FILE *debug_log; /* NULL */ @@ -65,7 +65,6 @@ extern int opt_reload_hit_only; /* 0 */ extern int opt_syslog_enable; /* 0 */ extern int opt_udp_hit_obj; /* 0 */ extern int opt_zap_disk_store; /* 0 */ -extern int select_loops; /* 0 */ extern int syslog_enable; /* 0 */ extern int theInIcpConnection; /* -1 */ extern int theOutIcpConnection; /* -1 */ @@ -82,13 +81,10 @@ extern struct in_addr local_addr; extern struct in_addr no_addr; extern struct in_addr theOutICPAddr; extern struct timeval current_time; +extern struct timeval squid_start; extern time_t squid_curtime; /* 0 */ -extern time_t squid_starttime; /* 0 */ extern volatile int reconfigure_pending; /* 0 */ extern volatile int shutdown_pending; /* 0 */ -extern volatile unsigned long nudpconn; /* 0 */ -extern volatile unsigned long ntcpconn; /* 0 */ -extern int unlinkd_count; /* 0 */ extern int fileno_stack_count; /* 0 */ extern int store_rebuilding; /* 1 */ extern int store_swap_size; /* 0 */ @@ -97,6 +93,7 @@ extern unsigned long store_mem_size; /* 0 */ extern icpUdpData *UdpQueueHead; /* NULL */ extern icpUdpData *UdpQueueTail; /* NULL */ extern time_t hit_only_mode_until; /* 0 */ +extern StatCounters Counter; #ifdef HAVE_SYSLOG extern int _db_level; diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 68f0354fb6..54d12edb95 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -41,6 +41,7 @@ icpUdpReply(int fd, void *data) queue->len, inet_ntoa(queue->address.sin_addr), ntohs(queue->address.sin_port)); + Counter.icp.pkts_sent++; x = comm_udp_sendto(fd, &queue->address, sizeof(struct sockaddr_in), @@ -49,6 +50,8 @@ icpUdpReply(int fd, void *data) if (x < 0) { if (ignoreErrno(errno)) break; /* don't de-queue */ + } else { + Counter.icp.bytes_sent += x; } UdpQueueHead = queue->next; if (queue->logcode) @@ -231,7 +234,6 @@ icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) switch (header.opcode) { case ICP_OP_QUERY: - nudpconn++; /* We have a valid packet */ url = buf + sizeof(header) + sizeof(u_num32); if ((icp_request = urlParse(METHOD_GET, url)) == NULL) { @@ -402,6 +404,8 @@ icpHandleUdp(int sock, void *datanotused) sock, xstrerror()); return; } + Counter.icp.pkts_recv++; + Counter.icp.bytes_recv += len; buf[len] = '\0'; debug(12, 4) ("icpHandleUdp: FD %d: received %d bytes from %s.\n", sock, diff --git a/src/icp_v3.cc b/src/icp_v3.cc index 2dd120fc7b..4b957d3826 100644 --- a/src/icp_v3.cc +++ b/src/icp_v3.cc @@ -26,7 +26,6 @@ icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len) switch (header.opcode) { case ICP_OP_QUERY: - nudpconn++; /* We have a valid packet */ url = buf + sizeof(header) + sizeof(u_num32); if ((icp_request = urlParse(METHOD_GET, url)) == NULL) { diff --git a/src/main.cc b/src/main.cc index 3e5a20442d..e5a18eb695 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.191 1997/11/13 05:25:49 wessels Exp $ + * $Id: main.cc,v 1.192 1997/11/15 00:14:49 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -294,8 +294,8 @@ void shut_down(int sig) { shutdown_pending = sig == SIGINT ? -1 : 1; - debug(1, 1) ("Preparing for shutdown after %d connections\n", - ntcpconn + nudpconn); + debug(1, 1) ("Preparing for shutdown after %d requests\n", + Counter.client_http.requests); debug(1, 1) ("Waiting %d seconds for active connections to finish\n", shutdown_pending > 0 ? Config.shutdownLifetime : 0); #ifdef KILL_PARENT_OPT @@ -580,6 +580,7 @@ mainInitialize(void) if (Config.onoff.announce) eventAdd("start_announce", start_announce, NULL, 3600); eventAdd("ipcache_purgelru", ipcache_purgelru, NULL, 10); + statAvgInit(); } configured_once = 1; } @@ -619,7 +620,8 @@ main(int argc, char **argv) safe_inet_addr("255.255.255.255", &no_addr); squid_srandom(time(NULL)); - squid_starttime = getCurrentTime(); + getCurrentTime(); + squid_start = current_time; failure_notify = fatal_dump; mainParseOptions(argc, argv); diff --git a/src/protos.h b/src/protos.h index 18b3eb6f88..6759784b67 100644 --- a/src/protos.h +++ b/src/protos.h @@ -366,6 +366,7 @@ extern void stackFreeMemory(Stack *); extern void stat_init(cacheinfo **, const char *); extern void pconnHistCount(int, int); +extern void statAvgInit(void); /* To reduce memory fragmentation, we now store the memory version of an * object in fixed size blocks of size PAGE_SIZE and instead of calling @@ -494,6 +495,7 @@ extern void setMaxFD(void); extern time_t getCurrentTime(void); extern void normal_shutdown(void); extern int percent(int, int); +extern int dpercent(double, double); extern void squid_signal(int sig, SIGHDLR *, int flags); extern pid_t readPidFile(void); extern struct in_addr inaddrFromHostent(const struct hostent *hp); @@ -502,6 +504,10 @@ extern double doubleAverage(double, double, int, int); extern void debug_trap(const char *); extern void logsFlush(void); extern char *checkNullString(char *p); +extern void squid_getrusage(struct rusage *r); +extern double rusage_cputime(struct rusage *r); +extern int rusage_maxrss(struct rusage *r); +extern int rusage_pagefaults(struct rusage *r); extern void unlinkdInit(void); extern void unlinkdClose(void); @@ -522,7 +528,6 @@ extern int urlDefaultPort(protocol_t p); extern char *urlClean(char *); extern char *urlCanonicalClean(const request_t *); - extern void useragentOpenLog(void); extern void useragentRotateLog(void); extern void logUserAgent(const char *, const char *); diff --git a/src/stat.cc b/src/stat.cc index 20c1aca70f..5dca38e2f5 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.171 1997/11/14 20:00:39 wessels Exp $ + * $Id: stat.cc,v 1.172 1997/11/15 00:14:51 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -116,6 +116,7 @@ static void proto_newobject(cacheinfo *, protocol_t, int, int); static void proto_purgeobject(cacheinfo *, protocol_t, int); static void proto_touchobject(cacheinfo *, protocol_t, int); static int memoryAccounted(void); +static void statAvgTick(void *notused); #ifdef XMALLOC_STATISTICS static void info_get_mallstat(int, int, StoreEntry *); @@ -125,6 +126,9 @@ static void info_get_mallstat(int, int, StoreEntry *); int client_pconn_hist[PCONN_HIST_SZ]; int server_pconn_hist[PCONN_HIST_SZ]; +#define N_DELTAS 5 +static StatCounters Deltas[N_DELTAS]; + /* process utilization information */ static void statUtilization(cacheinfo * obj, StoreEntry * sentry, const char *desc) @@ -133,7 +137,7 @@ statUtilization(cacheinfo * obj, StoreEntry * sentry, const char *desc) proto_stat *p = &obj->proto_stat_data[PROTO_MAX]; proto_stat *q = NULL; int secs = 0; - secs = (int) (squid_curtime - squid_starttime); + secs = (int) (squid_curtime - squid_start.tv_sec); storeAppendPrintf(sentry, "{ %s\n", desc); /* } */ strcpy(p->protoname, "TOTAL"); p->object_count = 0; @@ -513,11 +517,9 @@ memoryAccounted(void) void info_get(StoreEntry * sentry) { - const char *tod = NULL; - float f; -#if defined(HAVE_GETRUSAGE) && defined(RUSAGE_SELF) struct rusage rusage; -#endif + double cputime; + double runtime; #if HAVE_MSTATS && HAVE_GNUMALLOC_H struct mstats ms; #elif HAVE_MALLINFO @@ -525,26 +527,31 @@ info_get(StoreEntry * sentry) int t; #endif + runtime = tvSubDsec(squid_start, current_time); + if (runtime == 0.0) + runtime = 1.0; storeAppendPrintf(sentry, open_bracket); storeAppendPrintf(sentry, "{Squid Object Cache: Version %s}\n", version_string); - tod = mkrfc1123(squid_starttime); - storeAppendPrintf(sentry, "{Start Time:\t%s}\n", tod); - tod = mkrfc1123(squid_curtime); - storeAppendPrintf(sentry, "{Current Time:\t%s}\n", tod); + storeAppendPrintf(sentry, "{Start Time:\t%s}\n", + mkrfc1123(squid_start.tv_sec)); + storeAppendPrintf(sentry, "{Current Time:\t%s}\n", + mkrfc1123(current_time.tv_sec)); storeAppendPrintf(sentry, "{Connection information for %s:}\n", appname); - storeAppendPrintf(sentry, "{\tNumber of TCP connections:\t%lu}\n", - ntcpconn); - storeAppendPrintf(sentry, "{\tNumber of UDP connections:\t%lu}\n", - nudpconn); - - - f = (float) (squid_curtime - squid_starttime); - storeAppendPrintf(sentry, "{\tConnections per hour:\t%.1f}\n", - f == 0.0 ? 0.0 : ((ntcpconn + nudpconn) / (f / 3600.0))); + storeAppendPrintf(sentry, "{\tNumber of HTTP requests received:\t%u}\n", + Counter.client_http.requests); + storeAppendPrintf(sentry, "{\tNumber of ICP messages received:\t%u}\n", + Counter.icp.pkts_recv); + storeAppendPrintf(sentry, "{\tNumber of ICP messages sent:\t%u}\n", + Counter.icp.pkts_sent); + + storeAppendPrintf(sentry, "{\tHTTP requests per minute:\t%.1f}\n", + Counter.client_http.requests / (runtime / 60.0)); + storeAppendPrintf(sentry, "{\tICP messages per minute:\t%.1f}\n", + (Counter.icp.pkts_sent + Counter.icp.pkts_recv) / (runtime / 60.0)); storeAppendPrintf(sentry, "{\tSelect loop called: %d times, %0.3f ms avg}\n", - select_loops, 1000.0 * f / select_loops); + Counter.select_loops, 1000.0 * runtime / Counter.select_loops); storeAppendPrintf(sentry, "{Cache information for %s:}\n", appname); @@ -555,37 +562,21 @@ info_get(StoreEntry * sentry) storeAppendPrintf(sentry, "{\tStorage LRU Expiration Age:\t%6.2f days}\n", (double) storeExpiredReferenceAge() / 86400.0); storeAppendPrintf(sentry, "{\tRequests given to unlinkd:\t%d}\n", - unlinkd_count); + Counter.unlink.requests); storeAppendPrintf(sentry, "{\tUnused fileno stack count:\t%d}\n", fileno_stack_count); -#if HAVE_GETRUSAGE && defined(RUSAGE_SELF) + squid_getrusage(&rusage); + cputime = rusage_cputime(&rusage); storeAppendPrintf(sentry, "{Resource usage for %s:}\n", appname); -#ifdef _SQUID_SOLARIS_ - /* Solaris 2.5 has getrusage() permission bug -- Arjan de Vet */ - enter_suid(); -#endif - getrusage(RUSAGE_SELF, &rusage); -#ifdef _SQUID_SOLARIS_ - leave_suid(); -#endif - storeAppendPrintf(sentry, "{\tCPU Time: %d seconds (%d user %d sys)}\n", - (int) rusage.ru_utime.tv_sec + (int) rusage.ru_stime.tv_sec, - (int) rusage.ru_utime.tv_sec, - (int) rusage.ru_stime.tv_sec); - storeAppendPrintf(sentry, "{\tCPU Usage: %d%%}\n", - percent(rusage.ru_utime.tv_sec + rusage.ru_stime.tv_sec, - squid_curtime - squid_starttime)); -#if defined(_SQUID_SGI_) || defined(_SQUID_OSF_) || defined(BSD4_4) - storeAppendPrintf(sentry, "{\tMaximum Resident Size: %ld KB}\n", - rusage.ru_maxrss); -#else + storeAppendPrintf(sentry, "{\tUP Time:\t%.3f seconds}\n", runtime); + storeAppendPrintf(sentry, "{\tCPU Time:\t%.3f seconds}\n", cputime); + storeAppendPrintf(sentry, "{\tCPU Usage:\t%d%%}\n", + dpercent(cputime, runtime)); storeAppendPrintf(sentry, "{\tMaximum Resident Size: %ld KB}\n", - (rusage.ru_maxrss * getpagesize()) >> 10); -#endif + rusage_maxrss(&rusage)); storeAppendPrintf(sentry, "{\tPage faults with physical i/o: %ld}\n", - rusage.ru_majflt); -#endif + rusage_pagefaults(&rusage)); #if HAVE_MSTATS && HAVE_GNUMALLOC_H ms = mstats(); @@ -908,3 +899,37 @@ pconnHistDump(StoreEntry * e) storeAppendPrintf(e, "\t%4d %9d\n", i, server_pconn_hist[i]); } } + +void +statAvgInit(void) +{ + memset(Deltas, '\0', N_DELTAS * sizeof(StatCounters)); + eventAdd("statAvgTick", statAvgTick, NULL, 60); +} + +static void +statAvgTick(void *notused) +{ + StatCounters *t = &Deltas[0]; + StatCounters *p = &Deltas[1]; + StatCounters *c = &Counter; + struct rusage rusage; + eventAdd("statAvgTick", statAvgTick, NULL, 60); + memmove(p, t, (N_DELTAS - 1) * sizeof(StatCounters)); + t->client_http.requests = c->client_http.requests - p->client_http.requests; + t->client_http.hits = c->client_http.hits - p->client_http.hits; + t->client_http.errors = c->client_http.errors - p->client_http.errors; + t->client_http.bytes_in = c->client_http.bytes_in - p->client_http.bytes_in; + t->client_http.bytes_out = c->client_http.bytes_out - p->client_http.bytes_out; + t->icp.pkts_sent = c->icp.pkts_sent - p->icp.pkts_sent; + t->icp.pkts_recv = c->icp.pkts_recv - p->icp.pkts_recv; + t->icp.bytes_sent = c->icp.bytes_sent - p->icp.bytes_sent; + t->icp.bytes_recv = c->icp.bytes_recv - p->icp.bytes_recv; + t->unlink.requests = c->unlink.requests - p->unlink.requests; + t->page_faults = c->page_faults - p->page_faults; + t->select_loops = c->select_loops - p->select_loops; + t->cputime = c->cputime - p->cputime; + squid_getrusage(&rusage); + c->page_faults = rusage_pagefaults(&rusage); + c->cputime = rusage_cputime(&rusage); +} diff --git a/src/structs.h b/src/structs.h index 5b5aac94e3..9d18e7c897 100644 --- a/src/structs.h +++ b/src/structs.h @@ -883,3 +883,25 @@ struct _ErrorState { char *reply; } ftp; }; + +struct _StatCounters { + struct { + int requests; + int hits; + int errors; + int bytes_in; + int bytes_out; + } client_http; + struct { + int pkts_sent; + int pkts_recv; + int bytes_sent; + int bytes_recv; + } icp; + struct { + int requests; + } unlink; + int page_faults; + int select_loops; + double cputime; +}; diff --git a/src/tools.cc b/src/tools.cc index d80902cb0c..1d5d2a4646 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.129 1997/11/05 05:29:40 wessels Exp $ + * $Id: tools.cc,v 1.130 1997/11/15 00:14:52 wessels Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -224,30 +224,63 @@ dumpMallocStats(void) #endif /* HAVE_MALLINFO */ } -static void -PrintRusage(void) +void +squid_getrusage(struct rusage *r) { #if HAVE_GETRUSAGE && defined(RUSAGE_SELF) - struct rusage rusage; #ifdef _SQUID_SOLARIS_ /* Solaris 2.5 has getrusage() permission bug -- Arjan de Vet */ enter_suid(); #endif - getrusage(RUSAGE_SELF, &rusage); + getrusage(RUSAGE_SELF, r); #ifdef _SQUID_SOLARIS_ leave_suid(); #endif - fprintf(debug_log, "CPU Usage: user %d sys %d\n", - (int) rusage.ru_utime.tv_sec, (int) rusage.ru_stime.tv_sec); -#if defined(_SQUID_SGI_) || defined(_SQUID_OSF_) || defined(BSD4_4) - fprintf(debug_log, "Maximum Resident Size: %ld KB\n", rusage.ru_maxrss); -#else /* _SQUID_SGI_ */ - fprintf(debug_log, "Maximum Resident Size: %ld KB\n", - (rusage.ru_maxrss * getpagesize()) >> 10); -#endif /* _SQUID_SGI_ */ - fprintf(debug_log, "Page faults with physical i/o: %ld\n", - rusage.ru_majflt); -#endif /* HAVE_GETRUSAGE */ +#else + memset(r, '\0', sizeof(struct rusage)); +#endif +} + +double +rusage_cputime(struct rusage *r) +{ + return (double) r->ru_stime.tv_sec + + (double) r->ru_utime.tv_sec + + (double) r->ru_stime.tv_usec / 1000000.0 + + (double) r->ru_utime.tv_usec / 1000000.0; +} + +int +rusage_maxrss(struct rusage *r) +{ +#if defined(_SQUID_SGI_) + return r->ru_maxrss; +#elif defined(_SQUID_OSF_) + return r->ru_maxrss; +#elif defined(BSD4_4) + return r->ru_maxrss; +#else + return (r->ru_maxrss * getpagesize()) >> 10; +#endif +} + +int +rusage_pagefaults(struct rusage *r) +{ + return r->ru_majflt; +} + + +static void +PrintRusage(void) +{ + struct rusage rusage; + squid_getrusage(&rusage); + fprintf(debug_log, "CPU Usage: %.3f seconds\n", rusage_cputime(&rusage)); + fprintf(debug_log, "Maximum Resident Size: %d KB\n", + rusage_maxrss(&rusage)); + fprintf(debug_log, "Page faults with physical i/o: %d\n", + rusage_pagefaults(&rusage)); } @@ -723,6 +756,12 @@ percent(int a, int b) return b ? ((int) (100.0 * a / b + 0.5)) : 0; } +int +dpercent(double a, double b) +{ + return b ? (100.0 * a / b) : 0.0; +} + void squid_signal(int sig, SIGHDLR * func, int flags) { diff --git a/src/typedefs.h b/src/typedefs.h index 06f6d038fc..787b73d673 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -73,6 +73,7 @@ typedef struct _CommWriteStateData CommWriteStateData; typedef struct _ErrorState ErrorState; typedef struct _dlink_node dlink_node; typedef struct _dlink_list dlink_list; +typedef struct _StatCounters StatCounters; typedef void AIOCB(void *, int aio_return, int aio_errno); typedef void CWCB(int fd, char *, size_t size, int flag, void *data); diff --git a/src/unlinkd.cc b/src/unlinkd.cc index a55cabac1c..cb2bc5c72e 100644 --- a/src/unlinkd.cc +++ b/src/unlinkd.cc @@ -1,5 +1,5 @@ /* - * $Id: unlinkd.cc,v 1.10 1997/10/25 17:23:04 wessels Exp $ + * $Id: unlinkd.cc,v 1.11 1997/11/15 00:14:53 wessels Exp $ * * DEBUG: section 43 Unlink Daemon * AUTHOR: Duane Wessels @@ -177,7 +177,7 @@ unlinkdUnlink(const char *path) NULL, /* Handler */ NULL, /* Handler-data */ xfree); - unlinkd_count++; + Counter.unlink.requests++; } void @@ -194,7 +194,6 @@ unlinkdClose(void) void unlinkdInit(void) { - unlinkd_count = 0; unlinkd_fd = unlinkdCreate(); if (unlinkd_fd < 0) fatal("unlinkdInit: failed to start unlinkd\n");