5 #ifndef TIMING_ANALYSIS_H 9 #define TIME_ANALYSIS_ADD(ta, timer, ...) 10 #define TIME_SEC_BEG_LOG(logger,timer, ...) 11 #define TIME_SEC_END_LOG(logger,ta,timer, ...) 12 #define TIME_SEC_BEG(timer, ...) 13 #define TIME_SEC_END(ta,timer, ...) 17 #pragma message ( "warning: PERF_ANALYSIS is defined..." ) 21 #error "PERF_ANALYSIS require the code to be compiled with NDEBUG" 24 #error "PERF_ANALYSIS require the code to be compiled with NODEBUG" 26 #if (defined LOG4CXX) && !(defined PERF_DEBUG) 27 #error "PERF_ANALYSIS require the code to be compiled without LOG4CXX" 34 #define TIME_ANALYSIS_ADD(ta, timer, ...) \ 35 { std::ostringstream ostr; \ 36 ostr << __VA_ARGS__; \ 37 ta.add(timer.getUnits(), ostr.str()); } 39 #define TIME_SEC_BEG_LOG(logger,timer, ...) \ 40 LOG4CXX_INFO(logger, __VA_ARGS__ << " started") \ 43 #define TIME_SEC_END_LOG(logger,ta,timer, ...) \ 45 TIME_ANALYSIS_ADD(ta,timer, __VA_ARGS__) \ 46 LOG4CXX_INFO(logger, __VA_ARGS__ << " ended in " << timer.getTime()) 48 #define TIME_SEC_BEG(timer, ...) \ 51 #define TIME_SEC_END(ta,timer, ...) \ 53 TIME_ANALYSIS_ADD(ta,timer, __VA_ARGS__) 55 typedef std::pair<double,std::string> section_timing_t;
56 typedef std::set<section_timing_t> timing_set_t;
63 void add(
double units,
const std::string& section_name) {
64 section_timing_t st(units,section_name);
68 void share_report(std::ostream& o,
double total) {
71 o <<
"Timing analysis Report" << std::endl;
72 timing_set_t::iterator it;
73 for(it = ts.begin(); it != ts.end(); it++) {
75 share = 100 * (it->first / total);
76 o << std::setw(6) << std::setprecision(2)
77 << std::fixed << share <<
" % : ";
78 o << it->second <<
" : " << it->first << std::endl;
80 share = 100 * (sum / total);
81 o << std::setw(6) << std::setprecision(2)
82 << std::fixed << share <<
" % : Total";
83 o <<
" : " << sum << std::endl;
86 void share_report(std::ostream& o) {
88 timing_set_t::iterator it;
89 for(it = ts.begin(); it != ts.end(); it++) {
92 share_report(o, total);
101 #endif // PERF_ANALYSIS 103 #endif // TIMING_ANALYSIS_H