00001
00005
00006 #ifndef __trace_counter_h__
00007 #define __trace_counter_h__
00008
00009 #include <stdio.h>
00010 #include <errno.h>
00011 #include "trace.h"
00012 #include "trace-common.h"
00013 #include "conv-config.h"
00014
00015 #define MAX_ENTRIES 500
00016
00017
00018
00019
00020
00021
00023 class StatTable {
00024 public:
00025 StatTable();
00026 ~StatTable();
00027 void init(int argc);
00029 void setEp(int epidx, int stat, long long value, double time);
00034 void write(FILE* fp);
00035 void clear();
00036 int numStats() { return numStats_; }
00040 void doReduction(int phase, double idleTime);
00041
00042 private:
00044 struct Statistics {
00045 char* name;
00046 char* desc;
00047 unsigned int numCalled [MAX_ENTRIES];
00048 double avgCount [MAX_ENTRIES];
00049 double stdDevCount[MAX_ENTRIES];
00050 double totTime [MAX_ENTRIES];
00051 long long maxCount [MAX_ENTRIES];
00052 long long minCount [MAX_ENTRIES];
00053
00054 Statistics(): name(NULL) { }
00055 };
00056
00057 Statistics* stats_;
00058 int numStats_;
00059 };
00060
00063 class CountLogPool {
00064 public:
00065 CountLogPool();
00066 ~CountLogPool() { }
00067
00068
00069 void write(int phase=-1) ;
00070
00071
00072 void writeSts(int phase=-1);
00073 FILE* openFile(int phase=-1);
00074 void setEp(int epidx,
00075 int index1, long long count1,
00076 int index2, long long count2,
00077 double time);
00078 void clearEps() { stats_.clear(); }
00079 void init(int argc) { stats_.init(argc); }
00080 void doReduction(int phase, double idleTime) {
00081 stats_.doReduction(phase, idleTime);
00082 }
00083
00084 private:
00085 StatTable stats_;
00086 int lastPhase_;
00087 };
00088
00091 class TraceCounter : public Trace {
00092 public:
00093 TraceCounter();
00094 ~TraceCounter();
00096 void traceInit(char **argv);
00100 void traceBegin();
00101 void traceEnd();
00103 int traceRegisterUserEvent(const char* userEvent) {
00104
00105
00106 return 0;
00107 }
00109 void userEvent(int e) {
00110
00111 }
00113 void creation(envelope *e, int epIdx, int num=1) { }
00115 void messageRecv(char *env, int pe) { }
00119 void beginExecute(envelope *e);
00120 void beginExecute(
00121 int event,
00122 int msgType,
00123 int ep,
00124 int srcPe,
00125 int ml=0,
00126 CmiObjId *idx=0);
00127 void endExecute();
00129 void beginIdle(double curWallTime);
00130 void endIdle(double curWallTime);
00132 void beginPack();
00133 void endPack();
00136 void beginUnpack();
00137 void endUnpack();
00139 void enqueue(envelope *e) { }
00140 void dequeue(envelope *e) { }
00142 void beginComputation();
00143 void endComputation();
00145 void traceClearEps();
00147 void traceWriteSts();
00149 void traceClose();
00150
00153 struct CounterArg {
00154 int code;
00155 char* arg;
00156 char* desc;
00157 CounterArg* next;
00158 int index;
00159
00160 CounterArg(): code(-1), arg(NULL), desc(NULL), next(NULL), index(-1) { }
00161 CounterArg(int c, char* a, char* d):
00162 code(c), arg(a), desc(d), next(NULL), index(-1) { }
00163 void setValues(int _code, char* _arg, char* _desc) {
00164 code = _code; arg = _arg; desc = _desc;
00165 }
00166 };
00167
00168 private:
00169 enum TC_Status : int8_t { IDLE, WORKING };
00170 int cancel_beginIdle, cancel_endIdle;
00171
00172
00173 int argStrSize_;
00174 int commandLineSz_;
00175 int counter1Sz_;
00176 int counter2Sz_;
00177 CounterArg* firstArg_;
00178 CounterArg* lastArg_;
00179 CounterArg* commandLine_;
00180 CounterArg* counter1_;
00181 CounterArg* counter2_;
00182
00183
00184 bool overview_;
00185 bool switchRandom_;
00186 bool switchByPhase_;
00187 bool noLog_;
00188 bool writeByPhase_;
00189
00190
00191 int execEP_;
00192 int genStart_;
00193 double startEP_;
00194 double startIdle_;
00195
00196
00197 double idleTime_;
00198 int phase_;
00199 int reductionPhase_;
00200 TC_Status status_;
00201 bool traceOn_;
00202 bool dirty_;
00203
00206 void beginOverview();
00207 void endOverview();
00209 void switchCounters();
00211 void registerArg(CounterArg* arg);
00215 bool matchArg(CounterArg* arg);
00217 void usage();
00219 void printHelp();
00220 };
00221
00222 #endif // __trace_counter_h__
00223