1 #ifndef teca_profiler_h
2 #define teca_profiler_h
4 #include "teca_config.h"
32 static int initialize();
37 static int finalize();
47 static void set_communicator(MPI_Comm comm);
52 static void set_timer_log_file(
const std::string &file_name);
57 static void set_mem_prof_log_file(
const std::string &file_name);
61 static void set_mem_prof_interval(
int interval);
66 static void enable(
int arg = 0x03);
67 static void disable();
70 static bool enabled();
77 static int start_event(
const char *eventname);
83 static int end_event(
const char *eventname);
86 static int write_c_stdio(
const char *file_name,
const char *mode,
87 const std::string &str);
91 static int write_mpi_io(MPI_Comm comm,
const char *file_name,
92 const std::string &str);
96 static int validate();
99 static int to_stream(std::ostream &os);
106 template <
int buffer_size>
113 const char *method,
int port) : eventname(buffer)
115 snprintf(buffer, buffer_size,
"%s::%s port=%d",
116 class_name, method, port);
117 teca_profiler::start_event(eventname);
123 int n_threads,
int n_reqs) : eventname(buffer)
125 snprintf(buffer, buffer_size,
126 "%s thread_pool process n_threads=%d n_reqs=%d",
127 class_name, n_threads, n_reqs);
128 teca_profiler::start_event(eventname);
135 const char *method) : eventname(buffer)
138 strcat(buffer, class_name);
139 strcat(buffer, method);
140 teca_profiler::start_event(eventname);
146 { teca_profiler::start_event(name); }
149 { teca_profiler::end_event(this->eventname); }
152 char buffer[buffer_size];
153 const char *eventname;
156 #if defined(TECA_ENABLE_PROFILER)
157 #define TECA_PROFILE_PIPELINE(_n, _alg, _meth, _port, _code) \
159 teca_time_event<_n> event(_alg->get_class_name(), \
164 #define TECA_PROFILE_METHOD(_n, _alg, _meth, _code) \
166 teca_time_event<_n> \
167 event(_alg->get_class_name(), "::" _meth); \
171 #define TECA_PROFILE_THREAD_POOL(_n, _alg, _nt, _nr, _code) \
173 teca_time_event<_n> \
174 event(_alg->get_class_name(), _nt, _nr); \
178 #define TECA_PROFILE_PIPELINE(_n, _alg, _meth, _port, _code) \
183 #define TECA_PROFILE_METHOD(_n, _alg, _meth, _code) \
188 #define TECA_PROFILE_THREAD_POOL(_n, _alg, _nt, _nr, _code) \