Link conv-cpm as C++
[charm.git] / src / ck-perf / trace-controlPoints.h
blob64786b2ecdb7836b8081340f0496bdf776c94ad2
1 #ifndef _VERBOSE_H
2 #define _VERBOSE_H
4 #include <stdio.h>
5 #include <errno.h>
7 #include "trace.h"
8 #include "envelope.h"
9 #include "register.h"
10 #include "trace-common.h"
12 /**
13 * \addtogroup ControlPointFramework
14 * @{
18 /**
19 * An instrumentation module making use of
20 * the tracing framework hooks provided in Charm++. It is used
21 * by the control point framework to monitor idle time.
23 * Only the more common hooks are listened to in this module.
25 class TraceControlPoints : public Trace {
26 private:
28 double lastBeginExecuteTime;
29 int lastbeginMessageSize;
31 /** The start of the idle region */
32 double lastBeginIdle;
34 /** Amount of time spent so far in untraced regions */
35 double totalUntracedTime;
37 /** When tracing was suspended (0 if not currently suspended) */
38 double whenStoppedTracing;
40 /** The amount of time spent executing entry methods since we last reset the counters */
41 double totalEntryMethodTime;
43 /** The amount of time spent idle since we last reset the counters */
44 double totalIdleTime;
46 /** The highest seen memory usage since we last reset the counters */
47 double memUsage;
49 /** The number of entry method invocations since we last reset the counters */
50 long totalEntryMethodInvocations;
53 /** The time we last rest the counters */
54 double lastResetTime;
56 public:
57 int b1, b2, b3;
58 long b2mlen;
59 long b3mlen;
61 // In some programs like Changa, entry methods may be nested, and hence we only want to consider the outermost one
62 int nesting_level;
65 public:
66 TraceControlPoints(char **argv);
68 //begin/end tracing
69 void traceBegin(void);
70 void traceEnd(void);
73 // a user event has just occured
74 void userEvent(int eventID);
75 // a pair of begin/end user event has just occured
76 void userBracketEvent(int eventID, double bt, double et);
78 // "creation" of message(s) - message Sends
79 void creation(envelope *, int epIdx, int num=1);
80 void creationMulticast(envelope *, int epIdx, int num=1, int *pelist=NULL);
81 void creationDone(int num=1);
83 void messageRecv(char *env, int pe);
85 // **************************************************************
86 // begin/end execution of a Charm++ entry point
87 // NOTE: begin/endPack and begin/endUnpack can be called in between
88 // a beginExecute and its corresponding endExecute.
89 void beginExecute(envelope *);
90 void beginExecute(CmiObjId *tid);
91 void beginExecute(
92 int event, // event type defined in trace-common.h
93 int msgType, // message type
94 int ep, // Charm++ entry point id
95 int srcPe, // Which PE originated the call
96 int ml, // message size
97 CmiObjId* idx); // index
98 void endExecute(void);
100 // begin/end idle time for this pe
101 void beginIdle(double curWallTime);
102 void endIdle(double curWallTime);
104 // begin/end of execution
105 void beginComputation(void);
106 void endComputation(void);
108 /* Memory tracing */
109 void malloc(void *where, int size, void **stack, int stackSize);
110 void free(void *where, int size);
112 // do any clean-up necessary for tracing
113 void traceClose();
116 // ==================================================================
117 // The following methods are not required for a tracing module
119 /** reset the idle time and entry method execution time accumulators */
120 void resetTimings();
122 /** Reset the idle, overhead, and memory measurements */
123 void resetAll();
125 /** Fraction of the time spent idle since resetting the counters */
126 double idleRatio(){
127 double t = CmiWallTimer() - lastResetTime;
128 return (totalIdleTime) / (t-untracedTime());
131 double untracedTime(){
132 if(whenStoppedTracing == 0){
133 return totalUntracedTime;
134 } else {
135 return totalUntracedTime + (CmiWallTimer()-whenStoppedTracing);
140 /** Fraction of time spent as overhead since resetting the counters */
141 double overheadRatio(){
142 double t = CmiWallTimer() - lastResetTime;
143 return (t - totalIdleTime - totalEntryMethodTime) / (t-untracedTime());
146 /** Highest memory usage (in MB) value we've seen since resetting the counters */
147 double memoryUsageMB(){
148 return ((double)memUsage) / 1024.0 / 1024.0;
151 /** Determine the average grain size since last reset of counters */
152 double grainSize(){
153 return (double)totalEntryMethodTime / totalEntryMethodInvocations;
156 double bytesPerEntry() {
157 return (double)(b2mlen + b3mlen) / (double)(b2+b3);
164 TraceControlPoints *localControlPointTracingInstance();
167 /*! @} */
168 #endif