| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#ifndef _PROFILE_TOOLS_H_ |
| 29 |
#define _PROFILE_TOOLS_H_ |
| 30 |
|
| 31 |
#include "time_helper.h" |
| 32 |
|
| 33 |
namespace epee |
| 34 |
{ |
| 35 |
|
| 36 |
#ifdef ENABLE_PROFILING |
| 37 |
#define PROFILE_FUNC(immortal_ptr_str) static profile_tools::local_call_account lcl_acc(immortal_ptr_str); \ |
| 38 |
profile_tools::call_frame cf(lcl_acc); |
| 39 |
|
| 40 |
#define PROFILE_FUNC_SECOND(immortal_ptr_str) static profile_tools::local_call_account lcl_acc2(immortal_ptr_str); \ |
| 41 |
profile_tools::call_frame cf2(lcl_acc2); |
| 42 |
|
| 43 |
#define PROFILE_FUNC_THIRD(immortal_ptr_str) static profile_tools::local_call_account lcl_acc3(immortal_ptr_str); \ |
| 44 |
profile_tools::call_frame cf3(lcl_acc3); |
| 45 |
|
| 46 |
#define PROFILE_FUNC_ACC(acc) \ |
| 47 |
profile_tools::call_frame cf(acc); |
| 48 |
|
| 49 |
|
| 50 |
#else |
| 51 |
#define PROFILE_FUNC(immortal_ptr_str) |
| 52 |
#define PROFILE_FUNC_SECOND(immortal_ptr_str) |
| 53 |
#define PROFILE_FUNC_THIRD(immortal_ptr_str) |
| 54 |
#endif |
| 55 |
|
| 56 |
#define START_WAY_POINTS() uint64_t _____way_point_time = epee::misc_utils::get_tick_count(); |
| 57 |
#define WAY_POINT(name) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; MDEBUG("Way point " << name << ": " << delta);_____way_point_time = misc_utils::get_tick_count();} |
| 58 |
#define WAY_POINT2(name, avrg_obj) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; avrg_obj.push(delta); MDEBUG("Way point " << name << ": " << delta);_____way_point_time = misc_utils::get_tick_count();} |
| 59 |
|
| 60 |
|
| 61 |
#define TIME_MEASURE_START(var_name) uint64_t var_name = epee::misc_utils::get_tick_count(); |
| 62 |
#define TIME_MEASURE_PAUSE(var_name) var_name = epee::misc_utils::get_tick_count() - var_name; |
| 63 |
#define TIME_MEASURE_RESTART(var_name) var_name = epee::misc_utils::get_tick_count() - var_name; |
| 64 |
#define TIME_MEASURE_FINISH(var_name) var_name = epee::misc_utils::get_tick_count() - var_name; |
| 65 |
|
| 66 |
#define TIME_MEASURE_NS_START(var_name) uint64_t var_name = epee::misc_utils::get_ns_count(); |
| 67 |
#define TIME_MEASURE_NS_PAUSE(var_name) var_name = epee::misc_utils::get_ns_count() - var_name; |
| 68 |
#define TIME_MEASURE_NS_RESTART(var_name) var_name = epee::misc_utils::get_ns_count() - var_name; |
| 69 |
#define TIME_MEASURE_NS_FINISH(var_name) var_name = epee::misc_utils::get_ns_count() - var_name; |
| 70 |
|
| 71 |
namespace profile_tools |
| 72 |
{ |
| 73 |
struct local_call_account |
| 74 |
{ |
| 75 |
local_call_account(const char* pstr):m_count_of_call(0), m_summary_time_used(0),m_pname(pstr) |
| 76 |
{} |
| 77 |
~local_call_account() |
| 78 |
{ |
| 79 |
MINFO("PROFILE "<<m_pname<<":av_time:\t" << (m_count_of_call ? (m_summary_time_used/m_count_of_call):0) <<" sum_time:\t"<<m_summary_time_used<<" call_count:\t" << m_count_of_call); |
| 80 |
} |
| 81 |
|
| 82 |
size_t m_count_of_call; |
| 83 |
uint64_t m_summary_time_used; |
| 84 |
const char* m_pname; |
| 85 |
}; |
| 86 |
|
| 87 |
struct call_frame |
| 88 |
{ |
| 89 |
|
| 90 |
call_frame(local_call_account& cc):m_cc(cc) |
| 91 |
{ |
| 92 |
cc.m_count_of_call++; |
| 93 |
m_call_time = boost::posix_time::microsec_clock::local_time(); |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
~call_frame() |
| 98 |
{ |
| 99 |
|
| 100 |
|
| 101 |
boost::posix_time::ptime now_t(boost::posix_time::microsec_clock::local_time()); |
| 102 |
boost::posix_time::time_duration delta_microsec = now_t - m_call_time; |
| 103 |
uint64_t miliseconds_used = delta_microsec.total_microseconds(); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
m_cc.m_summary_time_used += miliseconds_used; |
| 108 |
} |
| 109 |
|
| 110 |
private: |
| 111 |
local_call_account& m_cc; |
| 112 |
boost::posix_time::ptime m_call_time; |
| 113 |
}; |
| 114 |
|
| 115 |
|
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
#endif |