#ifndef SQUID__SRC_CLIENTINFO_H
#define SQUID__SRC_CLIENTINFO_H
+#include "base/ByteCounter.h"
#include "cbdata.h"
#include "enums.h"
#include "hash.h"
#include "ip/Address.h"
#include "LogTags.h"
#include "typedefs.h"
+
#include <deque>
#if USE_DELAY_POOLS
struct {
int result_hist[LOG_TYPE_MAX];
int n_requests;
- kb_t kbytes_in;
- kb_t kbytes_out;
- kb_t hit_kbytes_out;
+ ByteCounter kbytes_in;
+ ByteCounter kbytes_out;
+ ByteCounter hit_kbytes_out;
} Http, Icp;
struct {
#if USE_CACHE_DIGESTS
#include "cbdata.h"
-/* for CacheDigestGuessStats */
#include "StatCounters.h"
class Version
struct {
int msgs;
- kb_t kbytes;
+ ByteCounter kbytes;
} sent, recv;
} stats;
};
#ifndef STATCOUNTERS_H_
#define STATCOUNTERS_H_
+#include "base/ByteCounter.h"
#include "StatHist.h"
#if USE_CACHE_DIGESTS
int mem_hits;
int disk_hits;
int errors;
- kb_t kbytes_in;
- kb_t kbytes_out;
- kb_t hit_kbytes_out;
+ ByteCounter kbytes_in;
+ ByteCounter kbytes_out;
+ ByteCounter hit_kbytes_out;
StatHist missSvcTime;
StatHist nearMissSvcTime;
StatHist nearHitSvcTime;
struct {
int requests;
int errors;
- kb_t kbytes_in;
- kb_t kbytes_out;
+ ByteCounter kbytes_in;
+ ByteCounter kbytes_out;
} all , http, ftp, other;
} server;
int hits_recv;
int replies_queued;
int replies_dropped;
- kb_t kbytes_sent;
- kb_t q_kbytes_sent;
- kb_t r_kbytes_sent;
- kb_t kbytes_recv;
- kb_t q_kbytes_recv;
- kb_t r_kbytes_recv;
+ ByteCounter kbytes_sent;
+ ByteCounter q_kbytes_sent;
+ ByteCounter r_kbytes_sent;
+ ByteCounter kbytes_recv;
+ ByteCounter q_kbytes_recv;
+ ByteCounter r_kbytes_recv;
StatHist querySvcTime;
StatHist replySvcTime;
int query_timeouts;
struct {
int times_used;
- kb_t kbytes_sent;
- kb_t kbytes_recv;
- kb_t memory;
+ ByteCounter kbytes_sent;
+ ByteCounter kbytes_recv;
+ ByteCounter memory;
int msgs_sent;
int msgs_recv;
#if USE_CACHE_DIGESTS
--- /dev/null
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SRC_BYTECOUNTER_H
+#define SQUID_SRC_BYTECOUNTER_H
+
+/// counter for accumulating byte values
+class ByteCounter
+{
+public:
+ ByteCounter() : bytes(0), kb(0) {}
+
+ ByteCounter &operator +=(size_t v) {
+ bytes += v;
+ kb += (bytes >> 10);
+ bytes &= 0x3FF;
+ return *this;
+ }
+
+public:
+ size_t bytes;
+ size_t kb;
+};
+
+#endif /* SQUID_SRC_BYTECOUNTER_H */
+
AsyncJobCalls.h \
AsyncCallQueue.cc \
AsyncCallQueue.h \
+ ByteCounter.h \
CbcPointer.h \
CbDataList.h \
CharacterSet.h \
if (p == AnyP::PROTO_HTTP) {
++ c->Http.n_requests;
++ c->Http.result_hist[ltype.oldType];
- kb_incr(&c->Http.kbytes_out, size);
+ c->Http.kbytes_out += size;
if (ltype.isTcpHit())
- kb_incr(&c->Http.hit_kbytes_out, size);
+ c->Http.hit_kbytes_out += size;
} else if (p == AnyP::PROTO_ICP) {
++ c->Icp.n_requests;
++ c->Icp.result_hist[ltype.oldType];
- kb_incr(&c->Icp.kbytes_out, size);
+ c->Icp.kbytes_out += size;
if (LOG_UDP_HIT == ltype.oldType)
- kb_incr(&c->Icp.hit_kbytes_out, size);
+ c->Icp.hit_kbytes_out += size;
}
c->last_seen = squid_curtime;
if (size == 0)
return;
- kb_incr(&statCounter.client_http.kbytes_out, size);
+ statCounter.client_http.kbytes_out += size;
if (logType.isTcpHit())
- kb_incr(&statCounter.client_http.hit_kbytes_out, size);
+ statCounter.client_http.hit_kbytes_out += size;
}
/**
return;
case Comm::OK:
- kb_incr(&(statCounter.client_http.kbytes_in), rd.size);
+ statCounter.client_http.kbytes_in += rd.size;
if (!receivedFirstByte_)
receivedFirstByte();
// may comm_close or setReplyToError
if (io.size > 0) {
fd_bytes(io.fd, io.size, FD_WRITE);
- kb_incr(&(statCounter.server.all.kbytes_out), io.size);
+ statCounter.server.all.kbytes_out += io.size;
// kids should increment their counters
}
debugs(9, 3, "FD " << io.fd << ", Read " << io.size << " bytes");
if (io.size > 0) {
- kb_incr(&(statCounter.server.all.kbytes_in), io.size);
- kb_incr(&(statCounter.server.ftp.kbytes_in), io.size);
+ statCounter.server.all.kbytes_in += io.size;
+ statCounter.server.ftp.kbytes_in += io.size;
}
if (io.flag == Comm::ERR_CLOSING)
if (io.size > 0) {
fd_bytes(io.fd, io.size, FD_WRITE);
- kb_incr(&(statCounter.server.all.kbytes_out), io.size);
- kb_incr(&(statCounter.server.ftp.kbytes_out), io.size);
+ statCounter.server.all.kbytes_out += io.size;
+ statCounter.server.ftp.kbytes_out += io.size;
}
if (io.flag == Comm::ERR_CLOSING)
debugs(9, 3, "FD " << io.fd << " Read " << io.size << " bytes");
if (io.size > 0) {
- kb_incr(&(statCounter.server.all.kbytes_in), io.size);
- kb_incr(&(statCounter.server.ftp.kbytes_in), io.size);
+ statCounter.server.all.kbytes_in += io.size;
+ statCounter.server.ftp.kbytes_in += io.size;
}
if (io.flag == Comm::ERR_CLOSING)
Ftp::Client::sentRequestBody(const CommIoCbParams &io)
{
if (io.size > 0)
- kb_incr(&(statCounter.server.ftp.kbytes_out), io.size);
+ statCounter.server.ftp.kbytes_out += io.size;
::Client::sentRequestBody(io);
}
delayId.bytesIn(len);
#endif
- kb_incr(&(statCounter.server.all.kbytes_in), len);
- kb_incr(&(statCounter.server.other.kbytes_in), len);
+ statCounter.server.all.kbytes_in += len;
+ statCounter.server.other.kbytes_in += len;
}
debugs(10, 5, HERE << conn << " read len=" << len);
if (size > 0) {
fd_bytes(conn->fd, size, FD_WRITE);
- kb_incr(&(statCounter.server.all.kbytes_out), size);
- kb_incr(&(statCounter.server.other.kbytes_out), size);
+ statCounter.server.all.kbytes_out += size;
+ statCounter.server.other.kbytes_out += size;
}
if (errflag) {
delayId.bytesIn(rd.size);
#endif
- kb_incr(&(statCounter.server.all.kbytes_in), rd.size);
- kb_incr(&(statCounter.server.http.kbytes_in), rd.size);
+ statCounter.server.all.kbytes_in += rd.size;
+ statCounter.server.http.kbytes_in += rd.size;
++ IOStats.Http.reads;
int bin = 0;
if (io.size > 0) {
fd_bytes(io.fd, io.size, FD_WRITE);
- kb_incr(&(statCounter.server.all.kbytes_out), io.size);
- kb_incr(&(statCounter.server.http.kbytes_out), io.size);
+ statCounter.server.all.kbytes_out += io.size;
+ statCounter.server.http.kbytes_out += io.size;
}
if (io.flag == Comm::ERR_CLOSING)
HttpStateData::sentRequestBody(const CommIoCbParams &io)
{
if (io.size > 0)
- kb_incr(&statCounter.server.http.kbytes_out, io.size);
+ statCounter.server.http.kbytes_out += io.size;
Client::sentRequestBody(io);
}
if (SENT == which) {
++statCounter.icp.pkts_sent;
- kb_incr(&statCounter.icp.kbytes_sent, len);
+ statCounter.icp.kbytes_sent += len;
if (ICP_QUERY == icp->opcode) {
++statCounter.icp.queries_sent;
- kb_incr(&statCounter.icp.q_kbytes_sent, len);
+ statCounter.icp.q_kbytes_sent += len;
} else {
++statCounter.icp.replies_sent;
- kb_incr(&statCounter.icp.r_kbytes_sent, len);
+ statCounter.icp.r_kbytes_sent += len;
/* this is the sent-reply service time */
statCounter.icp.replySvcTime.count(delay);
}
++statCounter.icp.hits_sent;
} else if (RECV == which) {
++statCounter.icp.pkts_recv;
- kb_incr(&statCounter.icp.kbytes_recv, len);
+ statCounter.icp.kbytes_recv += len;
if (ICP_QUERY == icp->opcode) {
++statCounter.icp.queries_recv;
- kb_incr(&statCounter.icp.q_kbytes_recv, len);
+ statCounter.icp.q_kbytes_recv += len;
} else {
++statCounter.icp.replies_recv;
- kb_incr(&statCounter.icp.r_kbytes_recv, len);
+ statCounter.icp.r_kbytes_recv += len;
/* statCounter.icp.querySvcTime set in clientUpdateCounters */
}
pd->times.received = squid_curtime;
pd->times.req_delay = fetch->resp_time;
- kb_incr(&pd->stats.sent.kbytes, (size_t) fetch->sent.bytes);
- kb_incr(&pd->stats.recv.kbytes, (size_t) fetch->recv.bytes);
+ pd->stats.sent.kbytes += fetch->sent.bytes;
+ pd->stats.recv.kbytes += fetch->recv.bytes;
pd->stats.sent.msgs += fetch->sent.msg;
pd->stats.recv.msgs += fetch->recv.msg;
}
/* update global stats */
- kb_incr(&statCounter.cd.kbytes_sent, (size_t) fetch->sent.bytes);
-
- kb_incr(&statCounter.cd.kbytes_recv, (size_t) fetch->recv.bytes);
-
+ statCounter.cd.kbytes_sent += fetch->sent.bytes;
+ statCounter.cd.kbytes_recv += fetch->recv.bytes;
statCounter.cd.msgs_sent += fetch->sent.msg;
-
statCounter.cd.msgs_recv += fetch->recv.msg;
delete fetch;
pd->cd = cacheDigestCreate(cblock.capacity, cblock.bits_per_entry);
if (cblock.mask_size >= freed_size)
- kb_incr(&statCounter.cd.memory, cblock.mask_size - freed_size);
+ statCounter.cd.memory += (cblock.mask_size - freed_size);
}
assert(pd->cd);
if (io.flag == Comm::OK && bodyPipe != NULL) {
if (io.size > 0) {
- kb_incr(&(statCounter.client_http.kbytes_in), io.size);
+ statCounter.client_http.kbytes_in += io.size;
char *const current_buf = uploadBuf + uploadAvailSize;
if (io.buf != current_buf)
void setSystemLimits(void) STUB
void squid_signal(int sig, SIGHDLR * func, int flags) STUB
void logsFlush(void) STUB
-void kb_incr(kb_t * k, size_t v) STUB
void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm) STUB
void parseEtcHosts(void) STUB
int getMyPort(void) STUB_RETVAL(0)
fflush(debug_log);
}
-void
-kb_incr(kb_t * k, size_t v)
-{
- k->bytes += v;
- k->kb += (k->bytes >> 10);
- k->bytes &= 0x3FF;
-}
-
void
debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm)
{
/// Default is APP_SHORTNAME ('squid').
extern SBuf service_name;
-void kb_incr(kb_t *, size_t);
void parseEtcHosts(void);
int getMyPort(void);
void setUmask(mode_t mask);
if (len > 0) {
server.bytesIn(len);
- kb_incr(&(statCounter.server.all.kbytes_in), len);
- kb_incr(&(statCounter.server.other.kbytes_in), len);
+ statCounter.server.all.kbytes_in += len;
+ statCounter.server.other.kbytes_in += len;
}
if (keepGoingAfterRead(len, errcode, xerrno, server, client))
if (len > 0) {
connectRespBuf->appended(len);
server.bytesIn(len);
- kb_incr(&(statCounter.server.all.kbytes_in), len);
- kb_incr(&(statCounter.server.other.kbytes_in), len);
+ statCounter.server.all.kbytes_in += len;
+ statCounter.server.other.kbytes_in += len;
}
if (keepGoingAfterRead(len, errcode, xerrno, server, client))
if (len > 0) {
client.bytesIn(len);
- kb_incr(&(statCounter.client_http.kbytes_in), len);
+ statCounter.client_http.kbytes_in += len;
}
if (keepGoingAfterRead(len, errcode, xerrno, client, server))
}
/* Valid data */
- kb_incr(&(statCounter.server.all.kbytes_out), len);
- kb_incr(&(statCounter.server.other.kbytes_out), len);
+ statCounter.server.all.kbytes_out += len;
+ statCounter.server.other.kbytes_out += len;
client.dataSent(len);
/* If the other end has closed, so should we */
}
/* Valid data */
- kb_incr(&(statCounter.client_http.kbytes_out), len);
+ statCounter.client_http.kbytes_out += len;
server.dataSent(len);
/* If the other end has closed, so should we */
typedef uint32_t nfmark_t;
typedef unsigned char tos_t;
-typedef struct {
- size_t bytes;
- size_t kb;
-} kb_t;
-
typedef struct _CommWriteStateData CommWriteStateData;
#if SQUID_SNMP
if (!dataWritten)
setReplyToOK(entry);
- kb_incr(&(statCounter.server.all.kbytes_in), aBufferLength);
- kb_incr(&(statCounter.server.http.kbytes_in), aBufferLength);
+ statCounter.server.all.kbytes_in += aBufferLength;
+ statCounter.server.http.kbytes_in += aBufferLength;
/* No range support, we always grab it all */
dataWritten = true;