13 #ifndef _H_SST_CORE_COMP_REG_STAT__
14 #define _H_SST_CORE_COMP_REG_STAT__
23 std::string fullStatName;
25 bool nameFound =
false;
26 StatisticBase::StatMode_t statCollectionMode = StatisticBase::STAT_MODE_COUNT;
27 Simulation::statEnableList_t* statEnableList;
28 Simulation::statParamsList_t* statParamsList;
29 Output out = Simulation::getSimulation()->getSimulationOutput();
30 UnitAlgebra collectionRate;
31 UnitAlgebra startAtTime;
32 UnitAlgebra stopAtTime;
34 std::string statRateParam;
35 std::string statTypeParam;
36 std::string statStartAtTimeParam;
37 std::string statStopAtTimeParam;
38 Statistic<T>* statistic = NULL;
41 StatisticBase* prevStat = Simulation::getSimulation()->getStatisticsProcessingEngine()->isStatisticRegisteredWithEngine<T>(getName(), getId(), statName, statSubId);
42 if (NULL != prevStat) {
44 return dynamic_cast<Statistic<T>*
>(prevStat);
48 fullStatName = StatisticBase::buildStatisticFullName(getName().c_str(), statName, statSubId);
51 if (
true == Simulation::getSimulation()->isWireUpFinished()) {
53 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());
65 statEnableList = Simulation::getSimulation()->getComponentStatisticEnableList(getId());
66 statParamsList = Simulation::getSimulation()->getComponentStatisticParamsList(getId());
71 for (uint32_t x = 0; x < statEnableList->size(); x++) {
75 if ((std::string(STATALLFLAG) == statEnableList->at(x)) || (statName == statEnableList->at(x))) {
77 Params::KeySet_t allowedKeySet;
78 allowedKeySet.insert(
"type");
79 allowedKeySet.insert(
"rate");
80 allowedKeySet.insert(
"startat");
81 allowedKeySet.insert(
"stopat");
82 statParamsList->at(x).pushAllowedKeys(allowedKeySet);
86 statTypeParam = statParamsList->at(x).find<std::string>(
"type",
"sst.AccumulatorStatistic");
87 statRateParam = statParamsList->at(x).find<std::string>(
"rate",
"0ns");
88 statStartAtTimeParam = statParamsList->at(x).find<std::string>(
"startat",
"0ns");
89 statStopAtTimeParam = statParamsList->at(x).find<std::string>(
"stopat",
"0ns");
92 if (
true == statRateParam.empty()) {
93 statRateParam =
"0ns";
95 if (
true == statStartAtTimeParam.empty()) {
96 statStartAtTimeParam =
"0ns";
98 if (
true == statStopAtTimeParam.empty()) {
99 statStopAtTimeParam =
"0ns";
102 collectionRate = UnitAlgebra(statRateParam);
103 startAtTime = UnitAlgebra(statStartAtTimeParam);
104 stopAtTime = UnitAlgebra(statStopAtTimeParam);
105 statParams = statParamsList->at(x);
112 if (
false == nameFound) {
114 out.verbose(CALL_INFO, 1, 0,
" Warning: Statistic %s is not enabled in python script, statistic will not be enabled...\n", fullStatName.c_str());
117 if (
true == statGood) {
119 if ((
true == collectionRate.hasUnits(
"s")) ||
120 (
true == collectionRate.hasUnits(
"hz")) ) {
122 statCollectionMode = StatisticBase::STAT_MODE_PERIODIC;
123 }
else if (
true == collectionRate.hasUnits(
"event")) {
125 statCollectionMode = StatisticBase::STAT_MODE_COUNT;
126 }
else if (0 == collectionRate.getValue()) {
128 collectionRate = UnitAlgebra(
"0ns");
129 statCollectionMode = StatisticBase::STAT_MODE_PERIODIC;
132 fprintf(stderr,
"ERROR: Statistic %s - Collection Rate = %s not valid; exiting...\n", fullStatName.c_str(), collectionRate.toString().c_str());
137 if ((
true != startAtTime.hasUnits(
"s")) || (
true != stopAtTime.hasUnits(
"s"))) {
139 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());
144 if (
true == statGood) {
146 statistic = CreateStatistic<T>(
this, statTypeParam, statName, statSubId, statParams);
147 if (NULL == statistic) {
148 fprintf(stderr,
"ERROR: Unable to instantiate Statistic %s; exiting...\n", fullStatName.c_str());
153 if (
false == statistic->isStatModeSupported(statCollectionMode)) {
154 if (StatisticBase::STAT_MODE_PERIODIC == statCollectionMode) {
155 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());
157 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());
163 statistic->setRegisteredCollectionMode(statCollectionMode);
167 if (
true == statGood) {
170 uint8_t enableLevel = getComponentInfoStatisticEnableLevel(statistic->getStatName());
171 uint8_t loadLevel = Simulation::getStatisticsOutput()->getStatisticLoadLevel();
172 if (0 == loadLevel) {
173 out.verbose(CALL_INFO, 1, 0,
" Warning: Statistic Load Level = 0 (all statistics disabled); statistic %s is disabled...\n", fullStatName.c_str());
178 }
else if (enableLevel > loadLevel) {
179 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);
185 if (
true == statGood) {
188 if (StatisticBase::STAT_MODE_PERIODIC == statCollectionMode) {
189 if (
false == Simulation::getSimulation()->getStatisticsProcessingEngine()->addPeriodicBasedStatistic(collectionRate, statistic)) {
193 if (
false == Simulation::getSimulation()->getStatisticsProcessingEngine()->addEventBasedStatistic(collectionRate, statistic)) {
201 if (
true == statGood) {
203 StatisticOutput* statOutput = Simulation::getSimulation()->getStatisticsOutput();
204 statOutput->startRegisterFields(statistic->getCompName().c_str(), statistic->getStatName().c_str());
205 statistic->registerOutputFields(statOutput);
206 statOutput->stopRegisterFields();
209 Simulation::getSimulation()->getStatisticsProcessingEngine()->setStatisticStartTime(startAtTime, statistic);
210 Simulation::getSimulation()->getStatisticsProcessingEngine()->setStatisticStopTime(stopAtTime, statistic);
213 if (NULL != statistic) {
218 statTypeParam =
"sst.NullStatistic";
219 statistic = CreateStatistic<T>(
this, statTypeParam, statName, statSubId, statParams);
220 if (NULL == statistic) {
222 fprintf(stderr,
"ERROR: Unable to instantiate Null Statistic %s; exiting...\n", fullStatName.c_str());
228 Simulation::getSimulation()->getStatisticsProcessingEngine()->registerStatisticWithEngine<T>(getId(), statistic);
232 #endif //_H_SST_CORE_COMP_REG_STAT__