void process_clock::now( process_times & times_, system::error_code & ec ) { tms tm; clock_t c = ::times( &tm ); if ( c == clock_t(-1) ) // error { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); times_.real = times_.system = times_.user = nanoseconds(-1); } } else { times_.real = microseconds(c); times_.system = microseconds(tm.tms_stime + tm.tms_cstime); times_.user = microseconds(tm.tms_utime + tm.tms_cutime); if ( chrono_detail::tick_factor() != -1 ) { if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } times_.real *= chrono_detail::tick_factor(); times_.user *= chrono_detail::tick_factor(); times_.system *= chrono_detail::tick_factor(); } else { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); times_.real = times_.user = times_.system = nanoseconds(-1); } } } }
process_cpu_clock::time_point process_cpu_clock::now( system::error_code & ec ) { tms tm; clock_t c = ::times( &tm ); if ( c == clock_t(-1) ) // error { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } else { if ( chrono_detail::tick_factor() != -1 ) { time_point::rep r( c*chrono_detail::tick_factor(), (tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(), (tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor()); return time_point(duration(r)); } else { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } } }
process_real_cpu_clock::time_point process_real_cpu_clock::now( system::error_code & ec) { tms tm; clock_t c = ::times( &tm ); if ( c == clock_t(-1) ) // error { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } else { if ( chrono_detail::tick_factor() != -1 ) { if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } return time_point( microseconds(c)*chrono_detail::tick_factor()); } else { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } } }
process_cpu_clock::time_point process_cpu_clock::now( system::error_code & ec ) { tms tm; clock_t c = ::times( &tm ); if ( c == clock_t(-1) ) // error { if (::boost::chrono::is_throws(ec)) { boost::throw_exception( system::system_error( errno, ::boost::system::system_category(), "chrono::process_clock" )); } else { ec.assign( errno, ::boost::system::system_category() ); return time_point(); } } else { if ( chrono_detail::tick_factor() != -1 ) { time_point::rep r( c*chrono_detail::tick_factor(), (tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(), (tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor()); return time_point(duration(r)); } else { if (::boost::chrono::is_throws(ec)) { boost::throw_exception( system::system_error( errno, ::boost::system::system_category(), "chrono::process_clock" )); } else { ec.assign( errno, ::boost::system::system_category() ); return time_point(); } } } }
steady_clock::time_point steady_clock::now(system::error_code & ec) { timespec ts; if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) ) { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::steady_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } return time_point(duration( static_cast<steady_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec)); }
process_cpu_clock::time_point process_cpu_clock::now( system::error_code & ec ) { // note that Windows uses 100 nanosecond ticks for FILETIME boost::detail::win32::FILETIME_ creation, exit, user_time, system_time; #ifdef UNDER_CE // Windows CE does not support GetProcessTimes assert( 0 && "GetProcessTimes not supported under Windows CE" ); return time_point(); #else if ( boost::detail::win32::GetProcessTimes( boost::detail::win32::GetCurrentProcess(), &creation, &exit, &system_time, &user_time ) ) { if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } time_point::rep r( steady_clock::now().time_since_epoch().count(), ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32) | user_time.dwLowDateTime ) * 100, ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32) | system_time.dwLowDateTime ) * 100 ); return time_point(duration(r)); } else { boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError(); if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( cause, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_cpu_clock" )); } else { ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } #endif }
process_system_cpu_clock::time_point process_system_cpu_clock::now(system::error_code & ec) { tms tm; clock_t c = ::times(&tm); if (c == clock_t(-1)) // error { if (BOOST_CHRONO_IS_THROWS(ec)) { pdalboost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_system_cpu_clock")); } else { ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY); return time_point(); } } else { long factor = chrono_detail::tick_factor(); if (factor != -1) { if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } return time_point(nanoseconds((tm.tms_stime + tm.tms_cstime) * factor)); } else { if (BOOST_CHRONO_IS_THROWS(ec)) { pdalboost::throw_exception(system::system_error(errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_system_cpu_clock")); } else { ec.assign(errno, BOOST_CHRONO_SYSTEM_CATEGORY); return time_point(); } } } }
process_cpu_clock::time_point process_cpu_clock::now( system::error_code & ec ) { // note that Windows uses 100 nanosecond ticks for FILETIME autoboost::detail::winapi::FILETIME_ creation, exit, user_time, system_time; if ( autoboost::detail::winapi::GetProcessTimes( autoboost::detail::winapi::GetCurrentProcess(), &creation, &exit, &system_time, &user_time ) ) { if (!AUTOBOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } time_point::rep r(process_real_cpu_clock::now().time_since_epoch().count() , ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32) | user_time.dwLowDateTime ) * 100, ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32) | system_time.dwLowDateTime ) * 100 ); return time_point(duration(r)); } else { autoboost::detail::winapi::DWORD_ cause = autoboost::detail::winapi::GetLastError(); if (AUTOBOOST_CHRONO_IS_THROWS(ec)) { autoboost::throw_exception( system::system_error( cause, AUTOBOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_cpu_clock" )); } else { ec.assign( cause, AUTOBOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } }
void run_timer::report( system::error_code & ec ) { m_reported = true; if ( m_format.empty() ) m_format = chrono_detail::default_format(); process_times times; elapsed( times, ec ); if (ec) return; if ( BOOST_CHRONO_IS_THROWS(ec) ) { chrono_detail::show_time( times, m_format.c_str(), m_places, m_os ); } else // non-throwing { try { chrono_detail::show_time( times, m_format.c_str(), m_places, m_os ); if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } } catch (...) // eat any exceptions { BOOST_ASSERT( 0 && "error reporting not fully implemented yet" ); if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::run_timer" )); } else { ec.assign(system::errc::success, BOOST_CHRONO_SYSTEM_CATEGORY); } } } }
process_system_cpu_clock::time_point process_system_cpu_clock::now( system::error_code & ec) { // note that Windows uses 100 nanosecond ticks for FILETIME boost::detail::win32::FILETIME_ creation, exit, user_time, system_time; if ( boost::detail::win32::GetProcessTimes( boost::detail::win32::GetCurrentProcess(), &creation, &exit, &system_time, &user_time ) ) { if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } return time_point(duration( ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32) | system_time.dwLowDateTime) * 100 )); } else { boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError(); if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( cause, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_system_cpu_clock" )); } else { ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } }