1 #ifndef teca_profiler_h
2 #define teca_profiler_h
4 #include "teca_config.h"
34 static int initialize();
39 static int finalize();
49 static void set_communicator(MPI_Comm comm);
54 static void set_timer_log_file(
const std::string &file_name);
59 static void set_mem_prof_log_file(
const std::string &file_name);
63 static void set_mem_prof_interval(
int interval);
68 static void enable(
int arg = 0x03);
69 static void disable();
72 static bool enabled();
79 static int start_event(
const char *eventname);
85 static int end_event(
const char *eventname);
88 static int write_c_stdio(
const char *file_name,
const char *mode,
89 const std::string &str);
93 static int write_mpi_io(MPI_Comm comm,
const char *file_name,
94 const std::string &str);
98 static int validate();
101 static int to_stream(std::ostream &os);
110 template <
int buffer_size>
117 const char *method,
int port) : eventname(buffer)
119 snprintf(buffer, buffer_size,
"%s::%s port=%d",
120 class_name, method, port);
121 teca_profiler::start_event(eventname);
127 int n_threads,
int n_reqs) : eventname(buffer)
129 snprintf(buffer, buffer_size,
130 "%s thread_pool process n_threads=%d n_reqs=%d",
131 class_name, n_threads, n_reqs);
132 teca_profiler::start_event(eventname);
139 const char *method) : eventname(buffer)
142 strcat(buffer, class_name);
143 strcat(buffer, method);
144 teca_profiler::start_event(eventname);
150 { teca_profiler::start_event(name); }
153 { teca_profiler::end_event(this->eventname); }
156 char buffer[buffer_size];
157 const char *eventname;
160 #if defined(TECA_ENABLE_PROFILER)
161 #define TECA_PROFILE_PIPELINE(_n, _alg, _meth, _port, _code) \
163 teca_time_event<_n> event(_alg->get_class_name(), \
168 #define TECA_PROFILE_METHOD(_n, _alg, _meth, _code) \
170 teca_time_event<_n> \
171 event(_alg->get_class_name(), "::" _meth); \
175 #define TECA_PROFILE_THREAD_POOL(_n, _alg, _nt, _nr, _code) \
177 teca_time_event<_n> \
178 event(_alg->get_class_name(), _nt, _nr); \
182 #define TECA_PROFILE_PIPELINE(_n, _alg, _meth, _port, _code) \
187 #define TECA_PROFILE_METHOD(_n, _alg, _meth, _code) \
192 #define TECA_PROFILE_THREAD_POOL(_n, _alg, _nt, _nr, _code) \