📄 stat.c
字号:
/* * $Id: stat.c,v 1.311.2.4 1999/04/07 23:27:31 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ * ---------------------------------------------------------- * * Squid is the result of efforts by numerous individuals from the * Internet community. Development is led by Duane Wessels of the * National Laboratory for Applied Network Research and funded by the * National Science Foundation. Squid is Copyrighted (C) 1998 by * Duane Wessels and the University of California San Diego. Please * see the COPYRIGHT file for full details. Squid incorporates * software developed and/or copyrighted by other sources. Please see * the CREDITS file for full details. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */#include "squid.h"#define DEBUG_OPENFD 1typedef int STOBJFLT(const StoreEntry *);typedef struct { StoreEntry *sentry; int bucket; STOBJFLT *filter;} StatObjectsState;/* LOCALS */static const char *describeStatuses(const StoreEntry *);static const char *describeTimestamps(const StoreEntry *);static void statAvgTick(void *notused);static void statAvgDump(StoreEntry *, int minutes, int hours);#if STAT_GRAPHSstatic void statGraphDump(StoreEntry *);#endifstatic void statCountersInit(StatCounters *);static void statCountersInitSpecial(StatCounters *);static void statCountersClean(StatCounters *);static void statCountersCopy(StatCounters * dest, const StatCounters * orig);static double statMedianSvc(int, int);static void statStoreEntry(StoreEntry * s, StoreEntry * e);static double statCPUUsage(int minutes);static OBJH stat_io_get;static OBJH stat_objects_get;static OBJH stat_vmobjects_get;#if DEBUG_OPENFDstatic OBJH statOpenfdObj;#endifstatic EVH statObjects;static OBJH info_get;static OBJH statFiledescriptors;static OBJH statCountersDump;static OBJH statPeerSelect;static OBJH statDigestBlob;static OBJH statAvg5min;static OBJH statAvg60min;static OBJH statUtilization;static OBJH statCountersHistograms;static OBJH statClientRequests;#ifdef XMALLOC_STATISTICSstatic void info_get_mallstat(int, int, StoreEntry *);#endifStatCounters CountHist[N_COUNT_HIST];static int NCountHist = 0;static StatCounters CountHourHist[N_COUNT_HOUR_HIST];static int NCountHourHist = 0;static voidstatUtilization(StoreEntry * e){ storeAppendPrintf(e, "Cache Utilisation:\n"); storeAppendPrintf(e, "\n"); storeAppendPrintf(e, "Last 5 minutes:\n"); if (NCountHist >= 5) statAvgDump(e, 5, 0); else storeAppendPrintf(e, "(no values recorded yet)\n"); storeAppendPrintf(e, "\n"); storeAppendPrintf(e, "Last 15 minutes:\n"); if (NCountHist >= 15) statAvgDump(e, 15, 0); else storeAppendPrintf(e, "(no values recorded yet)\n"); storeAppendPrintf(e, "\n"); storeAppendPrintf(e, "Last hour:\n"); if (NCountHist >= 60) statAvgDump(e, 60, 0); else storeAppendPrintf(e, "(no values recorded yet)\n"); storeAppendPrintf(e, "\n"); storeAppendPrintf(e, "Last 8 hours:\n"); if (NCountHourHist >= 8) statAvgDump(e, 0, 8); else storeAppendPrintf(e, "(no values recorded yet)\n"); storeAppendPrintf(e, "\n"); storeAppendPrintf(e, "Last day:\n"); if (NCountHourHist >= 24) statAvgDump(e, 0, 24); else storeAppendPrintf(e, "(no values recorded yet)\n"); storeAppendPrintf(e, "\n"); storeAppendPrintf(e, "Last 3 days:\n"); if (NCountHourHist >= 72) statAvgDump(e, 0, 72); else storeAppendPrintf(e, "(no values recorded yet)\n"); storeAppendPrintf(e, "\n"); storeAppendPrintf(e, "Totals since cache startup:\n"); statCountersDump(e);}static voidstat_io_get(StoreEntry * sentry){ int i; storeAppendPrintf(sentry, "HTTP I/O\n"); storeAppendPrintf(sentry, "number of reads: %d\n", IOStats.Http.reads); storeAppendPrintf(sentry, "Read Histogram:\n"); for (i = 0; i < 16; i++) { storeAppendPrintf(sentry, "%5d-%5d: %9d %2d%%\n", i ? (1 << (i - 1)) + 1 : 1, 1 << i, IOStats.Http.read_hist[i], percent(IOStats.Http.read_hist[i], IOStats.Http.reads)); } storeAppendPrintf(sentry, "\n"); storeAppendPrintf(sentry, "FTP I/O\n"); storeAppendPrintf(sentry, "number of reads: %d\n", IOStats.Ftp.reads); storeAppendPrintf(sentry, "Read Histogram:\n"); for (i = 0; i < 16; i++) { storeAppendPrintf(sentry, "%5d-%5d: %9d %2d%%\n", i ? (1 << (i - 1)) + 1 : 1, 1 << i, IOStats.Ftp.read_hist[i], percent(IOStats.Ftp.read_hist[i], IOStats.Ftp.reads)); } storeAppendPrintf(sentry, "\n"); storeAppendPrintf(sentry, "Gopher I/O\n"); storeAppendPrintf(sentry, "number of reads: %d\n", IOStats.Gopher.reads); storeAppendPrintf(sentry, "Read Histogram:\n"); for (i = 0; i < 16; i++) { storeAppendPrintf(sentry, "%5d-%5d: %9d %2d%%\n", i ? (1 << (i - 1)) + 1 : 1, 1 << i, IOStats.Gopher.read_hist[i], percent(IOStats.Gopher.read_hist[i], IOStats.Gopher.reads)); } storeAppendPrintf(sentry, "\n"); storeAppendPrintf(sentry, "WAIS I/O\n"); storeAppendPrintf(sentry, "number of reads: %d\n", IOStats.Wais.reads); storeAppendPrintf(sentry, "Read Histogram:\n"); for (i = 0; i < 16; i++) { storeAppendPrintf(sentry, "%5d-%5d: %9d %2d%%\n", i ? (1 << (i - 1)) + 1 : 1, 1 << i, IOStats.Wais.read_hist[i], percent(IOStats.Wais.read_hist[i], IOStats.Wais.reads)); }}static const char *describeStatuses(const StoreEntry * entry){ LOCAL_ARRAY(char, buf, 256); snprintf(buf, 256, "%-13s %-13s %-12s %-12s", storeStatusStr[entry->store_status], memStatusStr[entry->mem_status], swapStatusStr[entry->swap_status], pingStatusStr[entry->ping_status]); return buf;}const char *storeEntryFlags(const StoreEntry * entry){ LOCAL_ARRAY(char, buf, 256); int flags = (int) entry->flags; char *t; buf[0] = '\0'; if (EBIT_TEST(flags, ENTRY_SPECIAL)) strcat(buf, "SPECIAL,"); if (EBIT_TEST(flags, ENTRY_REVALIDATE)) strcat(buf, "REVALIDATE,"); if (EBIT_TEST(flags, DELAY_SENDING)) strcat(buf, "DELAY_SENDING,"); if (EBIT_TEST(flags, RELEASE_REQUEST)) strcat(buf, "RELEASE_REQUEST,"); if (EBIT_TEST(flags, REFRESH_REQUEST)) strcat(buf, "REFRESH_REQUEST,"); if (EBIT_TEST(flags, ENTRY_CACHABLE)) strcat(buf, "CACHABLE,"); if (EBIT_TEST(flags, ENTRY_DISPATCHED)) strcat(buf, "DISPATCHED,"); if (EBIT_TEST(flags, KEY_PRIVATE)) strcat(buf, "PRIVATE,"); if (EBIT_TEST(flags, ENTRY_FWD_HDR_WAIT)) strcat(buf, "FWD_HDR_WAIT,"); if (EBIT_TEST(flags, ENTRY_NEGCACHED)) strcat(buf, "NEGCACHED,"); if (EBIT_TEST(flags, ENTRY_VALIDATED)) strcat(buf, "VALIDATED,"); if (EBIT_TEST(flags, ENTRY_BAD_LENGTH)) strcat(buf, "BAD_LENGTH,"); if (EBIT_TEST(flags, ENTRY_ABORTED)) strcat(buf, "ABORTED,"); if ((t = strrchr(buf, ','))) *t = '\0'; return buf;}static const char *describeTimestamps(const StoreEntry * entry){ LOCAL_ARRAY(char, buf, 256); snprintf(buf, 256, "LV:%-9d LU:%-9d LM:%-9d EX:%-9d", (int) entry->timestamp, (int) entry->lastref, (int) entry->lastmod, (int) entry->expires); return buf;}static voidstatStoreEntry(StoreEntry * s, StoreEntry * e){ MemObject *mem = e->mem_obj; int i; struct _store_client *sc; storeAppendPrintf(s, "KEY %s\n", storeKeyText(e->key)); if (mem) storeAppendPrintf(s, "\t%s %s\n", RequestMethodStr[mem->method], mem->log_url); storeAppendPrintf(s, "\t%s\n", describeStatuses(e)); storeAppendPrintf(s, "\t%s\n", storeEntryFlags(e)); storeAppendPrintf(s, "\t%s\n", describeTimestamps(e)); storeAppendPrintf(s, "\t%d locks, %d clients, %d refs\n", (int) e->lock_count, storePendingNClients(e), (int) e->refcount); storeAppendPrintf(s, "\tSwap File %#08X\n", e->swap_file_number); if (mem != NULL) { storeAppendPrintf(s, "\tinmem_lo: %d\n", (int) mem->inmem_lo); storeAppendPrintf(s, "\tinmem_hi: %d\n", (int) mem->inmem_hi); storeAppendPrintf(s, "\tswapout: %d bytes done, %d queued, FD %d\n", (int) mem->swapout.done_offset, (int) mem->swapout.queue_offset, mem->swapout.fd); for (i = 0, sc = &mem->clients[i]; sc != NULL; sc = sc->next, i++) { if (sc->callback_data == NULL) continue; storeAppendPrintf(s, "\tClient #%d, %p\n", i, sc->callback_data); storeAppendPrintf(s, "\t\tcopy_offset: %d\n", (int) sc->copy_offset); storeAppendPrintf(s, "\t\tseen_offset: %d\n", (int) sc->seen_offset); storeAppendPrintf(s, "\t\tcopy_size: %d\n", (int) sc->copy_size); storeAppendPrintf(s, "\t\tswapin_fd: %d\n", (int) sc->swapin_fd); storeAppendPrintf(s, "\t\tflags:"); if (sc->flags.disk_io_pending) storeAppendPrintf(s, " disk_io_pending"); if (sc->flags.store_copying) storeAppendPrintf(s, " store_copying"); if (sc->flags.copy_event_pending) storeAppendPrintf(s, " copy_event_pending"); storeAppendPrintf(s, "\n"); } } storeAppendPrintf(s, "\n");}/* process objects list */static voidstatObjects(void *data){ StatObjectsState *state = data; StoreEntry *e; hash_link *link_ptr = NULL; hash_link *link_next = NULL; if (state->bucket >= store_hash_buckets) { storeComplete(state->sentry); storeUnlockObject(state->sentry); cbdataFree(state); return; } else if (EBIT_TEST(state->sentry->flags, ENTRY_ABORTED)) { storeUnlockObject(state->sentry); cbdataFree(state); return; } else if (fwdCheckDeferRead(-1, state->sentry)) { eventAdd("statObjects", statObjects, state, 0.1, 1); return; } storeBuffer(state->sentry); debug(49, 3) ("statObjects: Bucket #%d\n", state->bucket); link_next = hash_get_bucket(store_table, state->bucket); while (NULL != (link_ptr = link_next)) { link_next = link_ptr->next; e = (StoreEntry *) link_ptr; if (state->filter && 0 == state->filter(e)) continue; statStoreEntry(state->sentry, e); } state->bucket++; eventAdd("statObjects", statObjects, state, 0.0, 1); storeBufferFlush(state->sentry);}static voidstatObjectsStart(StoreEntry * sentry, STOBJFLT * filter){ StatObjectsState *state = xcalloc(1, sizeof(*state)); state->sentry = sentry; state->filter = filter; storeLockObject(sentry); cbdataAdd(state, cbdataXfree, 0); eventAdd("statObjects", statObjects, state, 0.0, 1);}static voidstat_objects_get(StoreEntry * sentry){ statObjectsStart(sentry, NULL);}static intstatObjectsVmFilter(const StoreEntry * e){ return e->mem_obj ? 1 : 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -