15 #include "trace-common.h"
17 // initial bin size, time in seconds
18 #define BIN_SIZE 0.001
22 #define MAX_PHASES 100
24 /// Bin entry record CPU time in an interval
27 void *operator new(size_t s
) {void*ret
=malloc(s
);_MEMCHECK(ret
);return ret
;}
28 void *operator new(size_t, void *ptr
) { return ptr
; }
29 void operator delete(void *ptr
) { free(ptr
); }
30 #if defined(_WIN32) || CMK_MULTIPLE_DELETE
31 void operator delete(void *, void *) { }
33 BinEntry(): _time(0.), _idleTime(0.) {}
34 BinEntry(double t
, double idleT
): _time(t
), _idleTime(idleT
) {}
35 double &time() { return _time
; }
36 double &getIdleTime() { return _idleTime
; }
45 /// a phase entry for trace summary
54 ~PhaseEntry() { delete [] count
; delete [] times
; delete [] maxtimes
; }
55 /// one entry is called for 'time' seconds.
56 void setEp(int epidx
, double time
) {
57 if (epidx
>=nEPs
) CmiAbort("Too many entry functions!\n");
60 if (maxtimes
[epidx
] < time
) maxtimes
[epidx
] = time
;
63 write two lines for each phase:
64 1. number of calls for each entry;
65 2. time in us spent for each entry.
67 void write(FILE *fp
, int seq
) {
69 fprintf(fp
, "[%d] ", seq
);
70 int _numEntries
=_entryTable
.size();
71 for (i
=0; i
<_numEntries
; i
++)
72 fprintf(fp
, "%d ", count
[i
]);
75 fprintf(fp
, "[%d] ", seq
);
76 for (i
=0; i
<_numEntries
; i
++)
77 fprintf(fp
, "%ld ", (long)(times
[i
]*1.0e6
) );
80 fprintf(fp
, "[%d] ", seq
);
81 for (i
=0; i
<_numEntries
; i
++)
82 fprintf(fp
, "%ld ", (long)(maxtimes
[i
]*1.0e6
) );
87 /// table of PhaseEntry
91 int numPhase
; /**< phase table size */
92 int cur_phase
; /**< current phase */
93 int phaseCalled
; /**< total number of phases */
95 PhaseTable(int n
): numPhase(n
) {
96 phases
= new PhaseEntry
*[n
];
98 for (int i
=0; i
<n
; i
++) phases
[i
] = NULL
;
103 for (int i
=0; i
<numPhase
; i
++) delete phases
[i
];
106 inline int numPhasesCalled() { return phaseCalled
; };
108 start a phase. If new, create a new PhaseEntry
110 void startPhase(int p
) {
111 if (p
<0 && p
>=numPhase
) CmiAbort("Invalid Phase number. \n");
113 if (phases
[cur_phase
] == NULL
) {
114 phases
[cur_phase
] = new PhaseEntry
;
115 _MEMCHECK(phases
[cur_phase
]);
119 void setEp(int epidx
, double time
) {
120 if (cur_phase
== -1) return;
121 if (phases
[cur_phase
] == NULL
) CmiAbort("No current phase!\n");
122 phases
[cur_phase
]->setEp(epidx
, time
);
124 void write(FILE *fp
) {
125 for (int i
=0; i
<numPhase
; i
++ )
127 phases
[i
]->write(fp
, i
);
135 /// info for each entry
141 enum {HIST_SIZE
= 10};
144 SumEntryInfo(): epTime(0.), epMaxTime(0.), epCount(0) {}
146 epTime
= epMaxTime
= 0.;
148 for (int i
=0; i
<HIST_SIZE
; i
++) hist
[i
]=0;
150 void setTime(double t
) {
153 if (epMaxTime
< t
) epMaxTime
= t
;
154 for (int i
=HIST_SIZE
-1; i
>=0; i
--) {
155 if (t
>epThreshold
+i
*epInterval
) {
167 BinEntry
*pool
; /**< bins */
168 FILE *fp
, *stsfp
, *sdfp
;
171 SumEntryInfo
*epInfo
;
174 /// a mark entry for trace summary
178 CkVec
<MarkEntry
*> events
[MAX_MARKS
];
184 /// for Summary-Detail
185 double *cpuTime
; //[MAX_INTERVALS * MAX_ENTRIES];
186 int *numExecutions
; //[MAX_INTERVALS * MAX_ENTRIES];
189 SumLogPool(char *pgm
);
191 double *getCpuTime() {return cpuTime
;}
195 void add(double time
, double idleTime
, int pe
);
196 void setEp(int epidx
, double time
);
198 for(int i
=0; i
< epInfoSize
; i
++) {
203 void shrink(double max
);
204 void addEventType(int eventType
, double time
);
205 void startPhase(int phase
) { phaseTab
.startPhase(phase
); }
206 BinEntry
*bins() { return pool
; }
207 UInt
getNumEntries() { return numBins
; }
208 UInt
getEpInfoSize() {return epInfoSize
;}
209 UInt
getPoolSize() {return poolSize
;}
210 // accessors to normal summary data
211 inline double getTime(unsigned int interval
) {
212 return pool
[interval
].time();
216 inline double getCPUtime(unsigned int interval
, unsigned int ep
){
218 return cpuTime
[interval
*epInfoSize
+ep
];
223 inline void setCPUtime(unsigned int interval
, unsigned int ep
, double val
){
224 cpuTime
[interval
*epInfoSize
+ep
] = val
; }
225 inline double addToCPUtime(unsigned int interval
, unsigned int ep
, double val
){
226 cpuTime
[interval
*epInfoSize
+ep
] += val
;
227 return cpuTime
[interval
*epInfoSize
+ep
]; }
228 inline int getNumExecutions(unsigned int interval
, unsigned int ep
){
229 return numExecutions
[interval
*epInfoSize
+ep
]; }
230 inline void setNumExecutions(unsigned int interval
, unsigned int ep
, unsigned int val
){
231 numExecutions
[interval
*epInfoSize
+ep
] = val
; }
232 inline int incNumExecutions(unsigned int interval
, unsigned int ep
){
233 ++numExecutions
[interval
*epInfoSize
+ep
];
234 return numExecutions
[interval
*epInfoSize
+ep
]; }
235 inline int getUtilization(int interval
, int ep
);
238 void updateSummaryDetail(int epIdx
, double startTime
, double endTime
);
243 /// class for recording trace summary events
245 TraceSummary calculate CPU utilizations in bins, and will record
246 number of calls and total wall time for each entry.
248 class TraceSummary
: public Trace
{
249 SumLogPool
* _logPool
;
253 int msgNum
; /* used to handle multiple endComputation calls?? */
255 /* per-log metadata maintained to derive cross-event information */
256 double binStart
; /* time of last filled bin? */
257 double start
, packstart
, unpackstart
, idleStart
;
258 double binTime
, binIdle
;
263 TraceSummary(char **argv
);
264 void creation(envelope
*e
, int epIdx
, int num
=1) {}
266 void beginExecute(envelope
*e
, void *obj
);
267 void beginExecute(char *msg
);
268 void beginExecute(CmiObjId
*tid
);
269 void beginExecute(int event
,int msgType
,int ep
,int srcPe
, int mlen
=0, CmiObjId
*idx
=NULL
, void *obj
=NULL
);
270 void endExecute(void);
271 void endExecute(char *msg
);
272 void beginIdle(double currT
);
273 void endIdle(double currT
);
274 void traceBegin(void);
276 void beginPack(void);
278 void beginUnpack(void);
279 void endUnpack(void);
280 void beginComputation(void);
281 void endComputation(void);
283 void traceClearEps();
284 void traceWriteSts();
288 for trace summary event mark
290 void addEventType(int eventType
);
292 for starting a new phase
294 void startPhase(int phase
);
299 SumLogPool
*pool() { return _logPool
; }
302 * Supporting methods for CCS queries
304 void traceEnableCCS();
305 void fillData(double *buffer
, double reqStartTime
,
306 double reqBinSize
, int reqNumBins
);