00001
00002
00007 #ifndef STATS_H
00008 #define STATS_H
00009 #include "stats.decl.h"
00010 #include "pose_config.h"
00011
00012
00013 #define DO_TIMER 1
00014 #define RB_TIMER 2
00015 #define GVT_TIMER 3
00016 #define SIM_TIMER 4
00017 #define CAN_TIMER 5
00018 #define CP_TIMER 6
00019 #define LB_TIMER 7
00020 #define FC_TIMER 8
00021 #define COMM_TIMER 9
00022
00023
00024 extern CkChareID theGlobalStats;
00025 extern CkGroupID theLocalStats;
00026
00027 extern POSE_Config pose_config;
00028
00030 class localStatSummary : public CMessage_localStatSummary {
00031 public:
00032 double doTime, rbTime, gvtTime, simTime, cpTime, canTime, lbTime, fcTime,
00033 commTime, maxDo, minDo, maxGRT;
00034 long cpBytes;
00035 int pe, dos, undos, commits, loops, gvts, maxChkPts;
00036 POSE_TimeType maxGVT;
00037 };
00038
00040 class localStat : public Group {
00041 private:
00043 short int whichStat;
00045 int rollbacks, dos, undos, commits, loops, gvts, chkPts, maxChkPts;
00047 long cpBytes;
00049 double dot, rbt, gvtt, simt, cpt, cant, lbt, fct, commt;
00051 double rollbackTime, totalTime, gvtTime, simTime, cpTime, canTime,
00052 lbTime, fcTime, commTime, maxDo, minDo;
00054
00055 POSE_TimeType maxGVT;
00056 double maxGRT;
00058 char dopFileName[20];
00060 FILE *dopFilePtr;
00061 public:
00063 localStat(void) : whichStat(0),rollbacks(0),dos(0),undos(0),commits(0),loops(0),gvts(0),cpBytes(0),chkPts(0),maxChkPts(0), maxGVT (0),
00064 rollbackTime(0.0),totalTime(0.0),gvtTime(0.0),simTime(0.0),cpTime(0.0),canTime(0.0),lbTime(0.0),fcTime(0.0),
00065 commTime(0.0),maxGRT(0.0),
00066 maxDo(-1.0),minDo(-1.0)
00067 {
00068 #ifdef VERBOSE_DEBUG
00069 CkPrintf("[%d] constructing localStat\n",CkMyPe());
00070 #endif
00071 if (pose_config.dop) {
00072 sprintf(dopFileName, "dop%d.log", CkMyPe());
00073 dopFilePtr = fopen(dopFileName, "w");
00074 if (dopFilePtr == NULL) {
00075 CkPrintf("ERROR: unable to open DOP file %s for writing\n", dopFileName);
00076 CkAbort("Error opening file");
00077 }
00078 }
00079 }
00081 localStat(CkMigrateMessage *msg) : Group(msg) { };
00083 ~localStat() {
00084 fclose(dopFilePtr);
00085 }
00087 void TimerStart(int timer);
00089 void TimerStop();
00091 void SwitchTimer(int timer);
00093 inline void Do() { dos++; }
00095 inline void Undo() { undos++; }
00097 inline void Commit() { commits++; }
00099 inline void Loop() { loops++; }
00101 inline void GvtInc() { gvts++; }
00103 inline void Rollback() { rollbacks++; }
00105 inline void Checkpoint() { chkPts++; if (chkPts > maxChkPts) maxChkPts = chkPts; }
00107 inline void Reclaim() { chkPts--; }
00109 inline void CPbytes(int n) { cpBytes += n; }
00111 void SendStats();
00113 inline int TimerRunning() { return (whichStat); }
00115 inline void SetMaximums(POSE_TimeType gvt, double grt) {
00116 if (gvt > maxGVT) maxGVT = gvt;
00117 if (grt > maxGRT) maxGRT = grt;
00118 }
00120 inline void WriteDopData(double srt, double ert, POSE_TimeType svt, POSE_TimeType evt) {
00121 #if USE_LONG_TIMESTAMPS
00122 const char* format = "%f %f %lld %lld\n";
00123 #else
00124 const char* format = "%f %f %d %d\n";
00125 #endif
00126
00127
00128 if (fprintf(dopFilePtr, format, srt, ert, svt, evt) <= 0) {
00129 CkPrintf("WARNING: DOP data not written to %s\n", dopFileName);
00130 }
00131 }
00132 };
00133 PUPbytes(localStat)
00134
00135
00136 class globalStat : public Chare {
00137 private:
00138 double doAvg, doMax, rbAvg, rbMax, gvtAvg, gvtMax, simAvg, simMax, cpAvg,
00139 cpMax, canAvg, canMax, lbAvg, lbMax, fcAvg, fcMax, commAvg, commMax, maxTime;
00140 double minDo, maxDo, avgDo, GvtTime, maxGRT;
00141 long cpBytes;
00142 int reporting, totalDos, totalUndos, totalCommits, totalLoops, totalGvts, maxChkPts;
00143 POSE_TimeType maxGVT;
00144 public:
00146 globalStat(void);
00148 globalStat(CkMigrateMessage *msg) { };
00150 void localStatReport(localStatSummary *m);
00151 void DOPcalc(POSE_TimeType gvt, double grt);
00152 };
00153 PUPbytes(globalStat)
00154
00155
00156
00157
00158 inline void localStat::TimerStart(int timer)
00159 {
00160 double now;
00161 if (whichStat > 0) {
00162 CkPrintf("WARNING: timer %d active. Switching to timer %d.\n",
00163 whichStat, timer);
00164 SwitchTimer(timer);
00165 return;
00166 }
00167 now = CmiWallTimer();
00168 whichStat = timer;
00169 switch (timer) {
00170 case DO_TIMER: dot = now; break;
00171 case RB_TIMER: rbt = now; break;
00172 case GVT_TIMER: gvtt = now; break;
00173 case SIM_TIMER: simt = now; break;
00174 case CP_TIMER: cpt = now; break;
00175 case CAN_TIMER: cant = now; break;
00176 case LB_TIMER: lbt = now; break;
00177 case FC_TIMER: fct = now; break;
00178 case COMM_TIMER: commt = now; break;
00179 default: CkPrintf("ERROR: Invalid timer %d\n", timer);
00180 }
00181 }
00182
00183
00184 inline void localStat::TimerStop()
00185 {
00186 double now;
00187 now = CmiWallTimer();
00188 switch (whichStat) {
00189 case DO_TIMER:
00190 {
00191 double eventTime = now - dot;
00192 totalTime += eventTime;
00193 if (maxDo < eventTime)
00194 maxDo = eventTime;
00195 if ((minDo < 0.0) || (minDo > eventTime))
00196 minDo = eventTime;
00197 break;
00198 }
00199 case RB_TIMER: rollbackTime += now - rbt; break;
00200 case GVT_TIMER: gvtTime += now - gvtt; break;
00201 case SIM_TIMER: simTime += now - simt; break;
00202 case CP_TIMER: cpTime += now - cpt; break;
00203 case CAN_TIMER: canTime += now - cant; break;
00204 case LB_TIMER: lbTime += now - lbt; break;
00205 case FC_TIMER: fcTime += now - fct; break;
00206 case COMM_TIMER: commTime += now - commt; break;
00207 default: CkPrintf("ERROR: No timer active.\n");
00208 }
00209 whichStat = 0;
00210 }
00211
00212
00213
00214 inline void localStat::SwitchTimer(int timer)
00215 {
00216 double now;
00217 if (timer == whichStat)
00218 return;
00219 now = CmiWallTimer();
00220 switch (whichStat) {
00221 case DO_TIMER:
00222 {
00223 double eventTime = now - dot;
00224 totalTime += eventTime;
00225 if (maxDo < eventTime)
00226 maxDo = eventTime;
00227 if ((minDo < 0.0) || (minDo > eventTime))
00228 minDo = eventTime;
00229 break;
00230 }
00231 case RB_TIMER: rollbackTime += now - rbt; break;
00232 case GVT_TIMER: gvtTime += now - gvtt; break;
00233 case SIM_TIMER: simTime += now - simt; break;
00234 case CP_TIMER: cpTime += now - cpt; break;
00235 case CAN_TIMER: canTime += now - cant; break;
00236 case LB_TIMER: lbTime += now - lbt; break;
00237 case FC_TIMER: fcTime += now - fct; break;
00238 case COMM_TIMER: commTime += now - commt; break;
00239 default: CkPrintf("ERROR: No active timer.\n");
00240 }
00241 whichStat = timer;
00242 switch (timer) {
00243 case DO_TIMER: dot = now; break;
00244 case RB_TIMER: rbt = now; break;
00245 case GVT_TIMER: gvtt = now; break;
00246 case SIM_TIMER: simt = now; break;
00247 case CP_TIMER: cpt = now; break;
00248 case CAN_TIMER: cant = now; break;
00249 case LB_TIMER: lbt = now; break;
00250 case FC_TIMER: fct = now; break;
00251 case COMM_TIMER: commt = now; break;
00252 default: CkPrintf("ERROR: Invalid timer %d\n", timer);
00253 }
00254 }
00255
00256 #endif