Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "ThruputMeter.h"
00020
00021 Define_Module(ThruputMeter);
00022
00023
00024 void ThruputMeter::initialize()
00025 {
00026 startTime = par("startTime");
00027 long _batchSize = par("batchSize");
00028 if((_batchSize < 0) || (((long)(unsigned int)_batchSize) != _batchSize))
00029 throw cRuntimeError("invalid 'batchSize=%ld' parameter at '%s' module",_batchSize, getFullPath().c_str());
00030 batchSize = (unsigned int)_batchSize;
00031 maxInterval = par("maxInterval");
00032
00033 numPackets = numBits = 0;
00034 intvlStartTime = intvlLastPkTime = 0;
00035 intvlNumPackets = intvlNumBits = 0;
00036
00037 WATCH(numPackets);
00038 WATCH(numBits);
00039 WATCH(intvlStartTime);
00040 WATCH(intvlNumPackets);
00041 WATCH(intvlNumBits);
00042
00043 bitpersecVector.setName("thruput (bit/sec)");
00044 pkpersecVector.setName("packet/sec");
00045 }
00046
00047 void ThruputMeter::handleMessage(cMessage *msg)
00048 {
00049 updateStats(simTime(), PK(msg)->getBitLength());
00050 send(msg, "out");
00051 }
00052
00053 void ThruputMeter::updateStats(simtime_t now, unsigned long bits)
00054 {
00055 numPackets++;
00056 numBits += bits;
00057
00058
00059 if (intvlNumPackets >= batchSize || now-intvlStartTime >= maxInterval)
00060 beginNewInterval(now);
00061
00062 intvlNumPackets++;
00063 intvlNumBits += bits;
00064 intvlLastPkTime = now;
00065 }
00066
00067 void ThruputMeter::beginNewInterval(simtime_t now)
00068 {
00069 simtime_t duration = now - intvlStartTime;
00070
00071
00072 double bitpersec = intvlNumBits/duration.dbl();
00073 double pkpersec = intvlNumPackets/duration.dbl();
00074
00075 bitpersecVector.recordWithTimestamp(intvlStartTime, bitpersec);
00076 pkpersecVector.recordWithTimestamp(intvlStartTime, pkpersec);
00077
00078
00079 intvlStartTime = now;
00080 intvlNumPackets = intvlNumBits = 0;
00081 }
00082
00083 void ThruputMeter::finish()
00084 {
00085 simtime_t duration = simTime() - startTime;
00086
00087 recordScalar("duration", duration);
00088 recordScalar("total packets", numPackets);
00089 recordScalar("total bits", numBits);
00090
00091 recordScalar("avg throughput (bit/s)", numBits/duration.dbl());
00092 recordScalar("avg packets/s", numPackets/duration.dbl());
00093 }
00094
00095