00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _H_SST_CORE_STATISTICS_BASE
00013 #define _H_SST_CORE_STATISTICS_BASE
00014
00015 #include <sst/core/sst_types.h>
00016 #include <sst/core/serialization.h>
00017 #include <sst/core/params.h>
00018 #include <sst/core/oneshot.h>
00019 #include <sst/core/statapi/statfieldinfo.h>
00020
00021 namespace SST {
00022 class Component;
00023 class SubComponent;
00024 namespace Statistics {
00025 class StatisticOutput;
00026 class StatisticProcessingEngine;
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 class StatisticBase
00038 {
00039 public:
00040
00041 typedef enum {STAT_MODE_UNDEFINED, STAT_MODE_COUNT, STAT_MODE_PERIODIC} StatMode_t;
00042
00043
00044
00045 void enable() {m_statEnabled = true;}
00046
00047
00048 void disable() {m_statEnabled = false;}
00049
00050
00051
00052 virtual void clearStatisticData() {}
00053
00054
00055 virtual void resetCollectionCount();
00056
00057
00058 virtual void incrementCollectionCount();
00059
00060
00061 virtual void setCollectionCount(uint64_t newCount);
00062
00063
00064 virtual void setCollectionCountLimit(uint64_t newLimit);
00065
00066
00067
00068
00069
00070 void setFlagResetCountOnOutput(bool flag) {m_resetCountOnOutput = flag;}
00071
00072
00073
00074
00075
00076 void setFlagClearDataOnOutput(bool flag) {m_clearDataOnOutput = flag;}
00077
00078
00079
00080
00081 void setFlagOutputAtEndOfSim(bool flag) {m_outputAtEndOfSim = flag;}
00082
00083
00084
00085 const std::string& getCompName() const;
00086
00087
00088 inline const std::string& getStatName() const {return m_statName;}
00089
00090
00091 inline const std::string& getStatSubId() const {return m_statSubId;}
00092
00093
00094 inline const std::string& getFullStatName() const {return m_statFullName;}
00095
00096
00097 inline const std::string& getStatTypeName() const {return m_statTypeName;}
00098
00099
00100 inline const StatisticFieldInfo::fieldType_t& getStatDataType() const {return m_statDataType;}
00101
00102
00103 inline const char* getStatDataTypeShortName() const {return StatisticFieldInfo::getFieldTypeShortName(m_statDataType);}
00104
00105
00106 inline const char* getStatDataTypeFullName() const {return StatisticFieldInfo::getFieldTypeFullName(m_statDataType);}
00107
00108
00109 Component* getComponent() const {return m_component;}
00110
00111
00112 bool isEnabled() const {return m_statEnabled;}
00113
00114
00115 bool isOutputEnabled() const {return m_outputEnabled;}
00116
00117
00118 uint64_t getCollectionCountLimit() const {return m_collectionCountLimit;}
00119
00120
00121 uint64_t getCollectionCount() const {return m_currentCollectionCount;}
00122
00123
00124 bool getFlagResetCountOnOutput() const {return m_resetCountOnOutput;}
00125
00126
00127 bool getFlagClearDataOnOutput() const {return m_clearDataOnOutput;}
00128
00129
00130 bool getFlagOutputAtEndOfSim() const {return m_outputAtEndOfSim;}
00131
00132
00133 StatMode_t getRegisteredCollectionMode() const {return m_registeredCollectionMode;}
00134
00135
00136
00137
00138
00139 void delayOutput(const char* delayTime);
00140
00141
00142
00143
00144 void delayCollection(const char* delayTime);
00145
00146
00147
00148 virtual bool isReady() const {return true;}
00149
00150
00151 virtual bool isNullStatistic() const {return false;}
00152
00153 protected:
00154 friend class SST::Component;
00155 friend class SST::SubComponent;
00156 friend class SST::Statistics::StatisticProcessingEngine;
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 StatisticBase(Component* comp, std::string& statName, std::string& statSubId, Params& statParams);
00167
00168
00169 virtual ~StatisticBase() {}
00170
00171
00172 Params& getParams() {return m_statParams;}
00173
00174
00175 void setStatisticDataType(const StatisticFieldInfo::fieldType_t dataType) {m_statDataType = dataType;}
00176
00177
00178 void setStatisticTypeName(const char* typeName) {m_statTypeName = typeName;}
00179
00180 private:
00181
00182 void setRegisteredCollectionMode(StatMode_t mode) {m_registeredCollectionMode = mode;}
00183
00184
00185 static std::string buildStatisticFullName(const char* compName, const char* statName, const char* statSubId);
00186 static std::string buildStatisticFullName(const std::string& compName, const std::string& statName, const std::string& statSubId);
00187
00188
00189
00190
00191
00192
00193 virtual void registerOutputFields(StatisticOutput* statOutput) = 0;
00194
00195
00196
00197
00198
00199
00200 virtual void outputStatisticData(StatisticOutput* statOutput, bool EndOfSimFlag) = 0;
00201
00202
00203
00204
00205
00206
00207 virtual bool isStatModeSupported(StatMode_t mode) const {return true;}
00208
00209
00210 bool operator==(StatisticBase& checkStat);
00211
00212
00213 void initializeStatName(const char* compName, const char* statName, const char* statSubId);
00214 void initializeStatName(const std::string& compName, const std::string& statName, const std::string& statSubId);
00215
00216 void initializeProperties();
00217 void checkEventForOutput();
00218
00219
00220 void delayOutputExpiredHandler();
00221 void delayCollectionExpiredHandler();
00222
00223 private:
00224 StatisticBase();
00225
00226 private:
00227 Component* m_component;
00228 std::string m_statName;
00229 std::string m_statSubId;
00230 std::string m_statFullName;
00231 std::string m_statTypeName;
00232 Params m_statParams;
00233 StatMode_t m_registeredCollectionMode;
00234 uint64_t m_currentCollectionCount;
00235 uint64_t m_collectionCountLimit;
00236 StatisticFieldInfo::fieldType_t m_statDataType;
00237
00238 bool m_statEnabled;
00239 bool m_outputEnabled;
00240 bool m_resetCountOnOutput;
00241 bool m_clearDataOnOutput;
00242 bool m_outputAtEndOfSim;
00243
00244 bool m_outputDelayed;
00245 bool m_collectionDelayed;
00246 bool m_savedStatEnabled;
00247 bool m_savedOutputEnabled;
00248 OneShot::HandlerBase* m_outputDelayedHandler;
00249 OneShot::HandlerBase* m_collectionDelayedHandler;
00250
00251 friend class boost::serialization::access;
00252 template<class Archive>
00253 void serialize(Archive & ar, const unsigned int version)
00254 {
00255 ar & BOOST_SERIALIZATION_NVP(m_component);
00256 ar & BOOST_SERIALIZATION_NVP(m_statName);
00257 ar & BOOST_SERIALIZATION_NVP(m_statSubId);
00258 ar & BOOST_SERIALIZATION_NVP(m_statFullName);
00259 ar & BOOST_SERIALIZATION_NVP(m_statTypeName);
00260 ar & BOOST_SERIALIZATION_NVP(m_registeredCollectionMode);
00261 ar & BOOST_SERIALIZATION_NVP(m_currentCollectionCount);
00262 ar & BOOST_SERIALIZATION_NVP(m_collectionCountLimit);
00263 ar & BOOST_SERIALIZATION_NVP(m_statDataType);
00264 ar & BOOST_SERIALIZATION_NVP(m_statEnabled);
00265 ar & BOOST_SERIALIZATION_NVP(m_outputEnabled);
00266 ar & BOOST_SERIALIZATION_NVP(m_resetCountOnOutput);
00267 ar & BOOST_SERIALIZATION_NVP(m_clearDataOnOutput);
00268 ar & BOOST_SERIALIZATION_NVP(m_outputAtEndOfSim);
00269 ar & BOOST_SERIALIZATION_NVP(m_outputDelayed);
00270 ar & BOOST_SERIALIZATION_NVP(m_collectionDelayed);
00271 ar & BOOST_SERIALIZATION_NVP(m_savedStatEnabled);
00272 ar & BOOST_SERIALIZATION_NVP(m_savedOutputEnabled);
00273 ar & BOOST_SERIALIZATION_NVP(m_outputDelayedHandler);
00274 ar & BOOST_SERIALIZATION_NVP(m_collectionDelayedHandler);
00275 }
00276 };
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 template <typename T>
00289 class Statistic : public StatisticBase
00290 {
00291 public:
00292
00293
00294
00295
00296 void addData(T data)
00297 {
00298
00299
00300 if (true == isEnabled()) {
00301 addData_impl(data);
00302 incrementCollectionCount();
00303 }
00304 }
00305
00306 protected:
00307 friend class SST::Component;
00308
00309
00310
00311
00312
00313
00314
00315 Statistic(Component* comp, std::string& statName, std::string& statSubId, Params& statParams) :
00316 StatisticBase(comp, statName, statSubId, statParams)
00317 {
00318 setStatisticDataType(StatisticFieldInfo::getFieldTypeFromTemplate<T>());
00319 }
00320
00321 virtual ~Statistic(){}
00322
00323 private:
00324 Statistic(){};
00325
00326
00327 virtual void addData_impl(T data) = 0;
00328
00329 private:
00330 friend class boost::serialization::access;
00331 template<class Archive>
00332 void serialize(Archive & ar, const unsigned int version)
00333 {
00334 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(StatisticBase);
00335 }
00336 };
00337
00338 }
00339 }
00340
00341 BOOST_CLASS_EXPORT_KEY(SST::Statistics::StatisticBase)
00342
00343
00344 #endif