14 StatsModule::StatsModule(
int maxStats1,
int maxLnk1,
int maxQ1,
16 : maxStats(maxStats1), maxLnk(maxLnk1), maxQ(maxQ1),
18 stat =
new StatItem[maxStats+1];
19 lnkCnts =
new LinkCounts[maxLnk+1];
20 qCnts =
new QueueCounts[maxQ+1];
21 for (
int i = 1; i <= maxLnk; i++) {
22 lnkCnts[i].inByte = lnkCnts[i].outByte = 0;
23 lnkCnts[i].inPkt = lnkCnts[i].outPkt = 0;
24 lnkCnts[i].numPkt = 0;
26 for (
int i = 1; i <= maxQ; i++) {
27 qCnts[i].bytLen = qCnts[i].pktLen = 0;
30 totInByte = 0; totInPkt = 0; totDiscards = 0;
31 rtrInByte = 0; rtrInPkt = 0;
32 leafInByte = 0; leafInPkt = 0;
33 totOutByte = 0; totOutPkt = 0;
34 rtrOutByte = 0; rtrOutPkt = 0; rtrDiscards = 0;
35 leafOutByte = 0; leafOutPkt = 0; leafDiscards = 0;
38 StatsModule::~StatsModule() {
delete [] stat; }
41 void StatsModule::record(uint64_t now) {
42 unique_lock<mutex> lck(mtx);
43 int i, val, ctx, cLnk, qid;
49 string fname =
"statsSwitch";
50 ifstream sfs; sfs.open(fname.c_str());
52 if (sfs.fail())
return;
53 if (!Util::readWord(sfs,statsSwitch) || statsSwitch !=
"on") {
57 for (i = 1; i <= n; i++) {
58 StatItem& s = stat[i];
61 if (s.lnk == 0) val = totInPkt;
62 else if (s.lnk == -1) val = rtrInPkt;
63 else if (s.lnk == -2) val = leafInPkt;
64 else val = lnkCnts[s.lnk].inPkt;
67 if (s.lnk == 0) val = totOutPkt;
68 else if (s.lnk == -1) val = rtrOutPkt;
69 else if (s.lnk == -2) val = leafOutPkt;
70 else val = lnkCnts[s.lnk].outPkt;
73 if (s.lnk == 0) val = totInByte;
74 else if (s.lnk == -1) val = rtrInByte;
75 else if (s.lnk == -2) val = leafInByte;
76 else val = lnkCnts[s.lnk].inByte;
79 if (s.lnk == 0) val = totOutByte;
80 else if (s.lnk == -1) val = rtrOutByte;
81 else if (s.lnk == -2) val = leafOutByte;
82 else val = lnkCnts[s.lnk].outByte;
86 val = getLinkQlen(s.lnk);
113 fs << double(now)/1000000000 << endl;
147 cntrTyp typ;
string typStr, fname;
150 if (!Util::readWord(in,typStr))
return false;
152 if (typStr ==
"inPkt") typ = inPkt;
153 else if (typStr ==
"outPkt") typ = outPkt;
154 else if (typStr ==
"inByt") typ = inByt;
155 else if (typStr ==
"outByt") typ = outByt;
156 else if (typStr ==
"qPkt") typ = qPkt;
157 else if (typStr ==
"qByt") typ = qByt;
158 else if (typStr ==
"disc") typ = disc;
162 case inPkt:
case outPkt:
case inByt:
case outByt:
163 if (!Util::readInt(in,lnk))
return false;
165 case qPkt:
case qByt:
case disc:
166 if (!Util::readInt(in,lnk) || !Util::readInt(in,comt))
172 if (n >= maxStats)
return false;
183 bool StatsModule::read(istream& in) {
188 unique_lock<mutex> lck(mtx);
191 if (!Util::readInt(in,num))
return false;
196 string fname =
"stats";
197 fs.open(fname.c_str(),fstream::app);
198 if (fs.fail())
return false;
212 ss <<
" inPkt " << setw(2) << si.lnk << endl;
215 ss <<
"outPkt " << setw(2) << si.lnk << endl;
218 ss <<
" inByt " << setw(2) << si.lnk << endl;
221 ss <<
"outByt " << setw(2) << si.lnk << endl;
224 ss <<
" qPkt " << setw(2) << si.lnk
225 <<
" " << setw(2) << si.comt << endl;
228 ss <<
" qByt " << setw(2) << si.lnk
229 <<
" " << setw(2) << si.comt << endl;
232 ss <<
" disc " << setw(2) << si.lnk
233 <<
" " << setw(2) << si.comt << endl;
244 unique_lock<mutex> lck(mtx);