GlobalStatistics.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2007 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #ifndef __GLOBALSTATISTICS_H__
00025 #define __GLOBALSTATISTICS_H__
00026 
00027 #include <map>
00028 
00029 #include <omnetpp.h>
00030 
00031 class OverlayKey;
00032 
00038 #define RECORD_STATS(x) \
00039     do { \
00040         if (globalStatistics->isMeasuring()){ x; } \
00041     } while(false)
00042 
00043 
00044 
00050 class GlobalStatistics : public cSimpleModule
00051 {
00052 public:
00053     static const double MIN_MEASURED = 0.1; 
00054 
00055     double sentKBRTestAppMessages; 
00056     double deliveredKBRTestAppMessages; 
00057     int testCount;
00058     cOutVector currentDeliveryVector; 
00059 
00063     ~GlobalStatistics();
00064 
00072     void addStdDev(const std::string& name, double value);
00073 
00074 
00081     void recordOutVector(const std::string& name, double value /*, int avg = -1*/);
00082 
00083     void startMeasuring();
00084 
00085     inline bool isMeasuring() { return measuring; };
00086     inline simtime_t getMeasureStartTime() { return measureStartTime; };
00087 
00088     simtime_t calcMeasuredLifetime(simtime_t creationTime);
00089 
00090     void finalizeStatistics();
00091 
00092 protected:
00093 
00094     struct OutVector 
00095     {
00096         cOutVector vector; 
00097         int count; 
00098         double value; 
00099         double avg;
00100 
00101         OutVector(const std::string& name) :
00102             vector(name.c_str()), count(0), value(0), avg(0) {};
00103     };
00104 
00105     std::map<std::string, cStdDev*> stdDevMap; 
00106     std::map<std::string, OutVector*> outVectorMap; 
00107     cMessage* globalStatTimer; 
00108     double globalStatTimerInterval; 
00109 
00113     virtual void initialize();
00114 
00118     virtual void handleMessage(cMessage* msg);
00119 
00123     virtual void finish();
00124 
00125     bool measuring;
00126     simtime_t measureStartTime;
00127 };
00128 
00129 #endif
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3