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);
613 void output(
MPI_Comm comm,
string profiler_path =
"");
626 void output(std::ostream &os);
632 void output(
string profiler_path =
"");
637 void transform_profiler_data (
const string &output_file_suffix,
const string &formatter);
642 static void uninitialize();
648 static void*
operator new (
size_t sz);
654 static void operator delete (
void* p);
661 void static set_memory_monitoring(
const bool global_monitor,
const bool petsc_monitor);
667 bool static get_global_memory_monitoring();
673 bool static get_petsc_memory_monitoring();
687 static bool global_monitor_memory;
692 static bool petsc_monitor_memory;
700 static const long malloc_map_reserve;
705 void propagate_timers ();
710 void accept_from_child (
Timer &parent,
Timer &child);
716 int find_child(
const CodePoint &cp);
724 void output_header (property_tree::ptree &root,
int mpi_size);
730 std::shared_ptr<std::ostream> get_default_output_stream();
733 static CodePoint null_code_point;
742 unsigned int actual_node;
760 string task_description_;
767 string flow_version_;
771 string flow_revision_;
775 string json_filepath;
783 template<
typename ReduceFunctor>
784 void add_timer_info(ReduceFunctor reduce, property_tree::ptree* node,
int timer_idx,
double parent_time);
814 int const timer_index_;
816 inline TimerFrame(
const CodePoint &cp)
840 static unordered_map_with_alloc & malloc_map();
846 #else // FLOW123D_DEBUG_PROFILER 852 static void initialize();
857 void set_program_info(
string program_name,
string program_version,
string branch,
string revision,
string build)
877 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