#include <GlobalStatistics.h>
Public Member Functions | |
~GlobalStatistics () | |
Destructor. | |
void | doFinish () |
Do the actual finish() call and record scalars needed because finish() gets called before all nodes have transmitted their data to GlobalStatistics. | |
void | addStdDev (const std::string &name, double value) |
add a value to a cStdDev | |
void | recordOutVector (const std::string &name, double value) |
record a value to a global cOutVector defined by name | |
void | startMeasuring () |
bool | isMeasuring () |
simtime_t | getMeasureStartTime () |
simtime_t | calcMeasuredLifetime (simtime_t creationTime) |
Public Attributes | |
double | sentKBRTestAppMessages |
total number of messages sent by KBRTestApp | |
double | deliveredKBRTestAppMessages |
total number of messages delivered by KBRTestApp | |
int | testCount |
cOutVector | currentDeliveryVector |
statistical output vector for current delivery ratio | |
int | nodesInitialized |
nodes that have run initialize() and "registered" with GlobalStatistics | |
int | nodesFinished |
nodes that have run finished() and have "deregistered" with GlobalStatistics | |
Protected Member Functions | |
virtual void | initialize () |
Init member function of module. | |
virtual void | handleMessage (cMessage *msg) |
HandleMessage member function of module. | |
virtual void | finish () |
Finish member function of module. | |
Protected Attributes | |
map< std::string, cStdDev * > | stdDevMap |
map to store and access the statistics data | |
map< std::string, OutVector * > | outVectorMap |
map to store and access the output vectors | |
cMessage * | globalStatTimer |
timer for periodic statistic updates | |
double | globalStatTimerInterval |
interval length of periodic statistic timer | |
bool | measureNetwInitPhase |
bool | measuring |
simtime_t | measureStartTime |
Classes | |
struct | OutVector |
< struct for cOutVectors and cummulated values More... |
GlobalStatistics::~GlobalStatistics | ( | ) |
Destructor.
00182 { 00183 // deallocate vectors 00184 for (map<std::string, cStdDev*>::iterator iter = stdDevMap.begin(); 00185 iter != stdDevMap.end(); iter++) { 00186 delete iter->second; 00187 } 00188 stdDevMap.clear(); 00189 00190 for (map<std::string, OutVector*>::iterator iter = outVectorMap.begin(); 00191 iter != outVectorMap.end(); iter++) { 00192 delete iter->second; 00193 } 00194 outVectorMap.clear(); 00195 }
void GlobalStatistics::doFinish | ( | ) |
Do the actual finish() call and record scalars needed because finish() gets called before all nodes have transmitted their data to GlobalStatistics.
00095 { 00096 if (nodesInitialized != nodesFinished) return; 00097 00098 recordScalar("GlobalStatistics: Simulation Time", simTime()); 00099 00100 bool outputMinMax = par("outputMinMax"); 00101 bool outputStdDev = par("outputStdDev"); 00102 00103 // record stats from other modules 00104 for (map<const std::string, cStdDev*>::iterator iter = stdDevMap.begin(); 00105 iter != stdDevMap.end(); iter++) { 00106 00107 const std::string& n = iter->first; 00108 const cStatistic& stat = *(iter->second); 00109 00110 recordScalar((n + ".mean").c_str(), stat.mean()); 00111 00112 if (outputStdDev) 00113 recordScalar((n + ".stddev").c_str(), stat.stddev()); 00114 00115 if (outputMinMax) { 00116 recordScalar((n + ".min").c_str(), stat.min()); 00117 recordScalar((n + ".max").c_str(), stat.max()); 00118 } 00119 } 00120 00121 for (map<const std::string, OutVector*>::iterator iter = outVectorMap.begin(); 00122 iter != outVectorMap.end(); iter++) { 00123 00124 const OutVector& ov = *(iter->second); 00125 00126 double mean = ov.count > 0 ? ov.value / ov.count : 0; 00127 00128 recordScalar(("Vector: " + iter->first + ".mean").c_str(), mean); 00129 } 00130 }
void GlobalStatistics::addStdDev | ( | const std::string & | name, | |
double | value | |||
) |
add a value to a cStdDev
00133 { 00134 if (!measuring) { 00135 return; 00136 } 00137 00138 std::map<std::string, cStdDev*>::iterator sdPos = stdDevMap.find(name); 00139 cStdDev* sd = NULL; 00140 00141 if (sdPos == stdDevMap.end()) { 00142 Enter_Method_Silent(); 00143 sd = new cStdDev(name.c_str()); 00144 stdDevMap.insert(pair<std::string, cStdDev*>(name, sd)); 00145 } else { 00146 sd = sdPos->second; 00147 } 00148 00149 *sd += value; 00150 }
void GlobalStatistics::recordOutVector | ( | const std::string & | name, | |
double | value | |||
) |
record a value to a global cOutVector defined by name
00153 { 00154 if (!measuring) { 00155 return; 00156 } 00157 00158 std::map<std::string, OutVector*>::iterator ovPos = 00159 outVectorMap.find(name); 00160 OutVector* ov = NULL; 00161 00162 if (ovPos == outVectorMap.end()) { 00163 Enter_Method_Silent(); 00164 ov = new OutVector(name); 00165 outVectorMap.insert(pair<std::string, OutVector*>(name, ov)); 00166 } else { 00167 ov = ovPos->second; 00168 } 00169 00170 ov->vector.record(value); 00171 ov->value += value; 00172 ov->count++; 00173 }
void GlobalStatistics::startMeasuring | ( | ) |
00054 { 00055 if(!measuring) { 00056 measuring = true; 00057 measureStartTime = simTime(); 00058 } 00059 }
bool GlobalStatistics::isMeasuring | ( | ) | [inline] |
simtime_t GlobalStatistics::getMeasureStartTime | ( | ) | [inline] |
simtime_t GlobalStatistics::calcMeasuredLifetime | ( | simtime_t | creationTime | ) |
00176 { 00177 return simTime() - ((creationTime > measureStartTime) 00178 ? creationTime : measureStartTime); 00179 }
void GlobalStatistics::initialize | ( | ) | [protected, virtual] |
Init member function of module.
00031 { 00032 sentKBRTestAppMessages = 0; 00033 deliveredKBRTestAppMessages = 0; 00034 00035 nodesInitialized = nodesFinished = 0; 00036 00037 measureNetwInitPhase = par("measureNetwInitPhase"); 00038 measuring = measureNetwInitPhase; 00039 measureStartTime = 0; 00040 00041 currentDeliveryVector.setName("Current Delivery Ratio"); 00042 00043 // start periodic globalStatTimer 00044 globalStatTimerInterval = par("globalStatTimerInterval"); 00045 globalStatTimer = new cMessage("globalStatTimer"); 00046 scheduleAt(simulation.simTime() + globalStatTimerInterval, globalStatTimer); 00047 00048 WATCH(measuring); 00049 WATCH(measureStartTime); 00050 WATCH(currentDeliveryVector); 00051 }
void GlobalStatistics::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
HandleMessage member function of module.
00063 { 00064 if (msg == globalStatTimer) { 00065 // schedule next timer event 00066 scheduleAt(simulation.simTime() + globalStatTimerInterval, msg); 00067 00068 double ratio; 00069 00070 if (sentKBRTestAppMessages == 0) { 00071 ratio = 0; 00072 } else { 00073 ratio = (double)deliveredKBRTestAppMessages / 00074 (double)sentKBRTestAppMessages; 00075 } 00076 00077 if (ratio > 1) ratio = 1; 00078 00079 currentDeliveryVector.record(ratio); 00080 sentKBRTestAppMessages = 0; 00081 deliveredKBRTestAppMessages = 0; 00082 00083 return; 00084 } 00085 00086 error("GlobalStatistics::handleMessage(): Unknown message type!"); 00087 }
void GlobalStatistics::finish | ( | ) | [protected, virtual] |
total number of messages sent by KBRTestApp
total number of messages delivered by KBRTestApp
cOutVector GlobalStatistics::currentDeliveryVector |
statistical output vector for current delivery ratio
nodes that have run initialize() and "registered" with GlobalStatistics
nodes that have run finished() and have "deregistered" with GlobalStatistics
map<std::string, cStdDev*> GlobalStatistics::stdDevMap [protected] |
map to store and access the statistics data
map<std::string, OutVector*> GlobalStatistics::outVectorMap [protected] |
map to store and access the output vectors
cMessage* GlobalStatistics::globalStatTimer [protected] |
timer for periodic statistic updates
double GlobalStatistics::globalStatTimerInterval [protected] |
interval length of periodic statistic timer
bool GlobalStatistics::measureNetwInitPhase [protected] |
bool GlobalStatistics::measuring [protected] |
simtime_t GlobalStatistics::measureStartTime [protected] |