Bug #1062: Fix linking errors by moving definition of userDrivenMode to machine-commo...
[charm.git] / src / ck-perf / trace-controlPoints.C
blob51cc6a19bbe9b6a19da25d3f365439380f34e843
1 #include "charm++.h"
2 #include "trace-controlPoints.h"
3 #include "trace-controlPointsBOC.h"
6 /**
7  *   \addtogroup ControlPointFramework
8  *   @{
9  */
12 // Charm++ "processor"(user thread)-private global variable
13 CkpvStaticDeclare(TraceControlPoints*, _trace);
15 // This global variable is required for any post-execution 
16 // parallel analysis or parallel activities the trace module 
17 // might wish to perform.
18 CkGroupID traceControlPointsGID;
20 /**
21   For each TraceFoo module, _createTraceFoo() must be defined.
22   This function is called in _createTraces() generated in moduleInit.C
24   This module is special in that it is always included in charm, but sometimes it does nothing.
25   This is called on all processors in SMP version.
27 void _createTracecontrolPoints(char **argv)
29   CkpvInitialize(TraceControlPoints*, _trace);
30   CkpvAccess(_trace) = new TraceControlPoints(argv);
31   CkpvAccess(_traces)->addTrace(CkpvAccess(_trace));
34 TraceControlPoints::TraceControlPoints(char **argv)
36   resetTimings();
38   nesting_level = 0;
40   whenStoppedTracing = 0;
42   b1=0;
43   b2=0;
44   b3=0;
46   if (CkpvAccess(traceOnPe) == 0) return;
48   // Process runtime arguments intended for the module
49   // CmiGetArgIntDesc(argv,"+ControlPointsPar0", &par0, "Fake integer parameter 0");
53 void TraceControlPoints::traceBegin(void){
54   if(whenStoppedTracing != 0)
55     totalUntracedTime += CmiWallTimer() - whenStoppedTracing;
56   whenStoppedTracing = 0;
57   CkPrintf("[%d] TraceControlPoints::traceBegin() totalUntracedTime=%f\n", CkMyPe(), totalUntracedTime);
61 void TraceControlPoints::traceEnd(void){
62   CkPrintf("[%d] TraceControlPoints::traceEnd()\n", CkMyPe());
63   CkAssert(whenStoppedTracing == 0); // can't support nested traceEnds on one processor yet...
64   whenStoppedTracing = CmiWallTimer();
69 void TraceControlPoints::userEvent(int eventID) 
71   //  CkPrintf("[%d] User Point Event id %d encountered\n", CkMyPe(), eventID);
74 void TraceControlPoints::userBracketEvent(int eventID, double bt, double et) {
75   //  CkPrintf("[%d] User Bracket Event id %d encountered\n", CkMyPe(), eventID);
78 void TraceControlPoints::creation(envelope *, int epIdx, int num) {
79   //  CkPrintf("[%d] Point-to-Point Message for Entry Method id %d sent\n",  CkMyPe(), epIdx);
82 void TraceControlPoints::creationMulticast(envelope *, int epIdx, int num, 
83                                     int *pelist) {
84   //  CkPrintf("[%d] Multicast Message for Entry Method id %d sent to %d pes\n", CkMyPe(), epIdx, num);
87 void TraceControlPoints::creationDone(int num) {
88   //  CkPrintf("[%d] Last initiated send completes\n", CkMyPe());
90   
91 void TraceControlPoints::messageRecv(char *env, int pe) {
92   // CkPrintf("[%d] Message from pe %d received by scheduler\n", CkMyPe(), pe);
94   
95 void TraceControlPoints::beginExecute(CmiObjId *tid)
97   nesting_level++;
98   if(nesting_level == 1){
99     // CmiObjId is a 4-integer tuple uniquely identifying a migratable
100     //   Charm++ object. Note that there are other non-migratable Charm++
101     //   objects that CmiObjId will not identify.
102     b1++;
103     lastBeginExecuteTime = CmiWallTimer();
104     lastbeginMessageSize = -1;
105   }
110 void TraceControlPoints::beginExecute(envelope *e)
112   nesting_level++;
113   if(nesting_level == 1){
114     lastBeginExecuteTime = CmiWallTimer();
115     lastbeginMessageSize = e->getTotalsize();
116     b2++;
117     b2mlen += lastbeginMessageSize;
118   }
121 void TraceControlPoints::beginExecute(int event,int msgType,int ep,int srcPe, 
122                                int mlen, CmiObjId *idx)
124   nesting_level++;
125   if(nesting_level == 1){
126     b3++;
127     b3mlen += mlen;
128     lastBeginExecuteTime = CmiWallTimer();
129     lastbeginMessageSize = mlen;
130   }
133 void TraceControlPoints::endExecute(void)
135   //  CkPrintf("TraceControlPoints::endExecute\n");
136   nesting_level--;
137   if(nesting_level == 0){
138     
139     double executionTime = CmiWallTimer() - lastBeginExecuteTime;
140     totalEntryMethodTime += executionTime;
141     totalEntryMethodInvocations ++;
142     
143     double m = (double)CmiMemoryUsage();
144     if(memUsage < m){
145       memUsage = m;
146     }    
147   }
150 void TraceControlPoints::beginIdle(double curWallTime) {
151   lastBeginIdle = CmiWallTimer();
152   // CkPrintf("[%d] Scheduler has no useful user-work\n", CkMyPe());
154   double m = (double)CmiMemoryUsage();
155   if(memUsage < m){
156     memUsage = m;
157   }
160 void TraceControlPoints::endIdle(double curWallTime) {
161   totalIdleTime += CmiWallTimer() - lastBeginIdle;
162   //  CkPrintf("[%d] Scheduler now has useful user-work\n", CkMyPe());
165 void TraceControlPoints::beginComputation(void)
167   CkPrintf("[%d] TraceControlPoints::beginComputation\n", CkMyPe());
168   // Code Below shows what trace-summary would do.
169   // initialze arrays because now the number of entries is known.
170   // _logPool->initMem();
173 void TraceControlPoints::endComputation(void)
175   CkPrintf("[%d] TraceControlPoints::endComputationn", CkMyPe());
178 void TraceControlPoints::malloc(void *where, int size, void **stack, int stackSize)
180   // CkPrintf("[%d] Memory allocation of size %d occurred\n", CkMyPe(), size);
181   double m = (double)CmiMemoryUsage();
182   if(memUsage < m){
183     memUsage = m;
184   }
187 void TraceControlPoints::free(void *where, int size) {
188   //  CkPrintf("[%d] %d-byte Memory block freed\n", CkMyPe(), size);
191 void TraceControlPoints::traceClose(void)
193   // Print out some performance counters on BG/P
194   CProxy_TraceControlPointsBOC myProxy(traceControlPointsGID);
196     
197   CkpvAccess(_trace)->endComputation();
198   // remove myself from traceArray so that no tracing will be called.
199   CkpvAccess(_traces)->removeTrace(this);
205 void TraceControlPoints::resetTimings(){
206   totalIdleTime = 0.0;
207   totalEntryMethodTime = 0.0;
208   totalEntryMethodInvocations = 0;
209   lastResetTime = CmiWallTimer();
210   totalUntracedTime = 0;
211   if(whenStoppedTracing !=0){
212     whenStoppedTracing = CmiWallTimer();
213   }
216 void TraceControlPoints::resetAll(){
217   totalIdleTime = 0.0;
218   totalEntryMethodTime = 0.0;
219   memUsage = 0;
220   totalEntryMethodInvocations = 0;
221   b2mlen=0;
222   b3mlen=0;
223   b2=0;
224   b3=0;
225   lastResetTime = CmiWallTimer();
226   totalUntracedTime = 0;
227   if(whenStoppedTracing !=0){
228     whenStoppedTracing = CmiWallTimer();
229   }
237 TraceControlPoints *localControlPointTracingInstance(){
238   return CkpvAccess(_trace);
243 extern "C" void traceControlPointsExitFunction() {
244   // The exit function of any Charm++ module must call CkExit() or
245   // the entire exit process will hang if multiple modules are linked.
246   // FIXME: This is NOT a feature. Something needs to be done about this.
247   CkExit();
250 // Initialization of the parallel trace module.
251 void initTraceControlPointsBOC() {
253 #ifdef __BIGSIM__
254   if (BgNodeRank()==0) {
255 #else
256     if (CkMyRank() == 0) {
257 #endif
258       registerExitFn(traceControlPointsExitFunction);
259     }
265 #include "TraceControlPoints.def.h"
268 /*@}*/