Merge remote branch 'origin/charm' into charmrun_merge
[charm.git] / src / ck-perf / tracef.C
1 /****************************************************************************
2              Fortran API for common Trace functions
3 ****************************************************************************/
4
5 #include<charm++.h>
6 #include<charm-api.h>
7                                                                                 
8 CpvStaticDeclare(int, a);
9                                                                                 
10 static int isInitialized=0;
11                                                                                 
12 static void checkInit(void) {
13         if (isInitialized) return;
14         isInitialized=1;
15         CpvInitialize(int,a);
16         CpvAccess(a)=0;
17 }
18
19 static char * FortrantoCString(char *x,int len){
20         char *newstr = new char[len + 1];
21   _MEMCHECK(newstr);
22   strncpy(newstr, x, len);
23   newstr[len] = 0;
24         return newstr;
25 }
26
27
28 FDECL {
29
30 #define ftracebegin              FTN_NAME(FTRACEBEGIN, ftracebegin)
31 #define ftraceend                FTN_NAME(FTRACEEND, ftraceend)
32 #define ftraceregisteruserevent  FTN_NAME(FTRACEREGISTERUSEREVENT, ftraceregisteruserevent)
33 #define ftraceuserbracketevent   FTN_NAME(FTRACEUSERBRACKETEVENT, ftraceuserbracketevent)
34 #define ftraceUserEvent          FTN_NAME(FTRACEUSEREVENT, ftraceuserevent)
35 #define ftraceFlushLog           FTN_NAME(FTRACEFLUSHLOG, ftraceflushlog)
36 #define ftraceRegisterFunc       FTN_NAME(FTRACEREGISTERFUNC,ftraceregisterfunc) 
37 #define ftraceBeginFunc          FTN_NAME(FTRACEBEGINFUNC,ftracebeginfunc)
38 #define ftraceEndFunc            FTN_NAME(FTRACEENDFUNC,ftraceendfunc)
39
40 #define fbgprintf                FTN_NAME(FBGPRINTF, fbgprintf)
41
42 void ftracebegin()
43 {
44           checkInit();
45           if ( CpvAccess(a) ==0)
46                 {
47                         traceBegin();
48                         CpvAccess(a)++;
49                 }
50           else
51                 { CpvAccess(a)++;}
52 }
53
54 void ftraceend()
55 {
56           checkInit();
57           if ( CpvAccess(a) == 1)
58                 {
59                         traceEnd();
60                         CpvAccess(a)--;
61                 }
62           else
63                 { CpvAccess(a)--;}
64                                                                                 
65 }
66
67 void ftraceregisteruserevent(char *x, int *ein, int *eout, int len)
68 {
69   char *newstr = new char[len + 1];
70   _MEMCHECK(newstr);
71   strncpy(newstr, x, len);
72   newstr[len] = 0;
73   int newe = traceRegisterUserEvent(newstr, *ein);
74   *eout = newe;
75 }
76
77 void ftraceuserbracketevent(int *e, double *begint, double *endt)
78 {
79   traceUserBracketEvent(*e, *begint, *endt);
80 }
81
82 void ftraceUserEvent(int *e)
83 {
84   traceUserEvent(*e);
85 }
86
87 void ftraceFlushLog()
88 {
89   traceFlushLog();
90 }
91
92 void ftraceRegisterFunc(char *name,int *outIdx,int lenName){
93         char *newstr = FortrantoCString(name,lenName);
94         *outIdx = traceRegisterFunction(newstr);
95         delete [] newstr;
96 }
97
98 void ftraceBeginFunc(int *idx){
99         traceBeginFuncIndexProj(*idx,(char*)"FORTRAN",0);
100 }
101
102 void ftraceEndFunc(int *idx){
103         traceEndFuncIndexProj(*idx);
104 }
105
106 #if CMK_BLUEGENE_CHARM
107 void fbgprintf(char *str, int len)
108 {
109   char *newstr = new char[len + 1];
110   _MEMCHECK(newstr);
111   strncpy(newstr, str, len);
112   newstr[len] = 0;
113   BgPrintf(newstr);
114   delete [] newstr;
115 }
116 #endif
117
118 }  // FDECL
119