00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _H_SST_CORE_COMP_REG_STAT__
00014 #define _H_SST_CORE_COMP_REG_STAT__
00015
00016
00017
00018
00019
00020
00021
00022
00023 std::string fullStatName;
00024 bool statGood = true;
00025 bool nameFound = false;
00026 StatisticBase::StatMode_t statCollectionMode = StatisticBase::STAT_MODE_COUNT;
00027 Simulation::statEnableList_t* statEnableList;
00028 Simulation::statParamsList_t* statParamsList;
00029 Output out = Simulation::getSimulation()->getSimulationOutput();
00030 UnitAlgebra collectionRate;
00031 UnitAlgebra startAtTime;
00032 UnitAlgebra stopAtTime;
00033 Params statParams;
00034 std::string statRateParam;
00035 std::string statTypeParam;
00036 std::string statStartAtTimeParam;
00037 std::string statStopAtTimeParam;
00038 Statistic<T>* statistic = NULL;
00039
00040
00041 StatisticBase* prevStat = Simulation::getSimulation()->getStatisticsProcessingEngine()->isStatisticRegisteredWithEngine<T>(getName(), getId(), statName, statSubId);
00042 if (NULL != prevStat) {
00043
00044 return dynamic_cast<Statistic<T>*>(prevStat);
00045 }
00046
00047
00048 fullStatName = StatisticBase::buildStatisticFullName(getName().c_str(), statName, statSubId);
00049
00050
00051 if (true == Simulation::getSimulation()->isWireUpFinished()) {
00052
00053 fprintf(stderr, "ERROR: Statistic %s - Cannot be registered after the Components have been wired up. Statistics must be registered on Component creation.; exiting...\n", fullStatName.c_str());
00054 exit(1);
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 statEnableList = Simulation::getSimulation()->getComponentStatisticEnableList(getId());
00066 statParamsList = Simulation::getSimulation()->getComponentStatisticParamsList(getId());
00067
00068
00069
00070
00071 for (uint32_t x = 0; x < statEnableList->size(); x++) {
00072
00073
00074
00075 if ((std::string(STATALLFLAG) == statEnableList->at(x)) || (statName == statEnableList->at(x))) {
00076
00077 Params::KeySet_t allowedKeySet;
00078 allowedKeySet.insert("type");
00079 allowedKeySet.insert("rate");
00080 allowedKeySet.insert("startat");
00081 allowedKeySet.insert("stopat");
00082 statParamsList->at(x).pushAllowedKeys(allowedKeySet);
00083
00084
00085
00086 statTypeParam = statParamsList->at(x).find_string("type", "sst.AccumulatorStatistic");
00087 statRateParam = statParamsList->at(x).find_string("rate", "0ns");
00088 statStartAtTimeParam = statParamsList->at(x).find_string("startat", "0ns");
00089 statStopAtTimeParam = statParamsList->at(x).find_string("stopat", "0ns");
00090
00091
00092 if (true == statRateParam.empty()) {
00093 statRateParam = "0ns";
00094 }
00095 if (true == statStartAtTimeParam.empty()) {
00096 statStartAtTimeParam = "0ns";
00097 }
00098 if (true == statStopAtTimeParam.empty()) {
00099 statStopAtTimeParam = "0ns";
00100 }
00101
00102 collectionRate = UnitAlgebra(statRateParam);
00103 startAtTime = UnitAlgebra(statStartAtTimeParam);
00104 stopAtTime = UnitAlgebra(statStopAtTimeParam);
00105 statParams = statParamsList->at(x);
00106 nameFound = true;
00107 break;
00108 }
00109 }
00110
00111
00112 if (false == nameFound) {
00113 statGood = false;
00114 out.verbose(CALL_INFO, 1, 0, " Warning: Statistic %s is not enabled in python script, statistic will not be enabled...\n", fullStatName.c_str());
00115 }
00116
00117 if (true == statGood) {
00118
00119 if ((true == collectionRate.hasUnits("s")) ||
00120 (true == collectionRate.hasUnits("hz")) ) {
00121
00122 statCollectionMode = StatisticBase::STAT_MODE_PERIODIC;
00123 } else if (true == collectionRate.hasUnits("event")) {
00124
00125 statCollectionMode = StatisticBase::STAT_MODE_COUNT;
00126 } else if (0 == collectionRate.getValue()) {
00127
00128 collectionRate = UnitAlgebra("0ns");
00129 statCollectionMode = StatisticBase::STAT_MODE_PERIODIC;
00130 } else {
00131
00132 fprintf(stderr, "ERROR: Statistic %s - Collection Rate = %s not valid; exiting...\n", fullStatName.c_str(), collectionRate.toString().c_str());
00133 exit(1);
00134 }
00135
00136
00137 if ((true != startAtTime.hasUnits("s")) || (true != stopAtTime.hasUnits("s"))) {
00138
00139 fprintf(stderr, "ERROR: Statistic %s - param startat = %s; stopat = %s must both be in units of seconds; exiting...\n", fullStatName.c_str(), startAtTime.toString().c_str(), stopAtTime.toString().c_str());
00140 exit(1);
00141 }
00142 }
00143
00144 if (true == statGood) {
00145
00146 statistic = Simulation::getSimulation()->CreateStatistic<T>(this, statTypeParam, statName, statSubId, statParams);
00147 if (NULL == statistic) {
00148 fprintf(stderr, "ERROR: Unable to instantiate Statistic %s; exiting...\n", fullStatName.c_str());
00149 exit(1);
00150 }
00151
00152
00153 if (false == statistic->isStatModeSupported(statCollectionMode)) {
00154 if (StatisticBase::STAT_MODE_PERIODIC == statCollectionMode) {
00155 out.verbose(CALL_INFO, 1, 0, " Warning: Statistic %s Does not support Periodic Based Collections; Collection Rate = %s\n", fullStatName.c_str(), collectionRate.toString().c_str());
00156 } else {
00157 out.verbose(CALL_INFO, 1, 0, " Warning: Statistic %s Does not support Event Based Collections; Collection Rate = %s\n", fullStatName.c_str(), collectionRate.toString().c_str());
00158 }
00159 statGood = false;
00160 }
00161
00162
00163 statistic->setRegisteredCollectionMode(statCollectionMode);
00164 }
00165
00166
00167 if (true == statGood) {
00168
00169
00170 uint8_t enableLevel = getComponentInfoStatisticEnableLevel(statistic->getStatName());
00171 uint8_t loadLevel = Simulation::getSimulation()->getStatisticsOutput()->getStatisticLoadLevel();
00172 if (0 == loadLevel) {
00173 out.verbose(CALL_INFO, 1, 0, " Warning: Statistic Load Level = 0 (all statistics disabled); statistic %s is disabled...\n", fullStatName.c_str());
00174 statGood = false;
00175
00176
00177
00178 } else if (enableLevel > loadLevel) {
00179 out.verbose(CALL_INFO, 1, 0, " Warning: Load Level %d is too low to enable Statistic %s with Enable Level %d, statistic will not be enabled...\n", loadLevel, fullStatName.c_str(), enableLevel);
00180 statGood = false;
00181 }
00182 }
00183
00184
00185 if (true == statGood) {
00186
00187
00188 if (StatisticBase::STAT_MODE_PERIODIC == statCollectionMode) {
00189 if (false == Simulation::getSimulation()->getStatisticsProcessingEngine()->addPeriodicBasedStatistic(collectionRate, statistic)) {
00190 statGood = false;
00191 }
00192 } else {
00193 if (false == Simulation::getSimulation()->getStatisticsProcessingEngine()->addEventBasedStatistic(collectionRate, statistic)) {
00194 statGood = false;
00195 }
00196 }
00197 }
00198
00199
00200
00201 if (true == statGood) {
00202
00203 StatisticOutput* statOutput = Simulation::getSimulation()->getStatisticsOutput();
00204 statOutput->startRegisterFields(statistic->getCompName().c_str(), statistic->getStatName().c_str());
00205 statistic->registerOutputFields(statOutput);
00206 statOutput->stopRegisterFields();
00207
00208
00209 Simulation::getSimulation()->getStatisticsProcessingEngine()->setStatisticStartTime(startAtTime, statistic);
00210 Simulation::getSimulation()->getStatisticsProcessingEngine()->setStatisticStopTime(stopAtTime, statistic);
00211 } else {
00212
00213 if (NULL != statistic) {
00214 delete statistic;
00215 }
00216
00217
00218 statTypeParam = "sst.NullStatistic";
00219 statistic = Simulation::getSimulation()->CreateStatistic<T>(this, statTypeParam, statName, statSubId, statParams);
00220 if (NULL == statistic) {
00221 statGood = false;
00222 fprintf(stderr, "ERROR: Unable to instantiate Null Statistic %s; exiting...\n", fullStatName.c_str());
00223 exit(1);
00224 }
00225 }
00226
00227
00228 Simulation::getSimulation()->getStatisticsProcessingEngine()->registerStatisticWithEngine<T>(getId(), statistic);
00229 return statistic;
00230
00231
00232 #endif //_H_SST_CORE_COMP_REG_STAT__