00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _H_SST_CORE_STATISTICS_OUTPUT
00013 #define _H_SST_CORE_STATISTICS_OUTPUT
00014
00015 #include "sst/core/sst_types.h"
00016 #include <sst/core/serialization.h>
00017 #include <sst/core/module.h>
00018 #include <sst/core/params.h>
00019 #include <sst/core/statapi/statfieldinfo.h>
00020 #include <sst/core/statapi/statbase.h>
00021 #include <unordered_map>
00022
00023
00024 #define STATISTICSDEFAULTOUTPUTNAME "sst.statOutputConsole"
00025 #define STATISTICSDEFAULTLOADLEVEL 0
00026
00027 namespace SST {
00028 class Component;
00029 class Simulation;
00030 namespace Statistics {
00031 class StatisticProcessingEngine;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 class StatisticOutput : public Module
00045 {
00046 public:
00047 typedef StatisticFieldInfo::fieldType_t fieldType_t;
00048 typedef StatisticFieldInfo::fieldHandle_t fieldHandle_t;
00049 typedef std::vector<StatisticFieldInfo*> FieldInfoArray_t;
00050 typedef std::unordered_map<std::string, fieldHandle_t> FieldNameMap_t;
00051
00052 public:
00053
00054
00055
00056 StatisticOutput(Params& outputParameters);
00057 ~StatisticOutput();
00058
00059
00060 std::string& getStatisticOutputName() {return m_statOutputName;}
00061
00062
00063 uint8_t getStatisticLoadLevel() {return m_statLoadLevel;}
00064
00065
00066 Params& getOutputParameters() {return m_outputParameters;}
00067
00068
00069
00070 public:
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 template<typename T>
00081 fieldHandle_t registerField(const char* fieldName)
00082 {
00083 if (is_type_same<T, int32_t >::value){return generateFileHandle(addFieldToLists(fieldName, StatisticFieldInfo::INT32)); }
00084 if (is_type_same<T, uint32_t >::value){return generateFileHandle(addFieldToLists(fieldName, StatisticFieldInfo::UINT32));}
00085 if (is_type_same<T, int64_t >::value){return generateFileHandle(addFieldToLists(fieldName, StatisticFieldInfo::INT64)); }
00086 if (is_type_same<T, uint64_t >::value){return generateFileHandle(addFieldToLists(fieldName, StatisticFieldInfo::UINT64));}
00087 if (is_type_same<T, float >::value){return generateFileHandle(addFieldToLists(fieldName, StatisticFieldInfo::FLOAT)); }
00088 if (is_type_same<T, double >::value){return generateFileHandle(addFieldToLists(fieldName, StatisticFieldInfo::DOUBLE));}
00089
00090
00091 return -1;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 StatisticFieldInfo* getRegisteredField(fieldHandle_t fieldHandle);
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 template<typename T>
00117 StatisticFieldInfo* getRegisteredField(const char* statisticName, const char* fieldName)
00118 {
00119 StatisticFieldInfo* NewStatFieldInfo;
00120 StatisticFieldInfo* ExistingStatFieldInfo;
00121 StatisticFieldInfo::fieldType_t FieldType = StatisticFieldInfo::UNDEFINED;
00122
00123
00124 if (is_type_same<T, int32_t >::value) {FieldType = StatisticFieldInfo::INT32; }
00125 if (is_type_same<T, uint32_t >::value) {FieldType = StatisticFieldInfo::UINT32;}
00126 if (is_type_same<T, int64_t >::value) {FieldType = StatisticFieldInfo::INT64; }
00127 if (is_type_same<T, uint64_t >::value) {FieldType = StatisticFieldInfo::UINT64;}
00128 if (is_type_same<T, float >::value) {FieldType = StatisticFieldInfo::FLOAT; }
00129 if (is_type_same<T, double >::value) {FieldType = StatisticFieldInfo::DOUBLE;}
00130
00131 NewStatFieldInfo = new StatisticFieldInfo(statisticName, fieldName, FieldType);
00132
00133
00134 FieldNameMap_t::const_iterator found = m_outputFieldNameMap.find(NewStatFieldInfo->getFieldUniqueName());
00135 if (found != m_outputFieldNameMap.end()) {
00136
00137
00138 ExistingStatFieldInfo = m_outputFieldInfoArray[found->second];
00139 delete NewStatFieldInfo;
00140 return ExistingStatFieldInfo;
00141 }
00142
00143 delete NewStatFieldInfo;
00144 return NULL;
00145 }
00146
00147
00148 FieldInfoArray_t& getFieldInfoArray() {return m_outputFieldInfoArray;}
00149
00150
00151
00152
00153
00154
00155
00156
00157 void outputField(fieldHandle_t fieldHandle, int32_t data);
00158 void outputField(fieldHandle_t fieldHandle, uint32_t data);
00159 void outputField(fieldHandle_t fieldHandle, int64_t data);
00160 void outputField(fieldHandle_t fieldHandle, uint64_t data);
00161 void outputField(fieldHandle_t fieldHandle, float data);
00162 void outputField(fieldHandle_t fieldHandle, double data);
00163
00164
00165
00166
00167
00168 const char* getFieldTypeShortName(fieldType_t type);
00169
00170 protected:
00171 friend class SST::Component;
00172 friend class SST::Simulation;
00173 friend class SST::Statistics::StatisticProcessingEngine;
00174
00175
00176
00177
00178
00179 virtual bool checkOutputParameters() = 0;
00180
00181
00182
00183 virtual void printUsage() = 0;
00184
00185
00186
00187
00188 virtual void startOfSimulation() = 0;
00189
00190
00191
00192 virtual void endOfSimulation() = 0;
00193
00194
00195
00196
00197 virtual void implStartOutputEntries(StatisticBase* statistic) = 0;
00198
00199
00200
00201 virtual void implStopOutputEntries() = 0;
00202
00203
00204
00205
00206 virtual void implOutputField(fieldHandle_t fieldHandle, int32_t data) = 0;
00207 virtual void implOutputField(fieldHandle_t fieldHandle, uint32_t data) = 0;
00208 virtual void implOutputField(fieldHandle_t fieldHandle, int64_t data) = 0;
00209 virtual void implOutputField(fieldHandle_t fieldHandle, uint64_t data) = 0;
00210 virtual void implOutputField(fieldHandle_t fieldHandle, float data) = 0;
00211 virtual void implOutputField(fieldHandle_t fieldHandle, double data) = 0;
00212
00213 private:
00214
00215 void startRegisterFields(const char* componentName, const char* statisticName);
00216 void stopRegisterFields();
00217
00218
00219 void setStatisticLoadLevel(uint8_t loadLevel) {m_statLoadLevel = loadLevel;}
00220
00221
00222 void startOutputEntries(StatisticBase* statistic);
00223 void stopOutputEntries();
00224
00225
00226 StatisticFieldInfo* addFieldToLists(const char* fieldName, fieldType_t fieldType);
00227 fieldHandle_t generateFileHandle(StatisticFieldInfo* FieldInfo);
00228
00229 protected:
00230 StatisticOutput() {;}
00231 void setStatisticOutputName(std::string name) {m_statOutputName = name;}
00232
00233 private:
00234 std::string m_statOutputName;
00235 Params m_outputParameters;
00236 FieldInfoArray_t m_outputFieldInfoArray;
00237 FieldNameMap_t m_outputFieldNameMap;
00238 fieldHandle_t m_highestFieldHandle;
00239 std::string m_currentFieldCompName;
00240 std::string m_currentFieldStatName;
00241 uint8_t m_statLoadLevel;
00242
00243 friend class boost::serialization::access;
00244 template<class Archive>
00245 void serialize(Archive & ar, const unsigned int version)
00246 {
00247
00248 ar & BOOST_SERIALIZATION_NVP(m_outputParameters);
00249 ar & BOOST_SERIALIZATION_NVP(m_outputFieldInfoArray);
00250 ar & BOOST_SERIALIZATION_NVP(m_highestFieldHandle);
00251 ar & BOOST_SERIALIZATION_NVP(m_currentFieldCompName);
00252 ar & BOOST_SERIALIZATION_NVP(m_currentFieldStatName);
00253 ar & BOOST_SERIALIZATION_NVP(m_statLoadLevel);
00254 }
00255 };
00256
00257 }
00258 }
00259
00260 BOOST_CLASS_EXPORT_KEY(SST::Statistics::StatisticOutput)
00261
00262 #endif