71 #define PCXX_EVENT_SRC
72 #include "pcxx_events.h"
79 #define DEBUGPROFMSG(msg) { cout<< msg; }
81 #define DEBUGPROFMSG(msg)
103 unsigned int ProfileGroup ,
const char *ProfileGroupName)
119 SetAlreadyOnStack(
false);
123 #endif //PROFILE_STATS
126 ExclInclCallList =
new std::list<std::pair<double, double> >();
127 #endif //PROFILE_CALLS
130 MyProfileGroup_ = ProfileGroup ;
138 <<
" FunctionInfo::FunctionInfo(n,t) : Name : "<< GetName()
139 <<
" Type : " << GetType() <<
endl;);
146 unsigned int ProfileGroup ,
const char *ProfileGroupName)
162 SetAlreadyOnStack(
false);
166 #endif //PROFILE_STATS
169 ExclInclCallList =
new std::list<std::pair<double, double> >();
170 #endif //PROFILE_CALLS
173 MyProfileGroup_ = ProfileGroup ;
181 <<
" FunctionInfo::FunctionInfo(n,t) : Name : "<< GetName()
182 <<
" Type : " << GetType() <<
endl;);
189 unsigned int ProfileGroup ,
const char *ProfileGroupName)
191 if (ProfileGroup & RtsLayer::ProfileMask) {
205 SetAlreadyOnStack(
false);
209 #endif //PROFILE_STATS
212 ExclInclCallList =
new std::list<std::pair<double, double> >();
213 #endif //PROFILE_CALLS
216 MyProfileGroup_ = ProfileGroup ;
224 <<
" FunctionInfo::FunctionInfo(n,t) : Name : "<< GetName()
225 <<
" Type : " << GetType() <<
endl;);
232 unsigned int ProfileGroup ,
const char *ProfileGroupName)
234 if (ProfileGroup & RtsLayer::ProfileMask) {
248 SetAlreadyOnStack(
false);
252 #endif //PROFILE_STATS
255 ExclInclCallList =
new std::list<std::pair<double, double> >();
256 #endif //PROFILE_CALLS
259 MyProfileGroup_ = ProfileGroup ;
267 <<
" FunctionInfo::FunctionInfo(n,t) : Name : "<< GetName()
268 <<
" Type : " << GetType() <<
endl;);
277 NumCalls(X.NumCalls),
278 NumSubrs(X.NumSubrs),
279 ExclTime(X.ExclTime),
280 InclTime(X.InclTime),
281 MyProfileGroup_(X.MyProfileGroup_)
315 int FunctionInfo::AppendExclInclTimeThisCall(
double ex,
double in)
317 ExclInclCallList->push_back(std::pair<double,double>(ex,in));
321 #endif //PROFILE_CALLS
333 if (MyProfileGroup_ & RtsLayer::ProfileMask) {
358 #endif // PROFILING_ON
362 " Profiler::Start (FunctionInfo * f) : Name : " <<
368 #if ( defined(PROFILE_CALLS) || defined(PROFILE_STATS) )
369 ExclTimeThisCall = 0;
370 #endif //PROFILE_CALLS || PROFILE_STATS
379 MyProfileGroup_ = ProfileGroup ;
392 : StartTime(X.StartTime),
393 ThisFunction(X.ThisFunction),
394 ParentProfiler(X.ParentProfiler),
395 MyProfileGroup_(X.MyProfileGroup_),
396 StartStopUsed_(X.StartStopUsed_)
402 #if ( defined(PROFILE_CALLS) || defined(PROFILE_STATS) )
403 ExclTimeThisCall = X.ExclTimeThisCall;
404 #endif //PROFILE_CALLS || PROFILE_STATS
419 #if ( defined(PROFILE_CALLS) || defined(PROFILE_STATS) )
420 ExclTimeThisCall = X.ExclTimeThisCall;
421 #endif //PROFILE_CALLS || PROFILE_STATS
431 if (MyProfileGroup_ & RtsLayer::ProfileMask) {
437 #ifdef PROFILING_ON // Calculations relevent to profiling only
442 <<
" Start : " <<
StartTime <<
" TotalTime : " << TotalTime<<
endl;);
457 #if ( defined(PROFILE_CALLS) || defined(PROFILE_STATS) )
458 ExclTimeThisCall += TotalTime;
461 << ExclTimeThisCall <<
" InclTimeThisCall " << TotalTime <<
endl;);
463 #endif //PROFILE_CALLS || PROFILE_STATS
466 ThisFunction->AppendExclInclTimeThisCall(ExclTimeThisCall, TotalTime);
467 #endif // PROFILE_CALLS
470 ThisFunction->AddSumExclSqr(ExclTimeThisCall*ExclTimeThisCall);
471 #endif // PROFILE_STATS
476 <<
" Profiler::Stop(): ParentProfiler Function Name : "
480 #if ( defined(PROFILE_CALLS) || defined(PROFILE_STATS) )
482 #endif //PROFILE_CALLS || PROFILE_STATS
486 #endif //PROFILING_ON
489 cout <<
"ERROR: Timers Overlap. Illegal operation Profiler::Stop "
508 if (MyProfileGroup_ & RtsLayer::ProfileMask) {
513 <<
" ~Profiler() : Reached top level function - dumping data"
532 << message <<
endl;);
534 while (current != 0) {
544 <<
" ProfileExit() : Reached top level function - dumping data"
562 char filename[1024], errormsg[1024];
566 #endif //PROFILING_ON
568 long listSize, numCalls;
569 std::list<std::pair<double,double> >
::iterator iter;
570 #endif // PROFILE_CALLS
579 if ((dirname = getenv(
"PROFILEDIR")) == NULL) {
581 dirname =
new char[8];
582 strcpy (dirname,
".");
588 if ((fp = fopen (filename,
"w+")) == NULL) {
589 sprintf(errormsg,
"Error: Could not create %s",filename);
613 #ifdef SGI_HW_COUNTERS
614 fprintf(fp,
"%d templated_functions_hw_counters\n", numFunc);
615 #else // SGI_TIMERS, TULIP_TIMERS
616 fprintf(fp,
"%d templated_functions\n", numFunc);
617 #endif // SGI_HW_COUNTERS
620 fprintf(fp,
"# Name Calls Subrs Excl Incl ");
622 fprintf(fp,
"SumExclSqr ");
623 #endif //PROFILE_STATS
624 fprintf(fp,
"ProfileCalls\n");
632 << (*it)->GetName()<<
" " << (*it)->GetType() <<
" Calls : "
633 << (*it)->GetCalls() <<
" Subrs : "<< (*it)->GetSubrs()
634 <<
" Excl : " << (*it)->GetExclTime() <<
" Incl : "
635 << (*it)->GetInclTime() <<
endl;);
637 fprintf(fp,
"\"%s %s\" %ld %ld %.16G %.16G ", (*it)->GetName(),
638 (*it)->GetType(), (*it)->GetCalls(), (*it)->GetSubrs(),
639 (*it)->GetExclTime(), (*it)->GetInclTime());
642 fprintf(fp,
"%.16G ", (*it)->GetSumExclSqr());
643 #endif //PROFILE_STATS
646 listSize = (long) (*it)->ExclInclCallList->size();
647 numCalls = (*it)->GetCalls();
649 if (listSize != numCalls)
652 DEBUGPROFMSG(
"Error *** list (profileCalls) size mismatch size "
653 << listSize <<
" numCalls " << numCalls <<
endl;);
656 fprintf(fp,
"%ld \n", listSize);
657 for (iter = (*it)->ExclInclCallList->begin();
658 iter != (*it)->ExclInclCallList->end(); iter++)
661 << (*it)->GetName() <<
" " << (*it)->GetType()
662 <<
" ExclThisCall : "<< (*iter).first <<
" InclThisCall : "
663 << (*iter).second <<
endl; );
664 fprintf(fp,
"%G %G\n", (*iter).first , (*iter).second);
667 #else // PROFILE_CALLS
669 #endif // PROFILE_CALLS
672 fprintf(fp,
"0 aggregates\n");
677 #endif //PROFILING_ON
683 #if ( defined(PROFILE_CALLS) || defined(PROFILE_STATS) )
684 int Profiler::ExcludeTimeThisCall(
double t)
686 ExclTimeThisCall -= t;
689 #endif //PROFILE_CALLS || PROFILE_STATS
718 char *dirname, tracefilename[1024];
719 if ((dirname = getenv(
"TRACEDIR")) == NULL) {
721 dirname =
new char[8];
722 strcpy (dirname,
".");
724 sprintf(tracefilename,
"%s/tau.####.trc",dirname);
725 pcxx_EvInit(tracefilename);
743 #ifdef SGI_HW_COUNTERS
745 int start_counters(
int e0,
int e1 );
746 int read_counters(
int e0,
long long *c0,
int e1,
long long *c1);
748 #endif // SGI_HW_COUNTERS
751 #ifdef SGI_HW_COUNTERS
772 if((start = start_counters(e0,e1)) < 0) {
773 perror(
"start_counters");
778 #endif // SGI_HW_COUNTERS
781 #ifdef SGI_HW_COUNTERS
788 static double accum = 0;
790 if ((gen_read = read_counters(e0, &c0, e1, &c1)) < 0) {
791 perror(
"read_counters");
794 if (gen_read != gen_start) {
795 perror(
"lost counter! aborting...");
800 DEBUGPROFMSG(
"Read counters e0 " << e0 <<
" e1 "<< e1<<
" gen_read "
801 << gen_read <<
" gen_start = " << gen_start <<
" accum "<< accum
802 <<
" c0 " << c0 <<
" c1 " << c1 <<
endl;);
807 #endif //SGI_HW_COUNTERS
813 #ifdef SGI_HW_COUNTERS
815 #else //SGI_HW_COUNTERS
819 clock_gettime(CLOCK_SGI_CYCLE,&tp);
820 return (tp.tv_sec * 1e6 + (tp.tv_nsec * 1
e-3)) ;
823 #if (defined(IPPL_TFLOP) || !defined(TULIP_TIMERS))
825 gettimeofday (&tp, 0);
826 return ( tp.tv_sec * 1000000 + tp.tv_usec );
827 #else // TULIP_TIMERS by default.
828 return pcxx_GetUSecD();
832 #endif // SGI_HW_COUNTERS
842 while (str && *str) {
843 if ( ( end = strchr(str,
'+') ) != NULL ) *end =
'\0';
852 if (strncasecmp(str,
"ff", 2) == 0) {
875 if (strncasecmp(str,
"mesh", 4) == 0) {
886 if (strncasecmp(str,
"paws1", 5) == 0) {
890 else if (strncasecmp(str,
"paws2", 5) == 0) {
894 else if (strncasecmp(str,
"paws3", 5) == 0) {
898 else if (strncasecmp(str,
"pa", 2) == 0) {
913 if (strncasecmp(str,
"su", 2) == 0) {
924 if (strncasecmp(str,
"de", 2) == 0) {
935 if (strncasecmp(str,
"ut", 2) == 0) {
957 cout << prog <<
" : Invalid Profile Group " << str <<
endl;
960 if ( (str = end) != NULL ) *str++ =
'+';
974 for (i=0; i<argc; i++) {
975 if (strcmp(argv[i],
"--profile") == 0) {
977 if ( (i + 1) < argc && argv[i+1][0] !=
'-' ) {
998 if (strchr(name,
'~') == NULL)
999 if (strchr(name,
':') == NULL)
1014 string groups = ProfileGroupName;
1016 string separators =
" |";
1019 start = groups.find_first_not_of(separators);
1020 n = groups.length();
1021 stop = groups.find_first_of(separators, start);
1023 if ((stop < 0) || (stop > n)) stop =
n;
1025 primary = groups.substr(start, stop - start) ;
1036 long int parameter, othernode;
1042 othernode = (
long int) destination;
1048 parameter = (length & 0x0000FFFF) | ((type & 0x000000FF) << 16) |
1050 pcxx_Event(TAU_MESSAGE_SEND, parameter);
1052 printf(
"Node %d TraceSendMsg, type %x dest %x len %x par %lx \n",
1066 long int parameter, othernode;
1072 othernode = (
long int) source;
1078 parameter = (length & 0x0000FFFF) | ((type & 0x000000FF) << 16) |
1080 pcxx_Event(TAU_MESSAGE_RECV, parameter);
1083 printf(
"Node %d TraceRecvMsg, type %x src %x len %x par %lx \n",
1098 char filename[1024], errormsg[1024];
1101 int numEvents, numExtra;
1104 if ((dirname = getenv(
"TRACEDIR")) == NULL) {
1106 dirname =
new char[8];
1107 strcpy (dirname,
".");
1112 if ((fp = fopen (filename,
"w+")) == NULL) {
1113 sprintf(errormsg,
"Error: Could not create %s",filename);
1127 numEvents += numExtra;
1129 fprintf(fp,
"%d dynamic_trace_events\n", numEvents);
1131 fprintf(fp,
"# FunctionId Group Tag \"Name Type\" Parameters\n");
1137 << (*it)->GetFunctionId() <<
" " << (*it)->GetPrimaryGroup()
1138 <<
" 0 " << (*it)->GetName() <<
" " << (*it)->GetType()
1139 <<
" EntryExit" <<
endl;);
1141 fprintf(fp,
"%ld %s 0 \"%s %s\" EntryExit\n", (*it)->GetFunctionId(),
1142 (*it)->GetPrimaryGroup(), (*it)->GetName(), (*it)->GetType() );
1145 fprintf(fp,
"%ld TRACER 0 \"EV_INIT\" none\n", (
long) PCXX_EV_INIT);
1146 fprintf(fp,
"%ld TRACER 0 \"FLUSH_ENTER\" none\n", (
long) PCXX_EV_FLUSH_ENTER);
1147 fprintf(fp,
"%ld TRACER 0 \"FLUSH_EXIT\" none\n", (
long) PCXX_EV_FLUSH_EXIT);
1148 fprintf(fp,
"%ld TRACER 0 \"FLUSH_CLOSE\" none\n", (
long) PCXX_EV_CLOSE);
1149 fprintf(fp,
"%ld TRACER 0 \"FLUSH_INITM\" none\n", (
long) PCXX_EV_INITM);
1150 fprintf(fp,
"%ld TRACER 0 \"WALL_CLOCK\" none\n", (
long) PCXX_EV_WALL_CLOCK);
1151 fprintf(fp,
"%ld TRACER 0 \"CONT_EVENT\" none\n", (
long) PCXX_EV_CONT_EVENT);
1152 fprintf(fp,
"%ld TAU_MESSAGE -7 \"MESSAGE_SEND\" par\n", (
long) TAU_MESSAGE_SEND);
1153 fprintf(fp,
"%ld TAU_MESSAGE -8 \"MESSAGE_RECV\" par\n", (
long) TAU_MESSAGE_RECV);
static Profiler * CurrentProfiler[1024]
#define DEBUGPROFMSG(msg)
static unsigned int enableProfileGroup(unsigned int ProfileGroup)
const char * GetName() const
constexpr double e
The value of .
unsigned int MyProfileGroup_
static unsigned int resetProfileGroup(void)
FunctionInfo * ThisFunction
static int setAndParseProfileGroups(char *prog, char *str)
Profiler & operator=(const Profiler &X)
void AddExclTime(double t)
static void ProfileExit(const char *message=0)
void AddInclTime(double t)
static std::string PrimaryGroup(const char *ProfileGroupName)
void SetAlreadyOnStack(bool value)
unsigned int MyProfileGroup_
static bool isCtorDtor(const char *name)
static std::vector< FunctionInfo * > FunctionDB[1024]
long GetFunctionId() const
static int setMyNode(int NodeId)
#define TAU_COMMUNICATION
static void TraceSendMsg(int type, int destination, int length)
static void TraceRecvMsg(int type, int source, int length)
static double GetEventCounter(void)
FunctionInfo & operator=(const FunctionInfo &X)
Profiler * ParentProfiler
static bool isEnabled(unsigned int ProfileGroup)
bool GetAlreadyOnStack(void)
#define TAU_DESCRIPTOR_OVERHEAD
void ExcludeTime(double t)
const char * GetType() const
static unsigned int ProfileMask
std::string::iterator iterator
static int SetEventCounter(void)
Profiler(FunctionInfo *fi, unsigned int ProfileGroup=0xffffffff, bool StartStop=false)
FunctionInfo(const char *name, const char *type, unsigned int ProfileGroup=0xffffffff, const char *ProfileGroupName="TAU_DEFAULT")
Inform & endl(Inform &inf)
static double getUSecD(void)
static void ProfileInit(int argc, char **argv)