Non-tested Fortran MPI function tracing API.
[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 void ftracebegin()
41 {
42           checkInit();
43           if ( CpvAccess(a) ==0)
44                 {
45                         traceBegin();
46                         CpvAccess(a)++;
47                 }
48           else
49                 { CpvAccess(a)++;}
50 }
51
52 void FTN_NAME(FTRACEEND, ftraceend)()
53 {
54           checkInit();
55           if ( CpvAccess(a) == 1)
56                 {
57                         traceEnd();
58                         CpvAccess(a)--;
59                 }
60           else
61                 { CpvAccess(a)--;}
62                                                                                 
63 }
64
65 void ftraceregisteruserevent(char *x, int *ein, int *eout, int len)
66 {
67   char *newstr = new char[len + 1];
68   _MEMCHECK(newstr);
69   strncpy(newstr, x, len);
70   newstr[len] = 0;
71   int newe = traceRegisterUserEvent(newstr, *ein);
72   *eout = newe;
73 }
74
75 void ftraceuserbracketevent(int *e, double *begint, double *endt)
76 {
77   traceUserBracketEvent(*e, *begint, *endt);
78 }
79
80 void ftraceUserEvent(int *e)
81 {
82   traceUserEvent(*e);
83 }
84
85 void ftraceFlushLog()
86 {
87   traceFlushLog();
88 }
89
90 void ftraceRegisterFunc(char *name,int *outIdx,int lenName){
91         char *newstr = FortrantoCString(name,lenName);
92         *outIdx = registerFunction(newstr);
93         delete [] newstr;
94 }
95
96 void ftraceBeginFunc(int idx){
97         beginFuncIndexProj(idx,"FORTRAN",0);
98 }
99
100 void ftraceEndFunc(int idx){
101         endFuncIndexProj(idx);
102 }
103
104
105 }  // FDECL
106