55 #include <unordered_map> 58 #include <boost/functional/hash/hash.hpp> 59 #include <boost/ref.hpp> 60 #include <boost/tuple/detail/tuple_basic.hpp> 62 #include <nlohmann/json.hpp> 72 static int sum(
int* val,
MPI_Comm comm);
73 static double sum(
double* val,
MPI_Comm comm);
74 static long sum(
long* val,
MPI_Comm comm);
76 static int min(
int* val,
MPI_Comm comm);
77 static double min(
double* val,
MPI_Comm comm);
78 static long min(
long* val,
MPI_Comm comm);
80 static int max(
int* val,
MPI_Comm comm);
81 static double max(
double* val,
MPI_Comm comm);
82 static long max(
long* val,
MPI_Comm comm);
86 #define CONSTEXPR_ constexpr 92 #define _PASTE(a,b) a ## b 93 #define PASTE(a,b) _PASTE(a, b) 112 #ifdef FLOW123D_DEBUG_PROFILER 113 #define START_TIMER(tag) static CONSTEXPR_ CodePoint PASTE(cp_,__LINE__) = CODE_POINT(tag); TimerFrame PASTE(timer_,__LINE__) = TimerFrame( PASTE(cp_,__LINE__) ) 115 #define START_TIMER(tag) 133 #ifdef FLOW123D_DEBUG_PROFILER 134 #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__) ) 136 #define START_TIMER_EXT(tag, subtag) 146 #ifdef FLOW123D_DEBUG_PROFILER 147 #define END_TIMER(tag) static CONSTEXPR_ CodePoint PASTE(cp_,__LINE__) = CODE_POINT(tag); Profiler::instance()->stop_timer( PASTE(cp_,__LINE__) ) 149 #define END_TIMER(tag) 157 #ifdef FLOW123D_DEBUG_PROFILER 158 #define END_START_TIMER(tag) Profiler::instance()->stop_timer(); START_TIMER(tag); 160 #define END_START_TIMER(tag) 183 #ifdef FLOW123D_DEBUG_PROFILER 184 #define ADD_CALLS(n_calls) Profiler::instance()->add_calls(n_calls) 186 #define ADD_CALLS(n_calls) 193 #ifdef FLOW123D_DEBUG_PROFILER 198 #define PROFILER_EMPTY_SUBTAG "" 203 #define PROFILER_HASH_DEFAULT 0 212 inline CONSTEXPR_ unsigned int str_hash(
const char * str,
unsigned int default_value) {
213 #define SALT 0 //0xef50e38f 214 return (*str == 0 ? SALT : default_value + str_hash(str+1, PROFILER_HASH_DEFAULT) * 101 + (
unsigned int)(*str) );
220 #define CODE_POINT(tag) CodePoint(tag, __FILE__, __func__, __LINE__) 225 #define CODE_POINT_EXT(tag, subtag) CodePoint(tag, subtag, __FILE__, __func__, __LINE__) 240 CONSTEXPR_ CodePoint(
const char *tag,
const char * file,
const char * func,
const unsigned int line)
241 : tag_(tag), subtag_(PROFILER_EMPTY_SUBTAG), file_(file), func_(func), line_(line),
242 hash_(str_hash(tag, PROFILER_HASH_DEFAULT)),
243 hash_idx_( str_hash(tag, PROFILER_HASH_DEFAULT)%max_n_timer_childs )
245 CONSTEXPR_ CodePoint(
const char *tag,
const char *subtag,
const char * file,
const char * func,
const unsigned int line)
246 : tag_(tag), subtag_(subtag), file_(file), func_(func), line_(line),
247 hash_(str_hash(subtag, str_hash(tag, PROFILER_HASH_DEFAULT))),
248 hash_idx_( str_hash(subtag, str_hash(tag, PROFILER_HASH_DEFAULT))%max_n_timer_childs )
252 static const unsigned int max_n_timer_childs=13;
255 const char *
const tag_;
258 const char *
const subtag_;
261 const char *
const file_;
264 const char *
const func_;
267 const unsigned int line_;
273 unsigned int hash_idx_;
295 static const unsigned int max_n_childs=CodePoint::max_n_timer_childs;
300 Timer(
const CodePoint &cp,
int parent);
314 bool stop(
bool forced =
false);
318 inline string tag()
const {
319 string buf(code_point_->tag_);
320 buf.append(code_point_->subtag_);
325 inline bool running()
const 326 {
return start_count >0; }
329 std::string code_point_str()
const;
334 double cumulative_time()
const;
339 void add_child(
int child_index,
const Timer &child);
369 unsigned int call_count;
373 unsigned int start_count;
380 const CodePoint *code_point_;
382 unsigned int full_hash_;
384 unsigned int hash_idx_;
393 int child_timers[max_n_childs];
399 size_t total_allocated_;
404 size_t total_deallocated_;
410 size_t max_allocated_;
417 size_t current_allocated_;
428 #ifdef FLOW123D_HAVE_PETSC 432 PetscLogDouble petsc_start_memory;
436 PetscLogDouble petsc_end_memory;
440 PetscLogDouble petsc_memory_difference;
448 PetscLogDouble petsc_peak_memory;
454 PetscLogDouble petsc_local_peak_memory;
455 #endif // FLOW123D_HAVE_PETSC 526 static Profiler* instance(
bool clear =
false);
533 void set_task_info(
string description,
int size);
539 void set_program_info(
string program_name,
string program_version,
string branch,
string revision,
string build);
547 int start_timer(
const CodePoint &cp);
555 void stop_timer(
const CodePoint &cp);
563 void stop_timer(
int timer_index = -1);
569 void add_calls(
unsigned int n_calls);
574 void notify_malloc(
const size_t size,
const long p);
579 void notify_free(
const long p);
585 static double get_resolution ();
588 #ifdef FLOW123D_HAVE_MPI 600 void output(
MPI_Comm comm, std::ostream &os);
606 void output(
MPI_Comm comm,
string profiler_path =
"");
619 void output(std::ostream &os);
625 void output(
string profiler_path =
"");
630 void transform_profiler_data (
const string &output_file_suffix,
const string &formatter);
635 static void uninitialize();
641 static void*
operator new (
size_t sz);
647 static void operator delete (
void* p);
649 static void operator delete (
void* p, std::size_t);
656 void static set_memory_monitoring(
const bool global_monitor,
const bool petsc_monitor);
662 bool static get_global_memory_monitoring();
668 bool static get_petsc_memory_monitoring();
682 static bool global_monitor_memory;
687 static bool petsc_monitor_memory;
695 static const long malloc_map_reserve;
700 void propagate_timers ();
705 void accept_from_child (
Timer &parent,
Timer &child);
711 int find_child(
const CodePoint &cp);
725 std::shared_ptr<std::ostream> get_default_output_stream();
731 unsigned int actual_node;
749 string task_description_;
756 string flow_version_;
760 string flow_revision_;
764 string json_filepath;
772 template<
typename ReduceFunctor>
773 void add_timer_info(ReduceFunctor reduce,
nlohmann::json* node,
int timer_idx,
double parent_time);
803 int const timer_index_;
805 inline TimerFrame(
const CodePoint &cp)
829 static unordered_map_with_alloc & malloc_map();
835 #else // FLOW123D_DEBUG_PROFILER 841 static Profiler* instance(
bool clear =
false);
865 static void uninitialize();
void set_task_info(string, int)
a class to store JSON values
double get_resolution() const
unsigned int actual_count() const
double actual_cumulative_time() const
void set_program_info(string, string, string, string, string)
Global macros to enhance readability and debugging, general constants.
void output(MPI_Comm, ostream &)
void notify_malloc(const size_t)
STREAM & operator<<(STREAM &s, UpdateFlags u)
void notify_free(const size_t)
static Profiler * instance(bool clear=false)
void transform_profiler_data(const string &, const string &)
const char * actual_tag() const