10 #ifdef ENABLE_STREAM_TIMING 21 LOGGER( mlog,
"stream_timer" );
23 stream_timer::stream_timer() :
24 f_state( state::starting ),
25 f_total_work_time( ns_t::zero() ),
26 f_n_work_periods( 0 ),
27 f_total_blocked_time( ns_t::zero() ),
28 f_n_blocked_periods( 0 ),
29 f_timer_start( time_point_t::min() ),
30 f_unpaused_buffer( ns_t::zero() ),
31 f_unpaused_state( state::paused )
35 stream_timer::~stream_timer()
39 void stream_timer::report(
const std::string& a_label )
const 41 typedef std::chrono::duration< double, std::ratio<1,1> > s_flt_t;
43 s_flt_t t_total_work_time_s = std::chrono::duration_cast< s_flt_t >( f_total_work_time );
44 s_flt_t t_total_blocked_time_s = std::chrono::duration_cast< s_flt_t >( f_total_blocked_time );
46 s_flt_t t_work_period = s_flt_t::zero();
47 double t_working_rate = std::numeric_limits< double >::infinity();
48 if( f_n_work_periods != 0 )
50 t_work_period = t_total_work_time_s / f_n_work_periods;
51 t_working_rate = 1. / t_work_period.count();
54 s_flt_t t_blocked_period = s_flt_t::zero();
55 if( f_n_blocked_periods != 0 ) t_blocked_period = t_total_blocked_time_s / f_n_blocked_periods;
57 std::stringstream t_timer_report;
58 t_timer_report <<
"Stream timer report for " << a_label <<
"\n";
59 t_timer_report <<
"-----------------------------------------------------------------------------------------------\n";
60 if( f_state != state::starting )
62 t_timer_report <<
" * Stream advanced " << f_n_blocked_periods <<
" times\n";
63 t_timer_report <<
" * Total time spent working: " << t_total_work_time_s.count() <<
" s\n";
64 t_timer_report <<
" * Total time waiting to advance: " << t_total_blocked_time_s.count() <<
" s\n";
65 t_timer_report <<
" * Mean working period: " << t_work_period.count() <<
" s\n";
66 t_timer_report <<
" * Mean blocked period: " << t_blocked_period.count() <<
" s\n";
67 t_timer_report <<
" * Stream working rate: " << t_working_rate <<
" s^-1\n";
71 t_timer_report <<
"Timer was unused\n";
73 LINFO( mlog, t_timer_report.str() );
76 void stream_timer::reset()
78 f_state = state::paused;
79 f_total_work_time = ns_t::zero();
81 f_total_blocked_time = ns_t::zero();
82 f_n_blocked_periods = 0;
83 f_timer_start = time_point_t::min();
84 f_unpaused_buffer = ns_t::zero();
85 f_unpaused_state = state::paused;