56 #include <boost/functional/hash/hash.hpp> 57 #include <boost/property_tree/ptree_fwd.hpp> 58 #include <boost/ref.hpp> 59 #include <boost/tuple/detail/tuple_basic.hpp> 60 #include <boost/unordered/unordered_map.hpp> 68 namespace property_tree = boost::property_tree;
74 static int sum(
int* val,
MPI_Comm comm);
75 static double sum(
double* val,
MPI_Comm comm);
76 static long sum(
long* val,
MPI_Comm comm);
78 static int min(
int* val,
MPI_Comm comm);
79 static double min(
double* val,
MPI_Comm comm);
80 static long min(
long* val,
MPI_Comm comm);
82 static int max(
int* val,
MPI_Comm comm);
83 static double max(
double* val,
MPI_Comm comm);
84 static long max(
long* val,
MPI_Comm comm);
88 #define CONSTEXPR_ constexpr 94 #define _PASTE(a,b) a ## b 95 #define PASTE(a,b) _PASTE(a, b) 114 #ifdef FLOW123D_DEBUG_PROFILER 115 #define START_TIMER(tag) static CONSTEXPR_ CodePoint PASTE(cp_,__LINE__) = CODE_POINT(tag); TimerFrame PASTE(timer_,__LINE__) = TimerFrame( PASTE(cp_,__LINE__) ) 117 #define START_TIMER(tag) 135 #ifdef FLOW123D_DEBUG_PROFILER 136 #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__) ) 138 #define START_TIMER_EXT(tag, subtag) 148 #ifdef FLOW123D_DEBUG_PROFILER 149 #define END_TIMER(tag) static CONSTEXPR_ CodePoint PASTE(cp_,__LINE__) = CODE_POINT(tag); Profiler::instance()->stop_timer( PASTE(cp_,__LINE__) ) 151 #define END_TIMER(tag) 159 #ifdef FLOW123D_DEBUG_PROFILER 160 #define END_START_TIMER(tag) Profiler::instance()->stop_timer(); START_TIMER(tag); 162 #define END_START_TIMER(tag) 185 #ifdef FLOW123D_DEBUG_PROFILER 186 #define ADD_CALLS(n_calls) Profiler::instance()->add_calls(n_calls) 188 #define ADD_CALLS(n_calls) 195 #ifdef FLOW123D_DEBUG_PROFILER 200 #define PROFILER_EMPTY_SUBTAG "" 205 #define PROFILER_HASH_DEFAULT 0 214 inline CONSTEXPR_ unsigned int str_hash(
const char * str,
unsigned int default_value) {
215 #define SALT 0 //0xef50e38f 216 return (*str == 0 ? SALT : default_value + str_hash(str+1, PROFILER_HASH_DEFAULT) * 101 + (
unsigned int)(*str) );
222 #define CODE_POINT(tag) CodePoint(tag, __FILE__, __func__, __LINE__) 227 #define CODE_POINT_EXT(tag, subtag) CodePoint(tag, subtag, __FILE__, __func__, __LINE__) 242 CONSTEXPR_ CodePoint(
const char *tag,
const char * file,
const char * func,
const unsigned int line)
243 : tag_(tag), subtag_(PROFILER_EMPTY_SUBTAG), file_(file), func_(func), line_(line),
244 hash_(str_hash(tag, PROFILER_HASH_DEFAULT)),
245 hash_idx_( str_hash(tag, PROFILER_HASH_DEFAULT)%max_n_timer_childs )
247 CONSTEXPR_ CodePoint(
const char *tag,
const char *subtag,
const char * file,
const char * func,
const unsigned int line)
248 : tag_(tag), subtag_(subtag), file_(file), func_(func), line_(line),
249 hash_(str_hash(subtag, str_hash(tag, PROFILER_HASH_DEFAULT))),
250 hash_idx_( str_hash(subtag, str_hash(tag, PROFILER_HASH_DEFAULT))%max_n_timer_childs )
254 static const unsigned int max_n_timer_childs=13;
257 const char *
const tag_;
260 const char *
const subtag_;
263 const char *
const file_;
266 const char *
const func_;
269 const unsigned int line_;
275 unsigned int hash_idx_;
297 static const unsigned int max_n_childs=CodePoint::max_n_timer_childs;
302 Timer(
const CodePoint &cp,
int parent);
316 bool stop(
bool forced =
false);
320 inline string tag()
const {
321 string buf(code_point_->tag_);
322 buf.append(code_point_->subtag_);
327 inline bool running()
const 328 {
return start_count >0; }
331 std::string code_point_str()
const;
336 double cumulative_time()
const;
341 void add_child(
int child_index,
const Timer &child);
371 unsigned int call_count;
375 unsigned int start_count;
382 const CodePoint *code_point_;
384 unsigned int full_hash_;
386 unsigned int hash_idx_;
395 int child_timers[max_n_childs];
401 size_t total_allocated_;
406 size_t total_deallocated_;
412 size_t max_allocated_;
419 size_t current_allocated_;
430 #ifdef FLOW123D_HAVE_PETSC 434 PetscLogDouble petsc_start_memory;
438 PetscLogDouble petsc_end_memory;
442 PetscLogDouble petsc_memory_difference;
450 PetscLogDouble petsc_peak_memory;
456 PetscLogDouble petsc_local_peak_memory;
457 #endif // FLOW123D_HAVE_PETSC 529 static void initialize();
540 void set_task_info(
string description,
int size);
546 void set_program_info(
string program_name,
string program_version,
string branch,
string revision,
string build);
554 int start_timer(
const CodePoint &cp);
562 void stop_timer(
const CodePoint &cp);
570 void stop_timer(
int timer_index = -1);
576 void add_calls(
unsigned int n_calls);
581 void notify_malloc(
const size_t size,
const long p);
586 void notify_free(
const long p);
592 static double get_resolution ();
595 #ifdef FLOW123D_HAVE_MPI 607 void output(
MPI_Comm comm, std::ostream &os);
624 void output(std::ostream &os);
633 void transform_profiler_data (
const string &output_file_suffix,
const string &formatter);
638 static void uninitialize();
644 static void*
operator new (
size_t sz);
650 static void operator delete (
void* p);
657 void static set_memory_monitoring(
const bool global_monitor,
const bool petsc_monitor);
663 bool static get_global_memory_monitoring();
669 bool static get_petsc_memory_monitoring();
683 static bool global_monitor_memory;
688 static bool petsc_monitor_memory;
696 static const long malloc_map_reserve;
701 void propagate_timers ();
706 void accept_from_child (
Timer &parent,
Timer &child);
712 int find_child(
const CodePoint &cp);
720 void output_header (property_tree::ptree &root,
int mpi_size);
726 std::shared_ptr<std::ostream> get_default_output_stream();
729 static CodePoint null_code_point;
738 unsigned int actual_node;
756 string task_description_;
763 string flow_version_;
767 string flow_revision_;
771 string json_filepath;
779 template<
typename ReduceFunctor>
780 void add_timer_info(ReduceFunctor reduce, property_tree::ptree* node,
int timer_idx,
double parent_time);
810 int const timer_index_;
812 inline TimerFrame(
const CodePoint &cp)
836 static unordered_map_with_alloc & malloc_map();
842 #else // FLOW123D_DEBUG_PROFILER 848 static void initialize();
853 void set_program_info(
string program_name,
string program_version,
string branch,
string revision,
string build)
873 static void uninitialize();
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.
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