added function (traceFlushLog) to be user callable function to voluntarily flush...
[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 FDECL {
20
21 #define ftracebegin              FTN_NAME(FTRACEBEGIN, ftracebegin)
22 #define ftraceend                FTN_NAME(FTRACEEND, ftraceend)
23 #define ftraceregisteruserevent  FTN_NAME(FTRACEREGISTERUSEREVENT, ftraceregisteruserevent)
24 #define ftraceuserbracketevent   FTN_NAME(FTRACEUSERBRACKETEVENT, ftraceuserbracketevent)
25 #define ftraceUserEvent          FTN_NAME(FTRACEUSEREVENT, ftraceuserevent)
26 #define ftraceFlushLog           FTN_NAME(FTRACEFLUSHLOG, ftraceflushlog)
27
28 void ftracebegin()
29 {
30           checkInit();
31           if ( CpvAccess(a) ==0)
32                 {
33                         traceBegin();
34                         CpvAccess(a)++;
35                 }
36           else
37                 { CpvAccess(a)++;}
38 }
39
40 void FTN_NAME(FTRACEEND, ftraceend)()
41 {
42           checkInit();
43           if ( CpvAccess(a) == 1)
44                 {
45                         traceEnd();
46                         CpvAccess(a)--;
47                 }
48           else
49                 { CpvAccess(a)--;}
50                                                                                 
51 }
52
53 void ftraceregisteruserevent(char *x, int *ein, int *eout, int len)
54 {
55   char *newstr = new char[len + 1];
56   _MEMCHECK(newstr);
57   strncpy(newstr, x, len);
58   newstr[len] = 0;
59   int newe = traceRegisterUserEvent(newstr, *ein);
60   *eout = newe;
61 }
62
63 void ftraceuserbracketevent(int *e, double *begint, double *endt)
64 {
65   traceUserBracketEvent(*e, *begint, *endt);
66 }
67
68 void ftraceUserEvent(int *e)
69 {
70   traceUserEvent(*e);
71 }
72
73 void ftraceFlushLog()
74 {
75   traceFlushLog();
76 }
77
78 }  // FDECL
79