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; 
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 
00078     void recordHistogram(const std::string& name, double value);
00079 
00086     void recordOutVector(const std::string& name, double value);
00087 
00088     void startMeasuring();
00089 
00090     inline bool isMeasuring() { return measuring; };
00091     inline simtime_t getMeasureStartTime() { return measureStartTime; };
00092 
00093     simtime_t calcMeasuredLifetime(simtime_t creationTime);
00094 
00095     void finalizeStatistics();
00096 
00097 protected:
00098 
00099     struct OutVector 
00100     {
00101         cOutVector vector; 
00102         int count; 
00103         double value; 
00104         double avg;
00105 
00106         OutVector(const std::string& name) :
00107             vector(name.c_str()), count(0), value(0), avg(0) {};
00108     };
00109 
00110     std::map<std::string, cStdDev*> stdDevMap; 
00111     std::map<std::string, cHistogram*> histogramMap; 
00112     std::map<std::string, OutVector*> outVectorMap; 
00113     cMessage* globalStatTimer; 
00114     double globalStatTimerInterval; 
00115 
00119     virtual void initialize();
00120 
00124     virtual void handleMessage(cMessage* msg);
00125 
00129     virtual void finish();
00130 
00131     bool measuring;
00132     simtime_t measureStartTime;
00133 };
00134 
00135 #endif