00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _H_SST_CORE_STATISTICS_ENGINE
00013 #define _H_SST_CORE_STATISTICS_ENGINE
00014
00015 #include <sst/core/sst_types.h>
00016 #include <sst/core/serialization.h>
00017 #include <sst/core/statapi/statfieldinfo.h>
00018
00019 namespace SST {
00020 class Component;
00021 class SimulationBase;
00022 class Simulation;
00023 namespace Statistics {
00024
00025 class StatisticBase;
00026
00027
00028
00029
00030
00031
00032
00033
00034 class StatisticProcessingEngine
00035 {
00036 public:
00037
00038
00039
00040
00041 void performStatisticOutput(StatisticBase* stat, bool endOfSimFlag = false);
00042
00043 private:
00044 friend class SST::Component;
00045 friend class SST::SimulationBase;
00046 friend class SST::Simulation;
00047
00048 StatisticProcessingEngine();
00049 ~StatisticProcessingEngine();
00050
00051 bool addPeriodicBasedStatistic(const UnitAlgebra& freq, StatisticBase* Stat);
00052 bool addEventBasedStatistic(const UnitAlgebra& count, StatisticBase* Stat);
00053 void setStatisticStartTime(const UnitAlgebra& startTime, StatisticBase* Stat);
00054 void setStatisticStopTime(const UnitAlgebra& stopTime, StatisticBase* Stat);
00055
00056 void endOfSimulation();
00057 void startOfSimulation();
00058
00059 template<typename T>
00060 void registerStatisticWithEngine(const ComponentId_t& compId, StatisticBase* Stat)
00061 {
00062 if (is_type_same<T, int32_t >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::INT32); }
00063 if (is_type_same<T, uint32_t >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::UINT32);}
00064 if (is_type_same<T, int64_t >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::INT64); }
00065 if (is_type_same<T, uint64_t >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::UINT64);}
00066 if (is_type_same<T, float >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::FLOAT); }
00067 if (is_type_same<T, double >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::DOUBLE);}
00068
00069
00070 addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::UNDEFINED);
00071 }
00072
00073 template<typename T>
00074 StatisticBase* isStatisticRegisteredWithEngine(const std::string& compName, const ComponentId_t& compId, std::string& statName, std::string& statSubId)
00075 {
00076 if (is_type_same<T, int32_t >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::INT32); }
00077 if (is_type_same<T, uint32_t >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::UINT32);}
00078 if (is_type_same<T, int64_t >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::INT64); }
00079 if (is_type_same<T, uint64_t >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::UINT64);}
00080 if (is_type_same<T, float >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::FLOAT); }
00081 if (is_type_same<T, double >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::DOUBLE);}
00082
00083
00084 return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::UNDEFINED);
00085 }
00086
00087 private:
00088 void addStatisticClock(const UnitAlgebra& freq, StatisticBase* Stat);
00089 TimeConverter* registerClock(const UnitAlgebra& freq, Clock::HandlerBase* handler, int priority);
00090 TimeConverter* registerStartOneShot(const UnitAlgebra& startTime, OneShot::HandlerBase* handler, int priority);
00091 TimeConverter* registerStopOneShot(const UnitAlgebra& stopTime, OneShot::HandlerBase* handler, int priority);
00092 bool handleStatisticEngineClockEvent(Cycle_t CycleNum, SimTime_t timeFactor);
00093 void handleStatisticEngineStartTimeEvent(SimTime_t timeFactor);
00094 void handleStatisticEngineStopTimeEvent(SimTime_t timeFactor);
00095 StatisticBase* isStatisticInCompStatMap(const std::string& compName, const ComponentId_t& compId, std::string& statName, std::string& statSubId, StatisticFieldInfo::fieldType_t fieldType);
00096 void addStatisticToCompStatMap(const ComponentId_t& compId, StatisticBase* Stat, StatisticFieldInfo::fieldType_t fieldType);
00097
00098 private:
00099 typedef std::vector<StatisticBase*> StatArray_t;
00100 typedef std::map<SimTime_t, StatArray_t*> StatMap_t;
00101 typedef std::map<SimTime_t, Clock*> ClockMap_t;
00102 typedef std::map<SimTime_t, OneShot*> OneShotMap_t;
00103 typedef std::map<ComponentId_t, StatArray_t*> CompStatMap_t;
00104
00105 StatArray_t m_EventStatisticArray;
00106 StatMap_t m_PeriodicStatisticMap;
00107 StatMap_t m_StartTimeMap;
00108 StatMap_t m_StopTimeMap;
00109 ClockMap_t m_ClockMap;
00110 OneShotMap_t m_StartTimeOneShotMap;
00111 OneShotMap_t m_StopTimeOneShotMap;
00112 CompStatMap_t m_CompStatMap;
00113 bool m_SimulationStarted;
00114
00115
00116 friend class boost::serialization::access;
00117 template<class Archive>
00118 void serialize(Archive& ar, const unsigned int version)
00119 {
00120 ar & BOOST_SERIALIZATION_NVP(m_EventStatisticArray);
00121 ar & BOOST_SERIALIZATION_NVP(m_PeriodicStatisticMap);
00122 ar & BOOST_SERIALIZATION_NVP(m_StartTimeMap);
00123 ar & BOOST_SERIALIZATION_NVP(m_StopTimeMap);
00124 ar & BOOST_SERIALIZATION_NVP(m_ClockMap);
00125 ar & BOOST_SERIALIZATION_NVP(m_StartTimeOneShotMap);
00126 ar & BOOST_SERIALIZATION_NVP(m_StopTimeOneShotMap);
00127 ar & BOOST_SERIALIZATION_NVP(m_CompStatMap);
00128 ar & BOOST_SERIALIZATION_NVP(m_SimulationStarted);
00129 }
00130 };
00131
00132 }
00133 }
00134
00135 BOOST_CLASS_EXPORT_KEY(SST::Statistics::StatisticProcessingEngine)
00136
00137 #endif