SURFEX v8.1
General documentation of Surfex
drhook.h
Go to the documentation of this file.
1 #ifndef _DRHOOK_H_
2 #define _DRHOOK_H_
3 
4 #ifdef _DRHOOK_C_
5 
6 #if defined(__GNUC__)
7 #define _GNU_SOURCE 1
8 #endif
9 
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <sys/time.h>
14 #include <sys/resource.h>
15 #include <unistd.h>
16 #include <ctype.h>
17 #include <signal.h>
18 #include <errno.h>
19 #include <time.h>
20 #include <math.h>
21 #include <sys/syscall.h>
22 #include <sys/types.h>
23 #include <pthread.h>
24 #include <limits.h>
25 
26 #ifdef _OPENMP
27 #include <omp.h>
28 #endif
29 
30 #ifdef RS6K
31 #include <fptrap.h>
32 #endif
33 
34 #ifdef VPP
35 #include <ucontext.h>
36 #endif
37 
38 int drhook_lhook = 1;
39 #else
40 extern int drhook_lhook;
41 #endif
42 
43 #ifndef O_LOCK_DONE
44 #define O_LOCK_DONE
45 
46 /* OpenMP/ODB lock type */
47 /* Keep consistent with "odb/include/privpub.h" */
48 /* Be ALSO consistent with OML_LOCK_KIND in ifsaux/module/oml_mod.F90 */
49 
50 typedef long long int o_lock_t; /* i.e. 64-bit integer */
51 
52 #define INIT_LOCKID_WITH_NAME(mylock, lockname) \
53  coml_init_lockid_with_name_(mylock, lockname, strlen(lockname))
54 
55 extern void coml_set_debug_(const int *konoff, int *kret);
56 extern void coml_init_lock_();
57 extern void coml_init_lockid_(o_lock_t *mylock);
58 extern void coml_init_lockid_with_name_(o_lock_t *mylock, const char *name, int name_len);
59 extern void coml_set_lock_();
60 extern void coml_set_lockid_(o_lock_t *mylock);
61 extern void coml_unset_lock_();
62 extern void coml_unset_lockid_(o_lock_t *mylock);
63 extern void coml_test_lock_(int *is_set);
64 extern void coml_test_lockid_(int *is_set, o_lock_t *mylock);
65 extern void coml_in_parallel_(int *is_parallel_region);
66 
67 #endif
68 
69 /* drhook.c external interfaces */
70 
71 extern void
72 c_drhook_getenv_(const char *s,
73  char *value,
74  /* Hidden arguments */
75  int slen,
76  const int valuelen);
77 
78 extern void
79 c_drhook_memcounter_(const int *thread_id,
80  const long long int *size,
81  long long int *keyptr_addr);
82 
83 extern void
84 c_drhook_raise_(const int *sig);
85 
86 extern void
87 c_drhook_print_(const int *ftnunitno,
88  const int *thread_id,
89  const int *print_option, /*
90  1=raw call counts
91  2=calling tree
92  3=profiling info
93  */
94  int *level);
95 
96 extern void
97 c_drhook_init_signals_(const int *enforce);
98 
99 extern void
100 c_drhook_set_lhook_(const int *lhook);
101 
102 extern void
103 c_drhook_init_(const char *progname,
104  const int *num_threads
105  /* Hidden length */
106  ,int progname_len);
107 
108 extern void
109 c_drhook_start_(const char *name,
110  const int *thread_id,
111  double *key,
112  const char *filename,
113  const int *sizeinfo
114  /* Hidden length */
115  ,int name_len, int filename_len);
116 
117 extern void
118 c_drhook_end_(const char *name,
119  const int *thread_id,
120  const double *key,
121  const char *filename,
122  const int *sizeinfo
123  /* Hidden length */
124  ,int name_len, int filename_len);
125 
126 extern void
127 c_drhook_watch_(const int *onoff,
128  const char *array_name,
129  const void *array_ptr,
130  const int *nbytes,
131  const int *abort_if_changed,
132  const int *printkey,
133  const int *nvals,
134  const int *print_traceback_when_set
135  /* Hidden length */
136  ,int array_name_len);
137 
138 extern void
139 c_drhook_check_watch_(const char *where,
140  const int *allow_abort
141  /* Hidden length */
142  , int where_len);
143 
144 /**** C-interface to Dr.Hook ****/
145 
146 extern void
147 Dr_Hook(const char *name, int option, double *handle,
148  const char *filename, int sizeinfo,
149  int name_len, int filename_len);
150 
151 #define DRHOOK_START_RECUR(name,recur) \
152  static const char *drhook_name = #name; \
153  static const int drhook_name_len = sizeof(#name) - 1; /* Compile time eval */ \
154  static const char *drhook_filename = __FILE__; \
155  static const int drhook_filename_len = sizeof(__FILE__) - 1; /* Compile time eval */ \
156  double zhook_handle; \
157  if (!recur && drhook_lhook) Dr_Hook(drhook_name, 0, &zhook_handle, \
158  drhook_filename, 0, \
159  drhook_name_len, drhook_filename_len); {
160 
161 #define DRHOOK_START(name) DRHOOK_START_RECUR(name,0)
162 
163 #define DRHOOK_START_BY_STRING_RECUR(name, recur) \
164  static const char *drhook_name = name; \
165  static const int drhook_name_len = sizeof(name) - 1; /* Compile time eval */ \
166  static const char *drhook_filename = __FILE__; \
167  static const int drhook_filename_len = sizeof(__FILE__) - 1; /* Compile time eval */ \
168  double zhook_handle; \
169  if (!recur && drhook_lhook) Dr_Hook(drhook_name, 0, &zhook_handle, \
170  drhook_filename, 0, \
171  drhook_name_len, drhook_filename_len); {
172 
173 #define DRHOOK_START_BY_STRING(name) DRHOOK_START_BY_STRING_RECUR(name,0)
174 
175 #define DRHOOK_RETURN_RECUR(sizeinfo,recur) \
176  if (!recur && drhook_lhook) Dr_Hook(drhook_name, 1, &zhook_handle, \
177  drhook_filename, sizeinfo, \
178  drhook_name_len, drhook_filename_len)
179 
180 #define DRHOOK_RETURN(sizeinfo) DRHOOK_RETURN_RECUR(sizeinfo,0)
181 
182 #define DRHOOK_END_RECUR(sizeinfo,recur) ; } DRHOOK_RETURN_RECUR(sizeinfo,recur)
183 
184 #define DRHOOK_END(sizeinfo) DRHOOK_END_RECUR(sizeinfo,0)
185 
186 /* Fortran routines */
187 
188 extern void
189 dr_hook_prt_(const int *ftnunitno,
190  const char *s
191  /* Hidden arguments */
192  , int s_len);
193 
194 extern void
195 dr_hook_procinfo_(int *myproc, int *nproc);
196 
197 #endif /* _DRHOOK_H_ */
198 
void dr_hook_prt_(const int *ftnunitno, const char *s, int s_len)
void coml_init_lockid_with_name_(o_lock_t *mylock, const char *name, int name_len)
static long size
Definition: bytes_io.c:262
static int nproc
Definition: drhook.c:436
void coml_init_lockid_(o_lock_t *mylock)
void c_drhook_getenv_(const char *s, char *value, int slen, const int valuelen)
Definition: drhook.c:3088
static int myproc
Definition: drhook.c:435
long long int o_lock_t
Definition: drhook.h:50
void Dr_Hook(const char *name, int option, double *handle, const char *filename, int sizeinfo, int name_len, int filename_len)
Definition: drhook.c:4496
void c_drhook_watch_(const int *onoff, const char *array_name, const void *array_ptr, const int *nbytes, const int *abort_if_changed, const int *printkey, const int *nvals, const int *print_traceback_when_set, int array_name_len)
Definition: drhook.c:3152
quick &counting sorts only inumt inumt name
void c_drhook_init_signals_(const int *enforce)
Definition: drhook.c:4474
void coml_test_lock_(int *is_set)
void c_drhook_memcounter_(const int *thread_id, const long long int *size, long long int *keyptr_addr)
Definition: drhook.c:3392
void coml_in_parallel_(int *is_parallel_region)
void coml_init_lock_()
int drhook_lhook
Definition: drhook.h:38
void coml_set_lockid_(o_lock_t *mylock)
void dr_hook_procinfo_(int *myproc, int *nproc)
logical lhook
Definition: yomhook.F90:15
void c_drhook_print_(const int *ftnunitno, const int *thread_id, const int *print_option, int *level)
Definition: drhook.c:3639
void c_drhook_end_(const char *name, const int *thread_id, const double *key, const char *filename, const int *sizeinfo, int name_len, int filename_len)
Definition: drhook.c:3320
void coml_set_lock_()
void c_drhook_raise_(const int *sig)
Definition: drhook.c:4487
void coml_unset_lock_()
void c_drhook_init_(const char *progname, const int *num_threads, int progname_len)
Definition: drhook.c:3116
void coml_set_debug_(const int *konoff, int *kret)
void c_drhook_set_lhook_(const int *lhook)
Definition: drhook.c:3080
void coml_unset_lockid_(o_lock_t *mylock)
void c_drhook_start_(const char *name, const int *thread_id, double *key, const char *filename, const int *sizeinfo, int name_len, int filename_len)
Definition: drhook.c:3225
void coml_test_lockid_(int *is_set, o_lock_t *mylock)
void c_drhook_check_watch_(const char *where, const int *allow_abort, int where_len)
Definition: drhook.c:3060