src/Profile/hpcxx/HPCxx_Profile.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 //##########################################################################
00017 // HPC++Lib: An object-oriented class library for high performance
00018 //           parallel programming.
00019 //
00020 // Copyright (c) 1997
00021 //      Indiana University
00022 //      Los Alamos National Laboratory
00023 //      University of Oregon
00024 // 
00025 // http://www.cs.uoregon.edu/paracomp/tau
00026 // http://www.acl.lanl.gov/Tulip
00027 // http://www.extreme.indiana.edu/HPC++
00028 //
00029 // Sameer Shende, Aida Chouchane
00030 // Pete Beckman, Dennis Gannon, Todd Green, Liz Johnson
00031 //
00032 // HPC++_VER: 
00033 //##########################################################################
00034 
00035 #ifndef __HPCXX_PROFILE_H_
00036 #define __HPCXX_PROFILE_H_
00037 
00038 
00039 #define HPCXX_MAX_COUNTERS      256
00040 #define HPCXX_MAX_PROFILE_EVENTS        HPCXX_MAX_COUNTERS
00041 #define HPCXX_MAX_COUNTER_STRING        8*HPCXX_MAX_COUNTERS
00042 
00043 
00044       /*hpc++ lib relevant events to be registered for profiling */
00045 
00046 
00047       /*3 counters for a Cond*/
00048 #define HPCXX_PROFILE_Wait_HPCxx_Cond         0
00049 #define HPCXX_PROFILE_Signal_HPCxx_Cond       1
00050 #define HPCXX_PROFILE_Broadcast_HPCxx_Cond    2
00051 
00052       /*2 counters for a GlobalPtr*/
00053 #define HPCXX_PROFILE_Read_HPCxx_GlobalPtr    3
00054 #define HPCXX_PROFILE_Write_HPCxx_GlobalPtr   4
00055 
00056       /*3 counters for a SyncQ*/
00057 #define HPCXX_PROFILE_Write_HPCxx_SyncQ       5
00058 #define HPCXX_PROFILE_Read_HPCxx_SyncQ        6
00059 #define HPCXX_PROFILE_WaitAndCopy_HPCxx_SyncQ 7
00060 
00061       /*6 counters for a Thread*/
00062 #define HPCXX_PROFILE_Create_HPCxx_Thread     8
00063 #define HPCXX_PROFILE_Suspend_HPCxx_Thread    9
00064 #define HPCXX_PROFILE_Resume_HPCxx_Thread     10
00065 #define HPCXX_PROFILE_Join_HPCxx_Thread       11
00066 /*#define HPCXX_PROFILE_Stop_HPCxx_Thread       12
00067   #define HPCXX_PROFILE_Sleep_HPCxx_Thread      13
00068   #define HPCXX_PROFILE_Yield_HPCxx_Thread      14*/
00069 
00070       /*2 counters for a CSem*/
00071 #define HPCXX_PROFILE_Increment_HPCxx_CSem    12
00072 #define HPCXX_PROFILE_Wait_HPCxx_CSem         13
00073 
00074       /*2 counters for a Sync*/
00075 #define HPCXX_PROFILE_Write_HPCxx_Sync        14
00076 #define HPCXX_PROFILE_Read_HPCxx_Sync         15
00077 
00078       /*2 counters for a Mutex*/
00079 #define HPCXX_PROFILE_Lock_HPCxx_Mutex        16
00080 #define HPCXX_PROFILE_Unlock_HPCxx_Mutex      17
00081 
00082 class HPCxx_Thread;
00083 class HPCxx_Runnable;
00084 class HPCxx_Group;
00085 
00086 #ifdef PROFILING_ON
00087 // map is used in a class member data field. 
00088 #ifndef PARSE_ONLY
00089 #include <map.h>
00090 #include <vector.h>
00091 #include <deque.h>
00092 #include <stack.h>
00093 #endif
00094 
00095 #ifdef __cplusplus
00096 extern "C" {
00097 #endif /* __cplusplus */
00098 
00099   /****************************GLOBAL FUNCTIONS****************************
00100   **************************************************************************/
00101 
00102   /* THREAD PROFILING*/
00103 
00104 void hpcxx_ProfileInit(HPCxx_Group *g);
00105 void hpcxx_ProfileThreadInit(HPCxx_Group *g);
00106 void hpcxx_ProfileExit();
00107 void hpcxx_ProfileExitThread();
00108 void hpcxx_ProfileDecrChildren();
00109 void hpcxx_ProfileWaitChildren();
00110 int  tid();
00111 
00112    /* FUNCTION PROFILING*/
00113 
00114 int  hpcxx_ProfileIsFunctionTopLevel(const int &, const int &);
00115 void hpcxx_ProfileSetNumberOfFunc( const int& );
00116 
00117 void hpcxx_ProfileSetCurrentNodeId(const int& nid);
00118 void hpcxx_ProfileSetCurrentContextId(const int& cid);
00119 int  hpcxx_ProfileThisNode();
00120 int  hpcxx_ProfileThisContext();
00121 
00122    /* AGGREGATE-SPECIFIC EVENT TRACING */
00123 int  hpcxx_ProfileGetEventCounter(void);
00124 int  hpcxx_ProfileShowEventTable(void);
00125 //void hpcxx_ProfileInitNrOfSysEvents();
00126 int  hpcxx_ProfileObjectInit(void);
00127 int  hpcxx_ProfileDumpObjectEventNames();
00128 
00129 /*API for user, to register new events to be traced dynamically*/
00130 int  hpcxx_ProfileRegisterEvent(int eventid, char *event_name);
00131 void hpcxx_ProfileIncrementCounter(void *addr,int counter_id);
00132 
00133 /*API for user, to register aggregates into the system*/
00134 void hpcxx_ProfileCollNames(char *coll, char *elem, 
00135                             char *var, void *var_addr); 
00136 void hpcxx_ProfileCollAttr(void *var_addr, int no_of_elements, 
00137                            int dimension, int size_of_aggregate);
00138  
00139 
00140 
00141 
00142 /*************************************************************************
00143 **************************************************************************/
00144 inline char* strnew(const char* str) {
00145     char* newstr = 0;
00146     if (str) {
00147         newstr = new char[strlen(str) + 1];
00148         strcpy(newstr, str);
00149     }
00150     return newstr;
00151 }
00152 
00153 struct lptr
00154 {
00155   bool operator()(void* s1, void* s2) const
00156   {
00157     return s1 < s2;
00158   }
00159 }; 
00160 
00161 typedef struct  hpcxx_ProfileFuncDescr {
00162   int numcalls;
00163   double usec;
00164   double cumusec;
00165 } hpcxx_ProfileFuncDescr;
00166 
00167 typedef struct hpcxx_CurrentFuncInfo {
00168   int parentFunction; // fid of calling function
00169   int myId; // current function id
00170   double start; // starting time of myId function
00171 } hpcxx_CurrentFuncInfo; 
00172 
00173 #ifdef __cplusplus
00174 }
00175 #endif  
00176 
00177 
00178 class HPCxx_ProfileVarInfo
00179 {
00180 public:
00181         char *containerName;
00182         char *containerType;
00183         char *varName;
00184 
00185         int  numelems ;
00186         int  dim ;
00187         int  size  ;
00188         long counters[HPCXX_MAX_COUNTERS]; 
00189         nexus_mutex_t counterLocks[HPCXX_MAX_COUNTERS];
00190 /* for keeping track of events that take place on an object */
00191         HPCxx_ProfileVarInfo(); 
00192         HPCxx_ProfileVarInfo(const char *cname, const char *ctype, const char *vname);
00193         void incrementCounter(int counter_id);
00194         void registerAttributes(int no_of_elements, int dimension, int size_of_aggregate);
00195         const  HPCxx_ProfileVarInfo& operator = ( const HPCxx_ProfileVarInfo& t) ;
00196 }; 
00197 
00198 
00199 
00200 
00201 class  HPCxx_ThProfiler {
00202 
00203 
00204 #ifndef PARSE_ONLY
00205     map<void*, HPCxx_ProfileVarInfo, lptr>* contNameDb_; 
00206 #endif
00207 
00208     int parentTh_;
00209     int id_;
00210 
00211     void checkFunctionList_();
00212 public:
00213     hpcxx_ProfileFuncDescr *pFuncList_;
00214     stack<hpcxx_CurrentFuncInfo, vector<hpcxx_CurrentFuncInfo> > funcStack;
00215     int currentFunc;
00216     
00217     HPCxx_ThProfiler() {}; /*default constructor*/
00218     HPCxx_ThProfiler( int );
00219     HPCxx_ThProfiler(const char* p);
00220     ~HPCxx_ThProfiler() {};
00221 
00222     const HPCxx_ThProfiler& operator = ( const HPCxx_ThProfiler& );
00223 
00224     int getThreadId();
00225     int getParentId();
00226 
00227     void initFunctionList(const int&);
00228     void exitFunctionProfiling(const double&);
00229     void dumpInformationProfiling();
00230     void setFunctionTime(const int& , const double&);
00231     void incrFunctionCalls(const int&);
00232     void updateFunctions(const int& , const double&);
00233     void setStartTime(const int& , const double &);
00234 
00235     int getNumberOfCollections();
00236     void collNames( char *, char *, char *, void *);
00237     void collAttr(void *, int, int, int);
00238     void incrementAggregateCounter(void *,int );
00239 };
00240 
00241 class HPCxx_FuncProfiler {
00242   int ident_;
00243   int nf_;
00244   double start_;
00245 
00246 public:
00247   HPCxx_FuncProfiler(int id);
00248   HPCxx_FuncProfiler(int id, int num);
00249   HPCxx_FuncProfiler(int id, char countonly);
00250   HPCxx_FuncProfiler(int id, int num , char countonly);
00251   ~HPCxx_FuncProfiler() ;
00252 
00253 };
00254 
00255 
00256 #else /* PROFILING_ON */
00257 // Profiling is turned off - default mode
00258 #   define hpcxx_ProfileInit(g)
00259 #   define hpcxx_ProfileThreadInit(g)
00260 #   define hpcxx_ProfileExit()
00261 #   define hpcxx_ProfileExitThread()
00262 #   define hpcxx_ProfileDecrChildren()
00263 #   define hpcxx_ProfileWaitChildren()
00264 #   define tid()
00265 #   define hpcxx_ProfileIsFunctionTopLevel(thread_id, function_id)
00266 #   define hpcxx_ProfileSetNumberOfFunc(fn)
00267 //#   define hpcxx_ProfileFuncEnter(fid ) 
00268 //#   define hpcxx_ProfileFuncExit(fid,d)
00269 #   define hpcxx_ProfileSetCurrentNodeId(nid)
00270 #   define hpcxx_ProfileSetCurrentContextId(cid)
00271 #   define hpcxx_ProfileThisNode()
00272 #   define hpcxx_ProfileThisContext()
00273 #   define hpcxx_ProfileGetEventCounter()
00274 #   define hpcxx_ProfileShowEventTable()
00275 #   define hpcxx_ProfileObjectInit()
00276 #   define hpcxx_ProfileInitNrOfSysEvents()
00277 #   define hpcxx_ProfileDumpObjectEventNames()
00278 #   define hpcxx_ProfileRegisterEvent(eventid,event_name)
00279 #   define hpcxx_ProfileIncrementCounter(addr,counter_id)
00280 #   define hpcxx_ProfileCollNames(coll,elem,var,var_addr) 
00281 #   define hpcxx_ProfileCollAttr(var_addr,no_of_elements,dimension,size_of_aggregate)
00282 
00283 // Define dummy classes that do not do anything 
00284 class HPCxx_FuncProfiler {
00285   int ident_;
00286   int nf_;
00287   double start_;
00288 
00289 public:
00290   HPCxx_FuncProfiler(int id) {};
00291   HPCxx_FuncProfiler(int id, int num) {};
00292   HPCxx_FuncProfiler(int id, char countonly) {};
00293   HPCxx_FuncProfiler(int id, int num , char countonly ) {};
00294   ~HPCxx_FuncProfiler() {};
00295 };
00296 
00297 class  HPCxx_ThProfiler {
00298 public:
00299     HPCxx_ThProfiler() {}; /*default constructor*/
00300     HPCxx_ThProfiler( int ) {};
00301     HPCxx_ThProfiler(const char* p) {};
00302     ~HPCxx_ThProfiler() {};
00303 };
00304 
00305 
00306 #endif /*PROFILING_ON*/
00307 
00308 
00309 #endif /* __HPCXX_PROFILE_H_ */
00310 
00311 
00312 /***************************************************************************
00313  * $RCSfile: addheaderfooter,v $   $Author: adelmann $
00314  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:17 $
00315  * IPPL_VERSION_ID: $Id: addheaderfooter,v 1.1.1.1 2003/01/23 07:40:17 adelmann Exp $ 
00316  ***************************************************************************/
00317 

Generated on Mon Jan 16 13:23:54 2006 for IPPL by  doxygen 1.4.6