55 #include <boost/property_tree/ptree.hpp> 56 #include <boost/unordered_map.hpp> 63 namespace property_tree = boost::property_tree;
83 #define CONSTEXPR_ constexpr 89 #define _PASTE(a,b) a ## b 90 #define PASTE(a,b) _PASTE(a, b) 109 #ifdef FLOW123D_DEBUG_PROFILER 110 #define START_TIMER(tag) static CONSTEXPR_ CodePoint PASTE(cp_,__LINE__) = CODE_POINT(tag); TimerFrame PASTE(timer_,__LINE__) = TimerFrame( PASTE(cp_,__LINE__) ) 112 #define START_TIMER(tag) 130 #ifdef FLOW123D_DEBUG_PROFILER 131 #define START_TIMER_EXT(tag, subtag) static CONSTEXPR_ CodePoint PASTE(cp_,__LINE__) = CODE_POINT_EXT(tag, subtag); TimerFrame PASTE(timer_,__LINE__) = TimerFrame( PASTE(cp_,__LINE__) ) 133 #define START_TIMER_EXT(tag, subtag) 143 #ifdef FLOW123D_DEBUG_PROFILER 144 #define END_TIMER(tag) static CONSTEXPR_ CodePoint PASTE(cp_,__LINE__) = CODE_POINT(tag); Profiler::instance()->stop_timer( PASTE(cp_,__LINE__) ) 146 #define END_TIMER(tag) 154 #ifdef FLOW123D_DEBUG_PROFILER 155 #define END_START_TIMER(tag) Profiler::instance()->stop_timer(); START_TIMER(tag); 157 #define END_START_TIMER(tag) 180 #ifdef FLOW123D_DEBUG_PROFILER 181 #define ADD_CALLS(n_calls) Profiler::instance()->add_calls(n_calls) 183 #define ADD_CALLS(n_calls) 190 #ifdef FLOW123D_DEBUG_PROFILER 195 #define PROFILER_EMPTY_SUBTAG "" 200 #define PROFILER_HASH_DEFAULT 0 209 inline CONSTEXPR_ unsigned int str_hash(
const char * str,
unsigned int default_value) {
210 #define SALT 0 //0xef50e38f 211 return (*str == 0 ? SALT : default_value + str_hash(str+1, PROFILER_HASH_DEFAULT) * 101 + (
unsigned int)(*str) );
217 #define CODE_POINT(tag) CodePoint(tag, __FILE__, __func__, __LINE__) 222 #define CODE_POINT_EXT(tag, subtag) CodePoint(tag, subtag, __FILE__, __func__, __LINE__) 237 CONSTEXPR_ CodePoint(
const char *tag,
const char * file,
const char * func,
const unsigned int line)
238 : tag_(tag), subtag_(PROFILER_EMPTY_SUBTAG), file_(file), func_(func), line_(line),
239 hash_(str_hash(tag, PROFILER_HASH_DEFAULT)),
240 hash_idx_( str_hash(tag, PROFILER_HASH_DEFAULT)%max_n_timer_childs )
242 CONSTEXPR_ CodePoint(
const char *tag,
const char *subtag,
const char * file,
const char * func,
const unsigned int line)
243 : tag_(tag), subtag_(subtag), file_(file), func_(func), line_(line),
244 hash_(str_hash(subtag, str_hash(tag, PROFILER_HASH_DEFAULT))),
245 hash_idx_( str_hash(subtag, str_hash(tag, PROFILER_HASH_DEFAULT))%max_n_timer_childs )
249 static const unsigned int max_n_timer_childs=13;
252 const char *
const tag_;
255 const char *
const subtag_;
258 const char *
const file_;
261 const char *
const func_;
264 const unsigned int line_;
270 unsigned int hash_idx_;
292 static const unsigned int max_n_childs=CodePoint::max_n_timer_childs;
297 Timer(
const CodePoint &cp,
int parent);
311 bool stop(
bool forced =
false);
315 inline string tag()
const {
316 string buf(code_point_->tag_);
317 buf.append(code_point_->subtag_);
322 inline bool running()
const 323 {
return start_count >0; }
326 std::string code_point_str()
const;
331 double cumulative_time()
const;
336 void add_child(
int child_index,
const Timer &child);
366 unsigned int call_count;
370 unsigned int start_count;
377 const CodePoint *code_point_;
379 unsigned int full_hash_;
381 unsigned int hash_idx_;
390 int child_timers[max_n_childs];
396 size_t total_allocated_;
401 size_t total_deallocated_;
407 size_t max_allocated_;
414 size_t current_allocated_;
425 #ifdef FLOW123D_HAVE_PETSC 429 PetscLogDouble petsc_start_memory;
433 PetscLogDouble petsc_end_memory;
437 PetscLogDouble petsc_memory_difference;
445 PetscLogDouble petsc_peak_memory;
451 PetscLogDouble petsc_local_peak_memory;
452 #endif // FLOW123D_HAVE_PETSC 455 friend std::ostream &
operator <<(std::ostream&,
const Timer&);
524 static void initialize();
535 void set_task_info(
string description,
int size);
541 void set_program_info(
string program_name,
string program_version,
string branch,
string revision,
string build);
549 int start_timer(
const CodePoint &cp);
557 void stop_timer(
const CodePoint &cp);
565 void stop_timer(
int timer_index = -1);
571 void add_calls(
unsigned int n_calls);
576 void notify_malloc(
const size_t size,
const long p);
581 void notify_free(
const long p);
587 static double get_resolution ();
590 #ifdef FLOW123D_HAVE_MPI 602 void output(
MPI_Comm comm, std::ostream &os);
619 void output(std::ostream &os);
628 void transform_profiler_data (
const string &output_file_suffix,
const string &formatter);
633 static void uninitialize();
639 static void*
operator new (
size_t sz);
645 static void operator delete (
void* p);
652 void static set_memory_monitoring(
const bool global_monitor,
const bool petsc_monitor);
658 bool static get_global_memory_monitoring();
664 bool static get_petsc_memory_monitoring();
678 static bool global_monitor_memory;
683 static bool petsc_monitor_memory;
691 static const long malloc_map_reserve;
696 void propagate_timers ();
701 void accept_from_child (Timer &parent, Timer &child);
707 int find_child(
const CodePoint &cp);
715 void output_header (property_tree::ptree &root,
int mpi_size);
721 std::shared_ptr<std::ostream> get_default_output_stream();
724 static CodePoint null_code_point;
733 unsigned int actual_node;
751 string task_description_;
758 string flow_version_;
762 string flow_revision_;
766 string json_filepath;
774 template<
typename ReduceFunctor>
775 void add_timer_info(ReduceFunctor reduce, property_tree::ptree* node,
int timer_idx,
double parent_time);
805 int const timer_index_;
807 inline TimerFrame(
const CodePoint &cp)
831 static unordered_map_with_alloc & malloc_map();
837 #else // FLOW123D_DEBUG_PROFILER 843 static void initialize();
848 void set_program_info(
string program_name,
string program_version,
string branch,
string revision,
string build)
868 static void uninitialize();
static int min(int *val, MPI_Comm comm)
static int sum(int *val, MPI_Comm comm)
double get_resolution() const
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)
STREAM & operator<<(STREAM &s, UpdateFlags u)
void transform_profiler_data(const string &output_file_suffix, const string &formatter)
static Profiler * instance()
static Profiler * _instance
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