80 #if defined(HAVE_CXX11_FULL) || defined(HAVE_CXX11_DRAFT)
81 #define CONSTEXPR_ constexpr
91 #define _PASTE(a,b) a ## b
92 #define PASTE(a,b) _PASTE(a, b)
111 #ifdef DEBUG_PROFILER
112 #define START_TIMER(tag) static CONSTEXPR_ CodePoint PASTE(cp_,__LINE__) = CODE_POINT(tag); TimerFrame PASTE(timer_,__LINE__) = TimerFrame( PASTE(cp_,__LINE__) )
114 #define START_TIMER(tag)
124 #ifdef DEBUG_PROFILER
125 #define END_TIMER(tag) static CONSTEXPR_ CodePoint PASTE(cp_,__LINE__) = CODE_POINT(tag); Profiler::instance()->stop_timer( PASTE(cp_,__LINE__) )
127 #define END_TIMER(tag)
135 #ifdef DEBUG_PROFILER
136 #define END_START_TIMER(tag) Profiler::instance()->stop_timer(); START_TIMER(tag);
138 #define END_START_TIMER(tag)
161 #ifdef DEBUG_PROFILER
162 #define ADD_CALLS(n_calls) Profiler::instance()->add_calls(n_calls)
164 #define ADD_CALLS(n_calls)
171 #ifdef DEBUG_PROFILER
180 inline CONSTEXPR_ unsigned int str_hash(
const char * str) {
181 #define SALT 0 //0xef50e38f
182 return (*str == 0 ? SALT : str_hash(str+1) * 101 + (
unsigned int)(*str) );
188 #define CODE_POINT(tag) CodePoint(tag, __FILE__, __func__, __LINE__)
200 CONSTEXPR_ CodePoint(
const char *tag,
const char * file,
const char * func,
const unsigned int line)
201 : tag_(tag), file_(file), func_(func), line_(line),
202 hash_(str_hash(tag)), hash_idx_( str_hash(tag)%max_n_timer_childs )
206 static const unsigned int max_n_timer_childs=13;
209 const char *
const tag_;
212 const char *
const file_;
215 const char *
const func_;
218 const unsigned int line_;
224 unsigned int hash_idx_;
246 static const unsigned int max_n_childs=CodePoint::max_n_timer_childs;
252 typedef clock_t TimeData;
257 Timer(
const CodePoint &cp,
int parent);
267 static TimeData get_time();
285 bool stop(
bool forced =
false);
289 inline const char *tag()
const
290 {
return code_point_->tag_; }
293 inline bool running()
const
294 {
return start_count >0; }
297 std::string code_point_str()
const;
302 double cumulative_time()
const;
307 void add_child(
int child_index,
const Timer &child);
322 unsigned int call_count;
326 unsigned int start_count;
333 const CodePoint *code_point_;
335 unsigned int full_hash_;
337 unsigned int hash_idx_;
346 int child_timers[max_n_childs];
351 size_t total_allocated_;
355 size_t total_deallocated_;
393 static void initialize();
397 inline static Profiler* instance() {
398 ASSERT( _instance ,
"Can not get Profiler instance. Profiler not initialized yet.\n");
407 void set_task_info(
string description,
int size);
413 void set_program_info(
string program_name,
string program_version,
string branch,
string revision,
string build);
421 int start_timer(
const CodePoint &cp);
429 void stop_timer(
const CodePoint &cp);
437 void stop_timer(
int timer_index = -1);
445 void add_calls(
unsigned int n_calls);
450 void notify_malloc(
const size_t size );
455 void notify_free(
const size_t size );
461 inline const char *actual_tag()
const
462 {
return timers_[actual_node].tag(); }
466 inline unsigned int actual_count()
const
467 {
return timers_[actual_node].call_count; }
471 inline double actual_cumulative_time()
const
472 {
return timers_[actual_node].cumulative_time(); }
486 void output(
MPI_Comm comm, ostream &os);
498 static void uninitialize();
503 static bool is_initialized() {
return (_instance != NULL); }
511 int find_child(
const CodePoint &cp);
517 void update_running_timers();
521 static CodePoint null_code_point;
543 string task_description_;
550 string flow_version_;
554 string flow_revision_;
594 int const timer_index_;
596 inline TimerFrame(
const CodePoint &cp)
597 : timer_index_(
Profiler::instance()->start_timer(cp) )
605 #else // DEBUG_PROFILER
611 static void initialize();
613 ASSERT( _instance ,
"Can not get Profiler instance. Profiler not initialized yet.\n");
619 void set_program_info(
string program_name,
string program_version,
string branch,
string revision,
string build)
635 static void uninitialize();
static int min(int *val, MPI_Comm comm)
static int sum(int *val, MPI_Comm comm)
static Profiler * instance()
unsigned int actual_count() const
double actual_cumulative_time() const
void notify_free(const size_t size)
void output(MPI_Comm comm)
Global macros to enhance readability and debugging, general constants.
static int max(int *val, MPI_Comm comm)
void set_program_info(string program_name, string program_version, string branch, string revision, string build)
static Profiler * _instance
static bool is_initialized()
void output(MPI_Comm comm, ostream &os)
void set_task_info(string description, int size)
void notify_malloc(const size_t size)
const char * actual_tag() const