00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef PROFILER_H
00043 #define PROFILER_H
00044
00045
00046 #define TAU_DEFAULT 0xffffffff
00047 #define TAU_MESSAGE 0x00000001
00048 #define TAU_PETE 0x00000002
00049 #define TAU_VIZ 0x00000004
00050 #define TAU_ASSIGN 0x00000008
00051 #define TAU_IO 0x00000010
00052 #define TAU_FIELD 0x00000020
00053 #define TAU_LAYOUT 0x00000040
00054 #define TAU_SPARSE 0x00000080
00055 #define TAU_DOMAINMAP 0x00000100
00056 #define TAU_UTILITY 0x00000200
00057 #define TAU_REGION 0x00000400
00058 #define TAU_PARTICLE 0x00000800
00059 #define TAU_MESHES 0x00001000
00060 #define TAU_SUBFIELD 0x00002000
00061 #define TAU_COMMUNICATION 0x00004000
00062 #define TAU_DESCRIPTOR_OVERHEAD 0x00008000
00063
00064
00065
00066
00067
00068
00069 #define TAU_FFT 0x00100000
00070 #define TAU_ACLMPL 0x00200000
00071 #define TAU_PAWS1 0x00400000
00072 #define TAU_PAWS2 0x00800000
00073 #define TAU_PAWS3 0x01000000
00074
00075
00076
00077 #define TAU_USER4 0x08000000
00078 #define TAU_USER3 0x10000000
00079 #define TAU_USER2 0x20000000
00080 #define TAU_USER1 0x40000000
00081 #define TAU_USER 0x80000000
00082
00083 #define TAU_MAX_THREADS 1024
00084
00085 #if (defined(PROFILING_ON) || defined(TRACING_ON))
00086
00087
00088 #include "Utility/Pstring.h"
00089
00090 #ifndef NO_RTTI
00091
00092 #ifdef IPPL_USE_STANDARD_HEADERS
00093 #include <typeinfo>
00094 using namespace std;
00095 #else
00096 #include <typeinfo.h>
00097 #endif
00098
00099 #endif
00100
00101 #ifdef IPPL_STDSTL
00102
00103 #include <vector>
00104 using std::vector;
00105
00106 #include <utility>
00107 using std::pair;
00108 #include <list>
00109 using std::list;
00110
00111 #else
00112
00113 #include <vector.h>
00114 #include <pair.h>
00115 #include <list.h>
00116
00117 #endif // IPPL_STDSTL
00118
00119
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00132
00133 class FunctionInfo
00134 {
00135 public:
00136
00137 FunctionInfo(const char* name, const char * type,
00138 unsigned int ProfileGroup = TAU_DEFAULT,
00139 const char *ProfileGroupName = "TAU_DEFAULT");
00140 FunctionInfo(string& name, const char* type,
00141 unsigned int ProfileGroup = TAU_DEFAULT,
00142 const char *ProfileGroupName = "TAU_DEFAULT");
00143 FunctionInfo(const char* name, string& type,
00144 unsigned int ProfileGroup = TAU_DEFAULT,
00145 const char *ProfileGroupName = "TAU_DEFAULT");
00146 FunctionInfo(string& name, string& type,
00147 unsigned int ProfileGroup = TAU_DEFAULT,
00148 const char *ProfileGroupName = "TAU_DEFAULT");
00149
00150 FunctionInfo(const FunctionInfo& X) ;
00151
00152 ~FunctionInfo();
00153 FunctionInfo& operator= (const FunctionInfo& X) ;
00154
00155
00156
00157 void ExcludeTime(double t);
00158
00159
00160 void AddInclTime(double t);
00161 void AddExclTime(double t);
00162 void IncrNumCalls(void);
00163
00164 bool GetAlreadyOnStack(void);
00165 void SetAlreadyOnStack(bool value);
00166
00167
00168
00169
00170 static vector<FunctionInfo*> FunctionDB[TAU_MAX_THREADS];
00171
00172 #ifdef PROFILE_CALLS
00173 list < pair<double,double> > *ExclInclCallList;
00174
00175
00176
00177 int AppendExclInclTimeThisCall(double ex, double in);
00178
00179 #endif // PROFILE_CALLS
00180
00181 private:
00182
00183
00184
00185 long NumCalls;
00186 long NumSubrs;
00187 double ExclTime;
00188 double InclTime;
00189 bool AlreadyOnStack;
00190 #ifdef PROFILE_STATS
00191 double SumExclSqr;
00192 #endif // PROFILE_STATS
00193
00194 public:
00195 string Name;
00196 string Type;
00197 string GroupName;
00198 long FunctionId;
00199
00200 const char* GetName() const { return Name.c_str(); }
00201 const char* GetType() const { return Type.c_str(); }
00202 const char* GetPrimaryGroup() const { return GroupName.c_str(); }
00203 long GetFunctionId() const { return FunctionId; }
00204 long GetCalls() const { return NumCalls; }
00205 long GetSubrs() const { return NumSubrs; }
00206 double GetExclTime() const { return ExclTime; }
00207 double GetInclTime() const { return InclTime; }
00208 unsigned int GetProfileGroup() const {return MyProfileGroup_; }
00209 #ifdef PROFILE_STATS
00210 double GetSumExclSqr() const { return SumExclSqr; }
00211 void AddSumExclSqr(double ExclSqr) { SumExclSqr += ExclSqr; }
00212 #endif // PROFILE_STATS
00213
00214 private:
00215 unsigned int MyProfileGroup_;
00216
00217
00218
00219
00220 };
00221
00222
00223
00224
00225 inline void
00226 FunctionInfo::ExcludeTime(double t)
00227 {
00228 ++NumSubrs;
00229 ExclTime -= t;
00230 }
00231
00232
00233 inline void
00234 FunctionInfo::AddInclTime(double t)
00235 {
00236 InclTime += t;
00237 }
00238
00239 inline void
00240 FunctionInfo::AddExclTime(double t)
00241 {
00242 ExclTime += t;
00243 }
00244
00245 inline void
00246 FunctionInfo::IncrNumCalls(void)
00247 {
00248 NumCalls++;
00249 }
00250
00251 inline void
00252 FunctionInfo::SetAlreadyOnStack(bool value)
00253 {
00254 AlreadyOnStack = value;
00255 }
00256
00257 inline bool
00258 FunctionInfo::GetAlreadyOnStack(void)
00259 {
00260 return AlreadyOnStack;
00261 }
00262
00263
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00276 class Profiler
00277 {
00278 public:
00279 Profiler(FunctionInfo * fi, unsigned int ProfileGroup = TAU_DEFAULT,
00280 bool StartStop = false);
00281
00282 void Start();
00283 Profiler(const Profiler& X);
00284 Profiler& operator= (const Profiler& X);
00285
00286 void Stop();
00287 ~Profiler();
00288 static void ProfileExit(const char *message=0);
00289 int StoreData(void);
00290
00291 #if ( defined(PROFILE_CALLS) || defined(PROFILE_STATS) )
00292 int ExcludeTimeThisCall(double t);
00293 double ExclTimeThisCall;
00294 #endif // PROFILE_CALLS || PROFILE_STATS
00295
00296 static Profiler * CurrentProfiler[TAU_MAX_THREADS];
00297 double StartTime;
00298 FunctionInfo * ThisFunction;
00299 Profiler * ParentProfiler;
00300
00301 private:
00302 unsigned int MyProfileGroup_;
00303 bool StartStopUsed_;
00304 bool AddInclFlag;
00305
00306
00307
00308
00309 };
00310
00312
00313
00314
00315
00316
00317
00318
00319
00320
00322 class RtsLayer
00323 {
00324 public:
00325 static unsigned int ProfileMask;
00326 static int Node;
00327 RtsLayer () { }
00328 ~RtsLayer () { }
00329
00330 static unsigned int enableProfileGroup(unsigned int ProfileGroup) ;
00331
00332 static unsigned int resetProfileGroup(void) ;
00333
00334 static int setAndParseProfileGroups (char *prog, char *str) ;
00335
00336 static bool isEnabled(unsigned int ProfileGroup) ;
00337
00338 static void ProfileInit(int argc, char **argv);
00339
00340 static string PrimaryGroup(const char *ProfileGroupName);
00341
00342 static bool isCtorDtor(const char *name);
00343
00344 static void TraceSendMsg(int type, int destination, int length);
00345 static void TraceRecvMsg(int type, int source, int length);
00346
00347 inline
00348 static const char * CheckNotNull(const char * str) {
00349 if (str == 0) return " ";
00350 else return str;
00351 }
00352
00353
00354 static int SetEventCounter(void);
00355 static double GetEventCounter(void);
00356
00357 static double getUSecD(void);
00358
00359 static int setMyNode(int NodeId);
00360
00361
00362 static int DumpEDF(void);
00363
00364
00365 static int myNode() { return Node;}
00366
00367
00368 static int myContext() { return 0; }
00369
00370
00371 inline
00372 static int myThread() { return 0; }
00373
00374 };
00375
00377
00378
00379
00381
00382 #define TAU_TYPE_STRING(profileString, str) static string profileString(str);
00383 #define TAU_PROFILE(name, type, group) \
00384 static FunctionInfo tauFI(name, type, group, #group); \
00385 Profiler tauFP(&tauFI, group);
00386 #define TAU_PROFILE_TIMER(var, name, type, group) \
00387 static FunctionInfo var##fi(name, type, group, #group); \
00388 Profiler var(&var##fi, group, true);
00389
00390
00391
00392 #define TAU_PROFILE_START(var) var.Start();
00393 #define TAU_PROFILE_STOP(var) var.Stop();
00394 #define TAU_PROFILE_STMT(stmt) stmt;
00395 #define TAU_PROFILE_EXIT(msg) Profiler::ProfileExit(msg);
00396 #define TAU_PROFILE_INIT(argc, argv) RtsLayer::ProfileInit(argc, argv);
00397 #define TAU_PROFILE_SET_NODE(node) RtsLayer::setMyNode(node);
00398
00399 #ifdef NO_RTTI
00400 #define CT(obj) string(#obj)
00401 #else // RTTI is present
00402 #define CT(obj) string(RtsLayer::CheckNotNull(typeid(obj).name()))
00403 #endif //NO_RTTI
00404
00405
00406
00407
00408
00409
00410
00411 #else
00412
00413 #define TYPE_STRING(profileString, str)
00414 #define PROFILED_BLOCK(name, type)
00415
00416 #define TAU_TYPE_STRING(profileString, str)
00417 #define TAU_PROFILE(name, type, group)
00418 #define TAU_PROFILE_TIMER(var, name, type, group)
00419 #define TAU_PROFILE_START(var)
00420 #define TAU_PROFILE_STOP(var)
00421 #define TAU_PROFILE_STMT(stmt)
00422 #define TAU_PROFILE_EXIT(msg)
00423 #define TAU_PROFILE_INIT(argc, argv)
00424 #define TAU_PROFILE_SET_NODE(node)
00425 #define CT(obj)
00426
00427 #endif
00428
00429 #ifdef TRACING_ON
00430 #define TAU_TRACE_SENDMSG(type, destination, length) RtsLayer::TraceSendMsg(type, destination, length);
00431 #define TAU_TRACE_RECVMSG(type, source, length) RtsLayer::TraceRecvMsg(type, source, length);
00432
00433 #else
00434 #define TAU_TRACE_SENDMSG(type, destination, length)
00435 #define TAU_TRACE_RECVMSG(type, source, length)
00436 #endif
00437
00438 #endif
00439
00440
00441
00442
00443