send-announce.cc \
$(SNMP_SOURCE) \
squid.h \
+ SquidMath.h \
+ SquidMath.cc \
SquidNew.cc \
$(SSL_SOURCE) \
stat.cc \
Server.cc \
$(SNMP_SOURCE) \
$(SSL_SOURCE) \
+ SquidMath.h \
+ SquidMath.cc \
stat.cc \
StatHist.cc \
stmem.cc \
tests/stub_cache_manager.cc
nodist_tests_testDiskIO_SOURCES= \
$(SWAP_TEST_GEN_SOURCES) \
+ SquidMath.cc \
+ SquidMath.h \
swap_log_op.cc
tests_testDiskIO_LDADD = \
$(SWAP_TEST_LDADD) \
Server.cc \
$(SNMP_SOURCE) \
$(SSL_SOURCE) \
+ SquidMath.h \
+ SquidMath.cc \
stat.cc \
StatHist.cc \
stmem.cc \
Server.cc \
$(SNMP_SOURCE) \
$(SSL_SOURCE) \
+ SquidMath.h \
+ SquidMath.cc \
stat.cc \
StatHist.cc \
stmem.cc \
Server.cc \
$(SNMP_SOURCE) \
$(SSL_SOURCE) \
+ SquidMath.h \
+ SquidMath.cc \
stat.cc \
StatHist.cc \
stmem.cc \
Server.cc \
$(SNMP_SOURCE) \
$(SSL_SOURCE) \
+ SquidMath.h \
+ SquidMath.cc \
stat.cc \
StatHist.cc \
stmem.cc \
nodist_tests_testStore_SOURCES= \
$(TESTSOURCES) \
+ SquidMath.cc \
+ SquidMath.h \
swap_log_op.cc
tests_testStore_LDADD= \
$(SWAP_TEST_SOURCES)
nodist_tests_testUfs_SOURCES = \
$(SWAP_TEST_GEN_SOURCES) \
+ SquidMath.cc \
+ SquidMath.h \
swap_log_op.cc
tests_testUfs_LDADD = \
$(SWAP_TEST_LDADD) \
Server.cc \
$(SNMP_SOURCE) \
$(SSL_SOURCE) \
+ SquidMath.h \
+ SquidMath.cc \
stat.cc \
StatHist.cc \
stmem.cc \
*/
#include "squid.h"
-#include "event.h"
-#include "CacheManager.h"
#ifdef USE_XPROF_STATS
+
+#include "CacheManager.h"
+#include "event.h"
+#include "SquidMath.h"
#include "Store.h"
/* Private stuff */
hist->count ? hist->summ / hist->count : 0,
hist->worst,
hist->count / time_frame,
- dpercent((double) hist->summ, (double) hist->delta));
+ Math::doublePercent((double) hist->summ, (double) hist->delta));
}
static void
--- /dev/null
+#include "config.h"
+#include "SquidMath.h"
+
+int
+Math::intPercent(const int a, const int b)
+{
+ return b ? ((int) (100.0 * a / b + 0.5)) : 0;
+}
+
+double
+Math::doublePercent(const double a, const double b)
+{
+ return b ? (100.0 * a / b) : 0.0;
+}
+
+double
+Math::doubleAverage(const double cur, const double newD, int N, const int max)
+{
+ if (N > max)
+ N = max;
+
+ return (cur * (N - 1.0) + newD) / N;
+}
+
+int
+Math::intAverage(const int cur, const int newI, int n, const int max)
+{
+ if (n > max)
+ n = max;
+
+ return (cur * (n - 1) + newI) / n;
+}
--- /dev/null
+#ifndef _SQUID_SRC_SQUIDMATH_H
+#define _SQUID_SRC_SQUIDMATH_H
+
+/* Math functions we define locally for Squid */
+namespace Math {
+
+extern int intPercent(int a, int b);
+extern double doublePercent(double, double);
+extern int intAverage(int, int, int, int);
+extern double doubleAverage(double, double, int, int);
+
+}; // namespace Math
+
+#endif /* _SQUID_SRC_SQUIDMATH_H */
#include "event.h"
#include "CacheManager.h"
#include "ClientInfo.h"
+#include "SquidMath.h"
#include "SquidTime.h"
#include "Store.h"
if (LOG_UDP_HIT == l)
icp_hits += c->Icp.result_hist[l];
- storeAppendPrintf(sentry,
- " %-20.20s %7d %3d%%\n",
- log_tags[l],
- c->Icp.result_hist[l],
- percent(c->Icp.result_hist[l], c->Icp.n_requests));
+ storeAppendPrintf(sentry, " %-20.20s %7d %3d%%\n",log_tags[l], c->Icp.result_hist[l], Math::intPercent(c->Icp.result_hist[l], c->Icp.n_requests));
}
- storeAppendPrintf(sentry, " HTTP Requests %d\n",
- c->Http.n_requests);
+ storeAppendPrintf(sentry, " HTTP Requests %d\n", c->Http.n_requests);
for (l = LOG_TAG_NONE; l < LOG_TYPE_MAX; ++l) {
if (c->Http.result_hist[l] == 0)
" %-20.20s %7d %3d%%\n",
log_tags[l],
c->Http.result_hist[l],
- percent(c->Http.result_hist[l], c->Http.n_requests));
+ Math::intPercent(c->Http.result_hist[l], c->Http.n_requests));
}
storeAppendPrintf(sentry, "\n");
storeAppendPrintf(sentry, "TOTALS\n");
storeAppendPrintf(sentry, "ICP : %d Queries, %d Hits (%3d%%)\n",
- icp_total, icp_hits, percent(icp_hits, icp_total));
+ icp_total, icp_hits, Math::intPercent(icp_hits, icp_total));
storeAppendPrintf(sentry, "HTTP: %d Requests, %d Hits (%3d%%)\n",
- http_total, http_hits, percent(http_hits, http_total));
+ http_total, http_hits, Math::intPercent(http_hits, http_total));
}
static void
#include "StoreFScoss.h"
#include "Parsing.h"
#include "swap_log_op.h"
+//#include "SquidMath.h"
#define STORE_META_BUFSZ 4096
/* is this applicable? I Hope not .. */
storeAppendPrintf(sentry, "Filemap bits in use: %d of %d (%d%%)\n",
SD->map->n_files_in_map, SD->map->max_n_files,
- percent(SD->map->n_files_in_map, SD->map->max_n_files));
+ Math::intPercent(SD->map->n_files_in_map, SD->map->max_n_files));
#endif
// storeAppendPrintf(&sentry, "Pending operations: %d out of %d\n", io->aq.aq_numpending, MAX_ASYNCOP);
#include "DiskIO/DiskIOStrategy.h"
#include "DiskIO/DiskIOModule.h"
#include "Parsing.h"
+#include "SquidMath.h"
#include "SquidTime.h"
#include "SwapDir.h"
#include "swap_log_op.h"
100.0 * cur_size / max_size);
storeAppendPrintf(&sentry, "Filemap bits in use: %d of %d (%d%%)\n",
map->n_files_in_map, map->max_n_files,
- percent(map->n_files_in_map, map->max_n_files));
+ Math::intPercent(map->n_files_in_map, map->max_n_files));
x = storeDirGetUFSStats(path, &totl_kb, &free_kb, &totl_in, &free_in);
if (0 == x) {
storeAppendPrintf(&sentry, "Filesystem Space in use: %d/%d KB (%d%%)\n",
totl_kb - free_kb,
totl_kb,
- percent(totl_kb - free_kb, totl_kb));
+ Math::intPercent(totl_kb - free_kb, totl_kb));
storeAppendPrintf(&sentry, "Filesystem Inodes in use: %d/%d (%d%%)\n",
totl_in - free_in,
totl_in,
- percent(totl_in - free_in, totl_in));
+ Math::intPercent(totl_in - free_in, totl_in));
}
storeAppendPrintf(&sentry, "Flags:");
#include "squid.h"
#include "helper.h"
+#include "SquidMath.h"
#include "SquidTime.h"
#include "Store.h"
#include "comm.h"
srv->dispatch_time = r->dispatch_time;
- hlp->stats.avg_svc_time =
- intAverage(hlp->stats.avg_svc_time,
- tvSubMsec(r->dispatch_time, current_time),
- hlp->stats.replies, REDIRECT_AV_FACTOR);
+ hlp->stats.avg_svc_time = Math::intAverage(hlp->stats.avg_svc_time, tvSubMsec(r->dispatch_time, current_time), hlp->stats.replies, REDIRECT_AV_FACTOR);
helperRequestFree(r);
} else {
hlp->stats.replies++;
srv->answer_time = current_time;
hlp->stats.avg_svc_time =
- intAverage(hlp->stats.avg_svc_time,
- tvSubMsec(srv->dispatch_time, current_time),
- hlp->stats.replies, REDIRECT_AV_FACTOR);
+ Math::intAverage(hlp->stats.avg_svc_time,
+ tvSubMsec(srv->dispatch_time, current_time),
+ hlp->stats.replies, REDIRECT_AV_FACTOR);
if (called)
helperStatefulServerDone(srv);
#include "MemObject.h"
#include "PeerDigest.h"
#include "PeerSelectState.h"
+#include "SquidMath.h"
#include "SquidTime.h"
#include "Store.h"
#include "icmp/net_db.h"
if (p->options.weighted_roundrobin)
rtt_av_factor = RTT_BACKGROUND_AV_FACTOR;
- p->stats.rtt = intAverage(p->stats.rtt, rtt,
- p->stats.pings_acked, rtt_av_factor);
+ p->stats.rtt = Math::intAverage(p->stats.rtt, rtt, p->stats.pings_acked, rtt_av_factor);
}
#if USE_HTCP
if (cbdataReferenceValid(psstate->callback_data)) {
peer *p = (peer *)psstate->callback_data;
p->mcast.flags.counting = 0;
- p->mcast.avg_n_members = doubleAverage(p->mcast.avg_n_members,
- (double) psstate->ping.n_recv,
- ++p->mcast.n_times_counted,
- 10);
+ p->mcast.avg_n_members = Math::doubleAverage(p->mcast.avg_n_members, (double) psstate->ping.n_recv, ++p->mcast.n_times_counted, 10);
debugs(15, 1, "Group " << p->host << ": " << psstate->ping.n_recv <<
" replies, "<< std::setw(4)<< std::setprecision(2) <<
p->mcast.avg_n_members <<" average, RTT " << p->stats.rtt);
if (p->options.weighted_roundrobin)
rtt_av_factor = RTT_BACKGROUND_AV_FACTOR;
- p->stats.rtt = intAverage(p->stats.rtt, rtt, psstate->ping.n_recv, rtt_av_factor);
+ p->stats.rtt = Math::intAverage(p->stats.rtt, rtt, psstate->ping.n_recv, rtt_av_factor);
}
static void
storeAppendPrintf(sentry, "PINGS ACKED: %8d %3d%%\n",
e->stats.pings_acked,
- percent(e->stats.pings_acked, e->stats.pings_sent));
+ Math::intPercent(e->stats.pings_acked, e->stats.pings_sent));
}
- storeAppendPrintf(sentry, "IGNORED : %8d %3d%%\n",
- e->stats.ignored_replies,
- percent(e->stats.ignored_replies, e->stats.pings_acked));
+ storeAppendPrintf(sentry, "IGNORED : %8d %3d%%\n", e->stats.ignored_replies, Math::intPercent(e->stats.ignored_replies, e->stats.pings_acked));
if (!e->options.no_query) {
storeAppendPrintf(sentry, "Histogram of PINGS ACKED:\n");
if (e->options.htcp) {
storeAppendPrintf(sentry, "\tMisses\t%8d %3d%%\n",
e->htcp.counts[0],
- percent(e->htcp.counts[0], e->stats.pings_acked));
+ Math::intPercent(e->htcp.counts[0], e->stats.pings_acked));
storeAppendPrintf(sentry, "\tHits\t%8d %3d%%\n",
e->htcp.counts[1],
- percent(e->htcp.counts[1], e->stats.pings_acked));
+ Math::intPercent(e->htcp.counts[1], e->stats.pings_acked));
} else {
#endif
storeAppendPrintf(sentry, " %12.12s : %8d %3d%%\n",
icp_opcode_str[op],
e->icp.counts[op],
- percent(e->icp.counts[op], e->stats.pings_acked));
+ Math::intPercent(e->icp.counts[op], e->stats.pings_acked));
}
#if USE_HTCP
storeAppendPrintf(sentry, "\n");
}
- storeAppendPrintf(sentry, "keep-alive ratio: %d%%\n",
- percent(e->stats.n_keepalives_recv, e->stats.n_keepalives_sent));
+ storeAppendPrintf(sentry, "keep-alive ratio: %d%%\n", Math::intPercent(e->stats.n_keepalives_recv, e->stats.n_keepalives_sent));
}
}
SQUIDCEXTERN void writePidFile(void);
SQUIDCEXTERN void setSocketShutdownLifetimes(int);
SQUIDCEXTERN void setMaxFD(void);
-SQUIDCEXTERN int percent(int, int);
-SQUIDCEXTERN double dpercent(double, double);
SQUIDCEXTERN void squid_signal(int sig, SIGHDLR *, int flags);
SQUIDCEXTERN pid_t readPidFile(void);
SQUIDCEXTERN void keepCapabilities(void);
/* AYJ debugs function to show locations being reset with memset() */
SQUIDCEXTERN void *xmemset(void *dst, int, size_t);
-SQUIDCEXTERN int intAverage(int, int, int, int);
-SQUIDCEXTERN double doubleAverage(double, double, int, int);
SQUIDCEXTERN void debug_trap(const char *);
SQUIDCEXTERN void logsFlush(void);
SQUIDCEXTERN const char *checkNullString(const char *p);
#include "cache_snmp.h"
#include "Store.h"
#include "mem_node.h"
+#include "SquidMath.h"
#include "SquidTime.h"
/************************************************************************
case PERF_SYS_CPUUSAGE:
squid_getrusage(&rusage);
Answer = snmp_var_new_integer(Var->name, Var->name_length,
- (snint) dpercent(rusage_cputime(&rusage), tvSubDsec(squid_start, current_time)),
+ (snint) Math::doublePercent(rusage_cputime(&rusage), tvSubDsec(squid_start, current_time)),
ASN_INTEGER);
break;
#include "client_side_request.h"
#include "client_side.h"
#include "MemBuf.h"
+#include "SquidMath.h"
#include "SquidTime.h"
/* these are included because they expose stats calls */
i ? (1 << (i - 1)) + 1 : 1,
1 << i,
IOStats.Http.read_hist[i],
- percent(IOStats.Http.read_hist[i], IOStats.Http.reads));
+ Math::intPercent(IOStats.Http.read_hist[i], IOStats.Http.reads));
}
storeAppendPrintf(sentry, "\n");
i ? (1 << (i - 1)) + 1 : 1,
1 << i,
IOStats.Ftp.read_hist[i],
- percent(IOStats.Ftp.read_hist[i], IOStats.Ftp.reads));
+ Math::intPercent(IOStats.Ftp.read_hist[i], IOStats.Ftp.reads));
}
storeAppendPrintf(sentry, "\n");
i ? (1 << (i - 1)) + 1 : 1,
1 << i,
IOStats.Gopher.read_hist[i],
- percent(IOStats.Gopher.read_hist[i], IOStats.Gopher.reads));
+ Math::intPercent(IOStats.Gopher.read_hist[i], IOStats.Gopher.reads));
}
storeAppendPrintf(sentry, "\n");
store_swap_size);
storeAppendPrintf(sentry, "\tStorage Swap capacity:\t%4.1f%% used, %4.1f%% free\n",
- dpercent(store_swap_size, Store::Root().maxSize()),
- dpercent((Store::Root().maxSize() - store_swap_size), Store::Root().maxSize()));
+ Math::doublePercent(store_swap_size, Store::Root().maxSize()),
+ Math::doublePercent((Store::Root().maxSize() - store_swap_size), Store::Root().maxSize()));
storeAppendPrintf(sentry, "\tStorage Mem size:\t%lu KB\n",
(unsigned long)mem_node::StoreMemSize() >> 10);
storeAppendPrintf(sentry, "\tStorage Mem capacity:\t%4.1f%% used, %4.1f%% free\n",
- dpercent(mem_node::InUseCount(), store_pages_max),
- dpercent((store_pages_max - mem_node::InUseCount()), store_pages_max));
+ Math::doublePercent(mem_node::InUseCount(), store_pages_max),
+ Math::doublePercent((store_pages_max - mem_node::InUseCount()), store_pages_max));
storeAppendPrintf(sentry, "\tMean Object Size:\t%0.2f KB\n",
n_disk_objects ? (double) store_swap_size / n_disk_objects : 0.0);
storeAppendPrintf(sentry, "\tCPU Time:\t%.3f seconds\n", cputime);
storeAppendPrintf(sentry, "\tCPU Usage:\t%.2f%%\n",
- dpercent(cputime, runtime));
+ Math::doublePercent(cputime, runtime));
storeAppendPrintf(sentry, "\tCPU Usage, 5 minute avg:\t%.2f%%\n",
statCPUUsage(5));
ms.bytes_total >> 10);
storeAppendPrintf(sentry, "\tTotal free: %6d KB %d%%\n",
- ms.bytes_free >> 10, percent(ms.bytes_free, ms.bytes_total));
+ ms.bytes_free >> 10, Math::intPercent(ms.bytes_free, ms.bytes_total));
#elif HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
t = mp.uordblks + mp.usmblks + mp.hblkhd;
storeAppendPrintf(sentry, "\tTotal in use: %6d KB %d%%\n",
- t >> 10, percent(t, mp.arena + mp.hblkhd));
+ t >> 10, Math::intPercent(t, mp.arena + mp.hblkhd));
t = mp.fsmblks + mp.fordblks;
storeAppendPrintf(sentry, "\tTotal free: %6d KB %d%%\n",
- t >> 10, percent(t, mp.arena + mp.hblkhd));
+ t >> 10, Math::intPercent(t, mp.arena + mp.hblkhd));
t = mp.arena + mp.hblkhd;
#if !(HAVE_MSTATS && HAVE_GNUMALLOC_H) && HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
storeAppendPrintf(sentry, "\tTotal accounted: %6d KB %3d%%\n",
- statMemoryAccounted() >> 10, percent(statMemoryAccounted(), t));
+ statMemoryAccounted() >> 10, Math::intPercent(statMemoryAccounted(), t));
#else
storeAppendPrintf(sentry, "\tmemPool accounted: %6d KB %3d%%\n",
(int) mp_stats.TheMeter->alloc.level >> 10,
- percent(mp_stats.TheMeter->alloc.level, t));
+ Math::intPercent(mp_stats.TheMeter->alloc.level, t));
storeAppendPrintf(sentry, "\tmemPool unaccounted: %6d KB %3d%%\n",
(t - (int) mp_stats.TheMeter->alloc.level) >> 10,
- percent((t - mp_stats.TheMeter->alloc.level), t));
+ Math::intPercent((t - mp_stats.TheMeter->alloc.level), t));
#endif
storeAppendPrintf(sentry, "\tmemPoolAlloc calls: %9.0f\n",
storeAppendPrintf(sentry, "cpu_time = %f seconds\n", ct);
storeAppendPrintf(sentry, "wall_time = %f seconds\n", dt);
- storeAppendPrintf(sentry, "cpu_usage = %f%%\n", dpercent(ct, dt));
+ storeAppendPrintf(sentry, "cpu_usage = %f%%\n", Math::doublePercent(ct, dt));
}
static void
statCPUUsage(int minutes)
{
assert(minutes < N_COUNT_HIST);
- return dpercent(CountHist[0].cputime - CountHist[minutes].cputime,
+ return Math::doublePercent(CountHist[0].cputime - CountHist[minutes].cputime,
tvSubDsec(CountHist[minutes].timestamp, CountHist[0].timestamp));
}
statRequestHitRatio(int minutes)
{
assert(minutes < N_COUNT_HIST);
- return dpercent(CountHist[0].client_http.hits -
+ return Math::doublePercent(CountHist[0].client_http.hits -
CountHist[minutes].client_http.hits,
CountHist[0].client_http.requests -
CountHist[minutes].client_http.requests);
statRequestHitMemoryRatio(int minutes)
{
assert(minutes < N_COUNT_HIST);
- return dpercent(CountHist[0].client_http.mem_hits -
+ return Math::doublePercent(CountHist[0].client_http.mem_hits -
CountHist[minutes].client_http.mem_hits,
CountHist[0].client_http.hits -
CountHist[minutes].client_http.hits);
statRequestHitDiskRatio(int minutes)
{
assert(minutes < N_COUNT_HIST);
- return dpercent(CountHist[0].client_http.disk_hits -
+ return Math::doublePercent(CountHist[0].client_http.disk_hits -
CountHist[minutes].client_http.disk_hits,
CountHist[0].client_http.hits -
CountHist[minutes].client_http.hits);
#endif
if (c > s)
- return dpercent(c - s, c);
+ return Math::doublePercent(c - s, c);
else
- return (-1.0 * dpercent(s - c, c));
+ return (-1.0 * Math::doublePercent(s - c, c));
}
static void
#include "squid.h"
#include "Store.h"
#include "MemObject.h"
+#include "SquidMath.h"
#include "SquidTime.h"
#include "SwapDir.h"
#include "swap_log_op.h"
storeAppendPrintf(&output, "Current Store Swap Size: %8lu KB\n",
store_swap_size);
storeAppendPrintf(&output, "Current Capacity : %d%% used, %d%% free\n",
- percent((int) store_swap_size, (int) maxSize()),
- percent((int) (maxSize() - store_swap_size), (int) maxSize()));
+ Math::intPercent((int) store_swap_size, (int) maxSize()),
+ Math::intPercent((int) (maxSize() - store_swap_size), (int) maxSize()));
/* FIXME Here we should output memory statistics */
/* now the swapDir */
#include "fde.h"
#include "MemBuf.h"
#include "wordlist.h"
+#include "SquidMath.h"
#include "SquidTime.h"
#include "ip/IpIntercept.h"
(int) (ms.bytes_total >> 10));
fprintf(debug_log, "\tTotal free: %6d KB %d%%\n",
(int) (ms.bytes_free >> 10),
- percent(ms.bytes_free, ms.bytes_total));
+ Math::intPercent(ms.bytes_free, ms.bytes_total));
#elif HAVE_MALLINFO && HAVE_STRUCT_MALLINFO
struct mallinfo mp;
t = mp.uordblks + mp.usmblks + mp.hblkhd;
fprintf(debug_log, "\tTotal in use: %6d KB %d%%\n",
- t >> 10, percent(t, mp.arena));
+ t >> 10, Math::intPercent(t, mp.arena));
t = mp.fsmblks + mp.fordblks;
fprintf(debug_log, "\tTotal free: %6d KB %d%%\n",
- t >> 10, percent(t, mp.arena));
+ t >> 10, Math::intPercent(t, mp.arena));
#if HAVE_STRUCT_MALLINFO_MXFAST
#endif /* RLIMIT_VMEM */
}
-int
-percent(int a, int b)
-{
- return b ? ((int) (100.0 * a / b + 0.5)) : 0;
-}
-
-double
-dpercent(double a, double b)
-{
- return b ? (100.0 * a / b) : 0.0;
-}
-
void
squid_signal(int sig, SIGHDLR * func, int flags)
{
#endif
}
-double
-doubleAverage(double cur, double newD, int N, int max)
-{
- if (N > max)
- N = max;
-
- return (cur * (N - 1.0) + newD) / N;
-}
-
-int
-intAverage(int cur, int newI, int n, int max)
-{
- if (n > max)
- n = max;
-
- return (cur * (n - 1) + newI) / n;
-}
-
void
logsFlush(void)
{