// boost/chrono/process_cpu_clocks.hpp -----------------------------------------------------------// // Copyright 2009-2011 Vicente J. Botet Escriba // Distributed under the Boost Software License, Version 1.0. // See http://www.boost.org/LICENSE_1_0.txt // See http://www.boost.org/libs/system for documentation. #ifndef BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP #define BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP #include #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) #include #include #include #include #include #include #include #ifndef BOOST_CHRONO_HEADER_ONLY #include // must be the last #include #endif namespace boost { namespace chrono { class BOOST_CHRONO_DECL process_real_cpu_clock { public: typedef nanoseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; BOOST_STATIC_CONSTEXPR bool is_steady = true; static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT; #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING static BOOST_CHRONO_INLINE time_point now(system::error_code & ec ); #endif }; class BOOST_CHRONO_DECL process_user_cpu_clock { public: typedef nanoseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; BOOST_STATIC_CONSTEXPR bool is_steady = true; static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT; #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING static BOOST_CHRONO_INLINE time_point now(system::error_code & ec ); #endif }; class BOOST_CHRONO_DECL process_system_cpu_clock { public: typedef nanoseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; BOOST_STATIC_CONSTEXPR bool is_steady = true; static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT; #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING static BOOST_CHRONO_INLINE time_point now(system::error_code & ec ); #endif }; template struct process_times : arithmetic, multiplicative, Rep, less_than_comparable > > > { //typedef process_real_cpu_clock::rep rep; typedef Rep rep; process_times() : real(0) , user(0) , system(0){} template explicit process_times( Rep2 r) : real(r) , user(r) , system(r){} template explicit process_times( process_times const& rhs) : real(rhs.real) , user(rhs.user) , system(rhs.system){} process_times( rep r, rep u, rep s) : real(r) , user(u) , system(s){} rep real; // real (i.e wall clock) time rep user; // user cpu time rep system; // system cpu time operator rep() const { return real; } template bool operator==(process_times const& rhs) { return (real==rhs.real && user==rhs.user && system==rhs.system); } process_times& operator+=( process_times const& rhs) { real+=rhs.real; user+=rhs.user; system+=rhs.system; return *this; } process_times& operator-=( process_times const& rhs) { real-=rhs.real; user-=rhs.user; system-=rhs.system; return *this; } process_times& operator*=( process_times const& rhs) { real*=rhs.real; user*=rhs.user; system*=rhs.system; return *this; } process_times& operator*=(rep const& rhs) { real*=rhs; user*=rhs; system*=rhs; return *this; } process_times& operator/=(process_times const& rhs) { real/=rhs.real; user/=rhs.user; system/=rhs.system; return *this; } process_times& operator/=(rep const& rhs) { real/=rhs; user/=rhs; system/=rhs; return *this; } bool operator<(process_times const & rhs) const { if (real < rhs.real) return true; if (real > rhs.real) return false; if (user < rhs.user) return true; if (user > rhs.user) return false; if (system < rhs.system) return true; else return false; } template void print(std::basic_ostream& os) const { os << "{"<< real <<";"<< user <<";"<< system << "}"; } template void read(std::basic_istream& is) const { typedef std::istreambuf_iterator in_iterator; in_iterator i(is); in_iterator e; if (i == e || *i != '{') // mandatory '{' { is.setstate(is.failbit | is.eofbit); return; } CharT x,y,z; is >> real >> x >> user >> y >> system >> z; if (!is.good() || (x != ';')|| (y != ';')|| (z != '}')) { is.setstate(is.failbit); } } }; } template struct common_type< chrono::process_times, chrono::process_times > { typedef chrono::process_times::type> type; }; template struct common_type< chrono::process_times, Rep2 > { typedef chrono::process_times::type> type; }; template struct common_type< Rep1, chrono::process_times > { typedef chrono::process_times::type> type; }; namespace chrono { template inline BOOST_CONSTEXPR bool operator==(const duration, Period1>& lhs, const duration, Period2>& rhs) { return boost::chrono::detail::duration_eq< duration, Period1>, duration, Period2> >()(lhs, rhs); } template inline BOOST_CONSTEXPR bool operator==(const duration, Period1>& lhs, const duration& rhs) { return boost::chrono::detail::duration_eq< duration, duration >()(duration(lhs.count().real), rhs); } template inline BOOST_CONSTEXPR bool operator==(const duration& lhs, const duration, Period2>& rhs) { return rhs == lhs; } // Duration < template inline BOOST_CONSTEXPR bool operator< (const duration, Period1>& lhs, const duration& rhs) { return boost::chrono::detail::duration_lt< duration, duration >()(duration(lhs.count().real), rhs); } template inline BOOST_CONSTEXPR bool operator< (const duration& lhs, const duration, Period2>& rhs) { return rhs < lhs; } template inline BOOST_CONSTEXPR bool operator< (const duration, Period1>& lhs, const duration, Period2>& rhs) { return boost::chrono::detail::duration_lt< duration, duration >()(lhs, rhs); } typedef process_times process_cpu_clock_times; class BOOST_CHRONO_DECL process_cpu_clock { public: typedef process_cpu_clock_times times; typedef boost::chrono::duration duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; BOOST_STATIC_CONSTEXPR bool is_steady = true; static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT; #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING static BOOST_CHRONO_INLINE time_point now(system::error_code & ec ); #endif }; template std::basic_ostream& operator<<(std::basic_ostream& os, process_times const& rhs) { rhs.print(os); return os; } template std::basic_istream& operator>>(std::basic_istream& is, process_times const& rhs) { rhs.read(is); return is; } template struct duration_values > { typedef process_times Res; public: static Res zero() { return Res(); } static Res max BOOST_PREVENT_MACRO_SUBSTITUTION () { return Res((std::numeric_limits::max)(), (std::numeric_limits::max)(), (std::numeric_limits::max)()); } static Res min BOOST_PREVENT_MACRO_SUBSTITUTION () { return Res((std::numeric_limits::min)(), (std::numeric_limits::min)(), (std::numeric_limits::min)()); } }; template struct clock_string { static std::basic_string name() { static const CharT u[] = { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 'r', 'e', 'a', 'l', '_', 'c', 'l', 'o', 'c', 'k' }; static const std::basic_string str(u, u + sizeof(u) / sizeof(u[0])); return str; } static std::basic_string since() { const CharT u[] = { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' }; const std::basic_string str(u, u + sizeof(u) / sizeof(u[0])); return str; } }; template struct clock_string { static std::basic_string name() { static const CharT u[] = { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 'u', 's', 'e', 'r', '_', 'c', 'l', 'o', 'c', 'k' }; static const std::basic_string str(u, u + sizeof(u) / sizeof(u[0])); return str; } static std::basic_string since() { const CharT u[] = { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' }; const std::basic_string str(u, u + sizeof(u) / sizeof(u[0])); return str; } }; template struct clock_string { static std::basic_string name() { static const CharT u[] = { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 's', 'y', 's', 't', 't', 'e', 'm', '_', 'c', 'l', 'o', 'c', 'k' }; static const std::basic_string str(u, u + sizeof(u) / sizeof(u[0])); return str; } static std::basic_string since() { const CharT u[] = { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' }; const std::basic_string str(u, u + sizeof(u) / sizeof(u[0])); return str; } }; template struct clock_string { static std::basic_string name() { static const CharT u[] = { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 'c', 'l', 'o', 'c', 'k' }; static const std::basic_string str(u, u + sizeof(u) / sizeof(u[0])); return str; } static std::basic_string since() { const CharT u[] = { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' }; const std::basic_string str(u, u + sizeof(u) / sizeof(u[0])); return str; } }; } // namespace chrono } // namespace boost namespace std { template struct numeric_limits > { typedef boost::chrono::process_times Res; public: static const bool is_specialized = true; static Res min BOOST_PREVENT_MACRO_SUBSTITUTION () { return Res((std::numeric_limits::min)(), (std::numeric_limits::min)(), (std::numeric_limits::min)()); } static Res max BOOST_PREVENT_MACRO_SUBSTITUTION () { return Res((std::numeric_limits::max)(), (std::numeric_limits::max)(), (std::numeric_limits::max)()); } static Res lowest() throw() { return (min)(); } static const int digits = std::numeric_limits::digits+ std::numeric_limits::digits+ std::numeric_limits::digits; static const int digits10 = std::numeric_limits::digits10+ std::numeric_limits::digits10+ std::numeric_limits::digits10; static const bool is_signed = Rep::is_signed; static const bool is_integer = Rep::is_integer; static const bool is_exact = Rep::is_exact; static const int radix = 0; //~ static Res epsilon() throw() { return 0; } //~ static Res round_error() throw() { return 0; } //~ static const int min_exponent = 0; //~ static const int min_exponent10 = 0; //~ static const int max_exponent = 0; //~ static const int max_exponent10 = 0; //~ static const bool has_infinity = false; //~ static const bool has_quiet_NaN = false; //~ static const bool has_signaling_NaN = false; //~ static const float_denorm_style has_denorm = denorm_absent; //~ static const bool has_denorm_loss = false; //~ static Res infinity() throw() { return 0; } //~ static Res quiet_NaN() throw() { return 0; } //~ static Res signaling_NaN() throw() { return 0; } //~ static Res denorm_min() throw() { return 0; } //~ static const bool is_iec559 = false; //~ static const bool is_bounded = true; //~ static const bool is_modulo = false; //~ static const bool traps = false; //~ static const bool tinyness_before = false; //~ static const float_round_style round_style = round_toward_zero; }; } #ifndef BOOST_CHRONO_HEADER_ONLY #include // pops abi_prefix.hpp pragmas #else #include #endif #endif #endif // BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP