00001
00005
00006 #ifndef _SUMMARY_H
00007 #define _SUMMARY_H
00008
00009 #include <stdio.h>
00010 #include <errno.h>
00011
00012 #include "trace.h"
00013 #include "envelope.h"
00014 #include "register.h"
00015 #include "trace-common.h"
00016
00017
00018 #define BIN_SIZE 0.001
00019
00020 #define MAX_MARKS 256
00021
00022 #define MAX_PHASES 100
00023
00025 class BinEntry {
00026 public:
00027 void *operator new(size_t s) {void*ret=malloc(s);_MEMCHECK(ret);return ret;}
00028 void *operator new(size_t, void *ptr) { return ptr; }
00029 void operator delete(void *ptr) { free(ptr); }
00030 #if defined(_WIN32) || CMK_MULTIPLE_DELETE
00031 void operator delete(void *, void *) { }
00032 #endif
00033 BinEntry(): _time(0.), _idleTime(0.) {}
00034 BinEntry(double t, double idleT): _time(t), _idleTime(idleT) {}
00035 double &time() { return _time; }
00036 double &getIdleTime() { return _idleTime; }
00037 void write(FILE *fp);
00038 int getU();
00039 int getUIdle();
00040 private:
00041 double _time;
00042 double _idleTime;
00043 };
00044
00046 class PhaseEntry {
00047 private:
00048 int nEPs;
00049 int *count;
00050 double *times;
00051 double *maxtimes;
00052 public:
00053 PhaseEntry();
00054 ~PhaseEntry() { delete [] count; delete [] times; delete [] maxtimes; }
00056 void setEp(int epidx, double time) {
00057 if (epidx>=nEPs) CmiAbort("Too many entry functions!\n");
00058 count[epidx]++;
00059 times[epidx] += time;
00060 if (maxtimes[epidx] < time) maxtimes[epidx] = time;
00061 }
00067 void write(FILE *fp, int seq) {
00068 int i;
00069 fprintf(fp, "[%d] ", seq);
00070 int _numEntries=_entryTable.size();
00071 for (i=0; i<_numEntries; i++)
00072 fprintf(fp, "%d ", count[i]);
00073 fprintf(fp, "\n");
00074
00075 fprintf(fp, "[%d] ", seq);
00076 for (i=0; i<_numEntries; i++)
00077 fprintf(fp, "%ld ", (long)(times[i]*1.0e6) );
00078 fprintf(fp, "\n");
00079
00080 fprintf(fp, "[%d] ", seq);
00081 for (i=0; i<_numEntries; i++)
00082 fprintf(fp, "%ld ", (long)(maxtimes[i]*1.0e6) );
00083 fprintf(fp, "\n");
00084 }
00085 };
00086
00088 class PhaseTable {
00089 private:
00090 PhaseEntry **phases;
00091 int numPhase;
00092 int cur_phase;
00093 int phaseCalled;
00094 public:
00095 PhaseTable(int n): numPhase(n) {
00096 phases = new PhaseEntry*[n];
00097 _MEMCHECK(phases);
00098 for (int i=0; i<n; i++) phases[i] = NULL;
00099 cur_phase = -1;
00100 phaseCalled = 0;
00101 }
00102 ~PhaseTable() {
00103 for (int i=0; i<numPhase; i++) delete phases[i];
00104 delete [] phases;
00105 }
00106 inline int numPhasesCalled() { return phaseCalled; };
00110 void startPhase(int p) {
00111 if (p<0 && p>=numPhase) CmiAbort("Invalid Phase number. \n");
00112 cur_phase = p;
00113 if (phases[cur_phase] == NULL) {
00114 phases[cur_phase] = new PhaseEntry;
00115 _MEMCHECK(phases[cur_phase]);
00116 phaseCalled ++;
00117 }
00118 }
00119 void setEp(int epidx, double time) {
00120 if (cur_phase == -1) return;
00121 if (phases[cur_phase] == NULL) CmiAbort("No current phase!\n");
00122 phases[cur_phase]->setEp(epidx, time);
00123 }
00124 void write(FILE *fp) {
00125 for (int i=0; i<numPhase; i++ )
00126 if (phases[i]) {
00127 phases[i]->write(fp, i);
00128 }
00129 }
00130 };
00131
00132 double epThreshold;
00133 double epInterval;
00134
00136 class SumEntryInfo {
00137 public:
00138 double epTime;
00139 double epMaxTime;
00140 int epCount;
00141 enum {HIST_SIZE = 10};
00142 int hist[HIST_SIZE];
00143 public:
00144 SumEntryInfo(): epTime(0.), epMaxTime(0.), epCount(0) {}
00145 void clear() {
00146 epTime = epMaxTime = 0.;
00147 epCount = 0;
00148 for (int i=0; i<HIST_SIZE; i++) hist[i]=0;
00149 }
00150 void setTime(double t) {
00151 epTime += t;
00152 epCount ++;
00153 if (epMaxTime < t) epMaxTime = t;
00154 for (int i=HIST_SIZE-1; i>=0; i--) {
00155 if (t>epThreshold+i*epInterval) {
00156 hist[i]++; break;
00157 }
00158 }
00159 }
00160 };
00161
00163 class SumLogPool {
00164 private:
00165 UInt poolSize;
00166 UInt numBins;
00167 BinEntry *pool;
00168 FILE *fp, *stsfp, *sdfp ;
00169 char *pgm;
00170
00171 SumEntryInfo *epInfo;
00172 UInt epInfoSize;
00173
00175 typedef struct {
00176 double time;
00177 } MarkEntry;
00178 CkVec<MarkEntry *> events[MAX_MARKS];
00179 int markcount;
00180
00182 PhaseTable phaseTab;
00183
00185 double *cpuTime;
00186 int *numExecutions;
00187
00188 public:
00189 SumLogPool(char *pgm);
00190 ~SumLogPool();
00191 double *getCpuTime() {return cpuTime;}
00192 void initMem();
00193 void write(void) ;
00194 void writeSts(void);
00195 void add(double time, double idleTime, int pe);
00196 void setEp(int epidx, double time);
00197 void clearEps() {
00198 for(int i=0; i < epInfoSize; i++) {
00199 epInfo[i].clear();
00200 }
00201 }
00202 void shrink(void);
00203 void shrink(double max);
00204 void addEventType(int eventType, double time);
00205 void startPhase(int phase) { phaseTab.startPhase(phase); }
00206 BinEntry *bins() { return pool; }
00207 UInt getNumEntries() { return numBins; }
00208 UInt getEpInfoSize() {return epInfoSize;}
00209 UInt getPoolSize() {return poolSize;}
00210
00211 inline double getTime(unsigned int interval) {
00212 return pool[interval].time();
00213 }
00214
00215
00216 inline double getCPUtime(unsigned int interval, unsigned int ep){
00217 if(cpuTime != NULL)
00218 return cpuTime[interval*epInfoSize+ep];
00219 else
00220 return 0.0;
00221 }
00222
00223 inline void setCPUtime(unsigned int interval, unsigned int ep, double val){
00224 cpuTime[interval*epInfoSize+ep] = val; }
00225 inline double addToCPUtime(unsigned int interval, unsigned int ep, double val){
00226 cpuTime[interval*epInfoSize+ep] += val;
00227 return cpuTime[interval*epInfoSize+ep]; }
00228 inline int getNumExecutions(unsigned int interval, unsigned int ep){
00229 return numExecutions[interval*epInfoSize+ep]; }
00230 inline void setNumExecutions(unsigned int interval, unsigned int ep, unsigned int val){
00231 numExecutions[interval*epInfoSize+ep] = val; }
00232 inline int incNumExecutions(unsigned int interval, unsigned int ep){
00233 ++numExecutions[interval*epInfoSize+ep];
00234 return numExecutions[interval*epInfoSize+ep]; }
00235 inline int getUtilization(int interval, int ep);
00236
00237
00238 void updateSummaryDetail(int epIdx, double startTime, double endTime);
00239
00240
00241 };
00242
00244
00248 class TraceSummary : public Trace {
00249 SumLogPool* _logPool;
00250 int execEvent;
00251 int execEp;
00252 int execPe;
00253 int msgNum;
00254
00255
00256 double binStart;
00257 double start, packstart, unpackstart, idleStart;
00258 double binTime, binIdle;
00259 int inIdle;
00260 int inExec;
00261 int depth;
00262 public:
00263 TraceSummary(char **argv);
00264 void creation(envelope *e, int epIdx, int num=1) {}
00265
00266 void beginExecute(envelope *e, void *obj);
00267 void beginExecute(char *msg);
00268 void beginExecute(CmiObjId *tid);
00269 void beginExecute(int event,int msgType,int ep,int srcPe, int mlen=0, CmiObjId *idx=NULL, void *obj=NULL);
00270 void endExecute(void);
00271 void endExecute(char *msg);
00272 void beginIdle(double currT);
00273 void endIdle(double currT);
00274 void traceBegin(void);
00275 void traceEnd(void);
00276 void beginPack(void);
00277 void endPack(void);
00278 void beginUnpack(void);
00279 void endUnpack(void);
00280 void beginComputation(void);
00281 void endComputation(void);
00282
00283 void traceClearEps();
00284 void traceWriteSts();
00285 void traceClose();
00286
00290 void addEventType(int eventType);
00294 void startPhase(int phase);
00295
00299 SumLogPool *pool() { return _logPool; }
00300
00304 void traceEnableCCS();
00305 void fillData(double *buffer, double reqStartTime,
00306 double reqBinSize, int reqNumBins);
00307 };
00308
00309 #endif
00310