Used as a stopwatch. More...
#include <timer.h>
Public Types | |
typedef time_t | value_type |
typedef double | duration_type |
Public Member Functions | |
timer () | |
C'tor. | |
timer (const timer &a_timer) | |
C'tor. | |
timer (const value_type a_start) | |
C'tor. | |
timer (const value_type a_start, const value_type a_stop) | |
C'tor. | |
void | clear (void) |
Clear the timer. | |
void | start (void) |
Start (or restart) the timer. | |
void | stop (void) |
Stop the timer. | |
const value_type | start_value (void) const |
Return the timer start value. | |
const value_type | stop_value (void) const |
Return the timer stop value. | |
void | assign (const timer &a_timer) |
Assign timer values from another timer instance. | |
void | assign (const value_type a_start) |
Assign timer from a start value. | |
void | assign (const value_type a_start, const value_type a_stop) |
Assign timer from start and stop values. | |
timer & | operator= (const timer &a_timer) |
Assignment. | |
void | use_localtime (const bool a_switch) |
Set whether to use localtime or GMT when constructing strings. | |
const bool | use_localtime (void) const |
Return whether to use localtime or GMT. | |
const std::string | started_at (void) const |
Generate a started-at string. | |
const std::string | stopped_at (void) const |
Generate a stopped-at string. | |
const std::string | duration (void) const |
Generate a duration string. | |
const std::string | eta (unsigned int a_percent_complete) const |
Given a percent-complete for some unknown task, estimate a time to completion. | |
const std::string | eta (unsigned int a_complete, unsigned int a_total) const |
Given a step number complete out of some total number of steps for some unknown task, estimate a time to completion. | |
const std::string | bps (uint64 a_bytes) const |
Given a number of bytes, estimate the BPS. | |
const bool | is_started (void) const |
Return whether or not the timer has been started. | |
const bool | is_stopped (void) const |
Return whether or not the timer has been stopped. | |
const duration_type | duration_secs (void) const |
Reutrn the duration in seconds. | |
const duration_type | duration_mins (void) const |
Return the duration in minutes. | |
const duration_type | duration_hours (void) const |
Return the duration in hours. | |
const duration_type | duration_days (void) const |
Return the duration in days. | |
const duration_type | duration_years (void) const |
Return the duration in years. | |
Private Member Functions | |
void | mf_start_value (const value_type a_t) |
Set the timer start value. | |
void | mf_stop_value (const value_type a_t) |
Set the timer stop value. | |
const duration_type | mf_calculate_duration (const value_type a_start, const value_type a_stop) const |
Calculate the duration between start and stop. | |
const std::string | mf_make_timer_string (const value_type a_t) const |
Generate a string in a regular human-readable format. | |
const std::string | mf_make_string (const value_type a_t) const |
Generate a string in a timestamp format. | |
const std::string | mf_make_string (const duration_type a_d) const |
Generate a duration string. | |
Private Attributes | |
value_type | m_start |
value_type | m_stop |
bool | m_started |
bool | m_stopped |
duration_type | m_duration |
bool | m_use_localtime |
Used as a stopwatch.
Definition at line 29 of file timer.h.
typedef double timer::duration_type |
typedef time_t timer::value_type |
timer::timer | ( | ) |
timer::timer | ( | const timer & | a_timer | ) |
timer::timer | ( | const value_type | a_start | ) |
timer::timer | ( | const value_type | a_start, | |
const value_type | a_stop | |||
) |
void timer::assign | ( | const value_type | a_start, | |
const value_type | a_stop | |||
) |
Assign timer from start and stop values.
Definition at line 181 of file timer.cc.
References clear(), m_duration, m_start, m_stop, mf_calculate_duration(), mf_start_value(), and mf_stop_value().
void timer::assign | ( | const value_type | a_start | ) |
Assign timer from a start value.
Definition at line 174 of file timer.cc.
References clear(), and mf_start_value().
void timer::assign | ( | const timer & | a_timer | ) |
Assign timer values from another timer instance.
Definition at line 162 of file timer.cc.
References clear(), is_started(), is_stopped(), m_duration, m_start, m_started, m_stop, m_stopped, mf_calculate_duration(), mf_start_value(), mf_stop_value(), start_value(), and stop_value().
Referenced by operator=(), test3(), and timer().
const std::string timer::bps | ( | uint64 | a_bytes | ) | const |
Given a number of bytes, estimate the BPS.
Definition at line 522 of file timer.cc.
References INTERNAL_ERROR, is_started(), is_stopped(), m_duration, throughput_to_string(), and TRY_nomem.
void timer::clear | ( | void | ) |
Clear the timer.
Definition at line 98 of file timer.cc.
References m_duration, m_start, m_started, m_stop, m_stopped, and m_use_localtime.
Referenced by assign(), report_manager::clear(), job_path_report::clear(), and timer().
const std::string timer::duration | ( | void | ) | const |
Generate a duration string.
Definition at line 385 of file timer.cc.
References INTERNAL_ERROR, is_started(), is_stopped(), m_duration, mf_make_string(), and TRY_nomem.
Referenced by archive_manager::archive(), vault_manager::delete_oldest_archive(), report_manager::format_synopsis(), archive_manager::init(), mf_calculate_duration(), job_archiver::process(), test1(), and test3().
const timer::duration_type timer::duration_days | ( | void | ) | const |
Return the duration in days.
Definition at line 442 of file timer.cc.
References duration_hours().
Referenced by duration_years(), and test2().
const timer::duration_type timer::duration_hours | ( | void | ) | const |
Return the duration in hours.
Definition at line 432 of file timer.cc.
References duration_mins().
Referenced by duration_days(), and test2().
const timer::duration_type timer::duration_mins | ( | void | ) | const |
Return the duration in minutes.
Definition at line 422 of file timer.cc.
References duration_secs().
Referenced by duration_hours(), archive_manager::mf_log_status(), and test2().
const timer::duration_type timer::duration_secs | ( | void | ) | const |
Reutrn the duration in seconds.
Definition at line 411 of file timer.cc.
References INTERNAL_ERROR, is_started(), is_stopped(), and m_duration.
Referenced by duration_mins(), job_archiver::mf_process_rsync_io(), and test2().
const timer::duration_type timer::duration_years | ( | void | ) | const |
Return the duration in years.
Definition at line 452 of file timer.cc.
References duration_days().
Referenced by test2().
const std::string timer::eta | ( | unsigned int | a_complete, | |
unsigned int | a_total | |||
) | const |
Given a step number complete out of some total number of steps for some unknown task, estimate a time to completion.
Definition at line 493 of file timer.cc.
References eta(), INTERNAL_ERROR, is_started(), is_stopped(), TRY, and TRY_nomem.
const std::string timer::eta | ( | unsigned int | a_percent_complete | ) | const |
Given a percent-complete for some unknown task, estimate a time to completion.
Definition at line 463 of file timer.cc.
References INTERNAL_ERROR, is_started(), is_stopped(), m_duration, mf_make_string(), TRY, TRY_nomem, and safe_num< T >::value().
Referenced by eta(), test(), and test3().
const bool timer::is_started | ( | void | ) | const |
Return whether or not the timer has been started.
Definition at line 399 of file timer.cc.
References m_started.
Referenced by assign(), bps(), duration(), duration_secs(), eta(), archive_manager::mf_log_status(), started_at(), and stopped_at().
const bool timer::is_stopped | ( | void | ) | const |
Return whether or not the timer has been stopped.
Definition at line 405 of file timer.cc.
References m_stopped.
Referenced by assign(), bps(), duration(), duration_secs(), eta(), and stopped_at().
const timer::duration_type timer::mf_calculate_duration | ( | const value_type | a_start, | |
const value_type | a_stop | |||
) | const [private] |
Calculate the duration between start and stop.
Definition at line 124 of file timer.cc.
References duration().
Referenced by assign(), and stop().
const std::string timer::mf_make_string | ( | const duration_type | a_d | ) | const [private] |
Generate a duration string.
Definition at line 283 of file timer.cc.
References estring::right, TRY, and TRY_nomem.
const std::string timer::mf_make_string | ( | const value_type | a_t | ) | const [private] |
Generate a string in a timestamp format.
Definition at line 273 of file timer.cc.
References mf_make_timer_string(), and TRY_nomem.
Referenced by duration(), eta(), started_at(), and stopped_at().
const std::string timer::mf_make_timer_string | ( | const value_type | a_t | ) | const [private] |
Generate a string in a regular human-readable format.
Definition at line 212 of file timer.cc.
References ERROR, m_use_localtime, estring::right, TRY, and TRY_nomem.
Referenced by mf_make_string().
void timer::mf_start_value | ( | const value_type | a_t | ) | [private] |
void timer::mf_stop_value | ( | const value_type | a_t | ) | [private] |
void timer::start | ( | void | ) |
Start (or restart) the timer.
Definition at line 137 of file timer.cc.
References mf_start_value().
Referenced by archive_manager::archive(), vault_manager::delete_oldest_archive(), archive_manager::init(), main(), job_archiver::mf_do_chores(), archive_manager::mf_log_status(), job_archiver::mf_process_rsync_io(), job_archiver::start(), test(), test1(), test2(), test_rvm(), and timer().
const timer::value_type timer::start_value | ( | void | ) | const |
const std::string timer::started_at | ( | void | ) | const |
Generate a started-at string.
Definition at line 359 of file timer.cc.
References INTERNAL_ERROR, is_started(), m_start, mf_make_string(), and TRY_nomem.
Referenced by report_manager::format_synopsis(), and test3().
void timer::stop | ( | void | ) |
Stop the timer.
Definition at line 143 of file timer.cc.
References m_duration, m_start, m_stop, mf_calculate_duration(), and mf_stop_value().
Referenced by archive_manager::archive(), vault_manager::delete_oldest_archive(), job_archiver::end(), archive_manager::init(), main(), job_archiver::mf_do_chores(), archive_manager::mf_log_status(), job_archiver::mf_process_rsync_io(), job_archiver::process(), test(), test1(), test2(), and test_rvm().
const timer::value_type timer::stop_value | ( | void | ) | const |
const std::string timer::stopped_at | ( | void | ) | const |
Generate a stopped-at string.
Definition at line 371 of file timer.cc.
References INTERNAL_ERROR, is_started(), is_stopped(), m_stop, mf_make_string(), and TRY_nomem.
Referenced by report_manager::format_synopsis(), and test3().
const bool timer::use_localtime | ( | void | ) | const |
Return whether to use localtime or GMT.
Definition at line 206 of file timer.cc.
References m_use_localtime.
void timer::use_localtime | ( | const bool | a_switch | ) |
Set whether to use localtime or GMT when constructing strings.
Definition at line 200 of file timer.cc.
References m_use_localtime.
Referenced by test3().
duration_type timer::m_duration [private] |
Definition at line 77 of file timer.h.
Referenced by assign(), bps(), clear(), duration(), duration_secs(), eta(), and stop().
value_type timer::m_start [private] |
Definition at line 73 of file timer.h.
Referenced by assign(), clear(), mf_start_value(), start_value(), started_at(), and stop().
bool timer::m_started [private] |
Definition at line 75 of file timer.h.
Referenced by assign(), clear(), is_started(), and mf_start_value().
value_type timer::m_stop [private] |
Definition at line 74 of file timer.h.
Referenced by assign(), clear(), mf_stop_value(), stop(), stop_value(), and stopped_at().
bool timer::m_stopped [private] |
Definition at line 76 of file timer.h.
Referenced by assign(), clear(), is_stopped(), and mf_stop_value().
bool timer::m_use_localtime [private] |
Definition at line 78 of file timer.h.
Referenced by clear(), mf_make_timer_string(), and use_localtime().