avoid generating BEGIN_TRACE for the default traceBegin() at startup.
[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
27 void ftracebegin()
28 {
29           checkInit();
30           if ( CpvAccess(a) ==0)
31                 {
32                         traceBegin();
33                         CpvAccess(a)++;
34                 }
35           else
36                 { CpvAccess(a)++;}
37 }
38
39 void FTN_NAME(FTRACEEND, ftraceend)()
40 {
41           checkInit();
42           if ( CpvAccess(a) == 1)
43                 {
44                         traceEnd();
45                         CpvAccess(a)--;
46                 }
47           else
48                 { CpvAccess(a)--;}
49                                                                                 
50 }
51
52 void ftraceregisteruserevent(char *x, int *ein, int *eout, int len)
53 {
54   char *newstr = new char[len + 1];
55   _MEMCHECK(newstr);
56   strncpy(newstr, x, len);
57   newstr[len] = 0;
58   int newe = traceRegisterUserEvent(newstr, *ein);
59   *eout = newe;
60 }
61
62 void ftraceuserbracketevent(int *e, double *begint, double *endt)
63 {
64   traceUserBracketEvent(*e, *begint, *endt);
65 }
66
67 void ftraceUserEvent(int *e)
68 {
69   traceUserEvent(*e);
70 }
71
72 }  // FDECL
73