Debian Codegraph @

contrib/epee/include/profile_tools.h

raw symbols SCIP
1 // Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of the Andrey N. Sabelnikov nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 //::QueryPerformanceCounter((LARGE_INTEGER *)&m_call_time);
95 }
96
97 ~call_frame()
98 {
99 //__int64 ret_time = 0;
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 //::QueryPerformanceCounter((LARGE_INTEGER *)&ret_time);
106 //m_call_time = (ret_time-m_call_time)/1000;
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 //_PROFILE_TOOLS_H_