File indexing completed on 2025-01-18 09:29:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP
0012 #define BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP
0013
0014 #include <boost/chrono/config.hpp>
0015
0016
0017 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
0018
0019 #include <boost/chrono/duration.hpp>
0020 #include <boost/chrono/time_point.hpp>
0021 #include <boost/operators.hpp>
0022 #include <boost/chrono/detail/system.hpp>
0023 #include <iosfwd>
0024 #include <boost/type_traits/common_type.hpp>
0025 #include <boost/chrono/clock_string.hpp>
0026
0027 #ifndef BOOST_CHRONO_HEADER_ONLY
0028 #include <boost/config/abi_prefix.hpp> // must be the last #include
0029 #endif
0030
0031 namespace boost { namespace chrono {
0032
0033 class BOOST_CHRONO_DECL process_real_cpu_clock {
0034 public:
0035 typedef nanoseconds duration;
0036 typedef duration::rep rep;
0037 typedef duration::period period;
0038 typedef chrono::time_point<process_real_cpu_clock> time_point;
0039 BOOST_STATIC_CONSTEXPR bool is_steady = true;
0040
0041 static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT;
0042 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0043 static BOOST_CHRONO_INLINE time_point now(system::error_code & ec );
0044 #endif
0045 };
0046
0047 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
0048 class BOOST_CHRONO_DECL process_user_cpu_clock {
0049 public:
0050 typedef nanoseconds duration;
0051 typedef duration::rep rep;
0052 typedef duration::period period;
0053 typedef chrono::time_point<process_user_cpu_clock> time_point;
0054 BOOST_STATIC_CONSTEXPR bool is_steady = true;
0055
0056 static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT;
0057 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0058 static BOOST_CHRONO_INLINE time_point now(system::error_code & ec );
0059 #endif
0060 };
0061
0062 class BOOST_CHRONO_DECL process_system_cpu_clock {
0063 public:
0064 typedef nanoseconds duration;
0065 typedef duration::rep rep;
0066 typedef duration::period period;
0067 typedef chrono::time_point<process_system_cpu_clock> time_point;
0068 BOOST_STATIC_CONSTEXPR bool is_steady = true;
0069
0070 static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT;
0071 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0072 static BOOST_CHRONO_INLINE time_point now(system::error_code & ec );
0073 #endif
0074 };
0075 #endif
0076
0077 template <typename Rep>
0078 struct process_times
0079 : arithmetic<process_times<Rep>,
0080 multiplicative<process_times<Rep>, Rep,
0081 less_than_comparable<process_times<Rep> > > >
0082 {
0083
0084 typedef Rep rep;
0085 process_times()
0086 : real(0)
0087 , user(0)
0088 , system(0){}
0089
0090 #if ! defined BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0
0091 template <typename Rep2>
0092 explicit process_times(
0093 Rep2 r)
0094 : real(r)
0095 , user(r)
0096 , system(r){}
0097 #endif
0098 template <typename Rep2>
0099 explicit process_times(
0100 process_times<Rep2> const& rhs)
0101 : real(rhs.real)
0102 , user(rhs.user)
0103 , system(rhs.system){}
0104 process_times(
0105 rep r,
0106 rep u,
0107 rep s)
0108 : real(r)
0109 , user(u)
0110 , system(s){}
0111
0112 rep real;
0113 rep user;
0114 rep system;
0115
0116 #if ! defined BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0
0117 operator rep() const
0118 {
0119 return real;
0120 }
0121 #endif
0122 template <typename Rep2>
0123 bool operator==(process_times<Rep2> const& rhs) {
0124 return (real==rhs.real &&
0125 user==rhs.user &&
0126 system==rhs.system);
0127 }
0128
0129 process_times& operator+=(
0130 process_times const& rhs)
0131 {
0132 real+=rhs.real;
0133 user+=rhs.user;
0134 system+=rhs.system;
0135 return *this;
0136 }
0137 process_times& operator-=(
0138 process_times const& rhs)
0139 {
0140 real-=rhs.real;
0141 user-=rhs.user;
0142 system-=rhs.system;
0143 return *this;
0144 }
0145 process_times& operator*=(
0146 process_times const& rhs)
0147 {
0148 real*=rhs.real;
0149 user*=rhs.user;
0150 system*=rhs.system;
0151 return *this;
0152 }
0153 process_times& operator*=(rep const& rhs)
0154 {
0155 real*=rhs;
0156 user*=rhs;
0157 system*=rhs;
0158 return *this;
0159 }
0160 process_times& operator/=(process_times const& rhs)
0161 {
0162 real/=rhs.real;
0163 user/=rhs.user;
0164 system/=rhs.system;
0165 return *this;
0166 }
0167 process_times& operator/=(rep const& rhs)
0168 {
0169 real/=rhs;
0170 user/=rhs;
0171 system/=rhs;
0172 return *this;
0173 }
0174 bool operator<(process_times const & rhs) const
0175 {
0176 if (real < rhs.real) return true;
0177 if (real > rhs.real) return false;
0178 if (user < rhs.user) return true;
0179 if (user > rhs.user) return false;
0180 if (system < rhs.system) return true;
0181 else return false;
0182 }
0183
0184 template <class CharT, class Traits>
0185 void print(std::basic_ostream<CharT, Traits>& os) const
0186 {
0187 os << "{"<< real <<";"<< user <<";"<< system << "}";
0188 }
0189
0190 template <class CharT, class Traits>
0191 void read(std::basic_istream<CharT, Traits>& is)
0192 {
0193 typedef std::istreambuf_iterator<CharT, Traits> in_iterator;
0194 in_iterator i(is);
0195 in_iterator e;
0196 if (i == e || *i++ != '{')
0197 {
0198 is.setstate(is.failbit | is.eofbit);
0199 return;
0200 }
0201 CharT x,y,z;
0202 is >> real >> x >> user >> y >> system >> z;
0203 if (!is.good() || (x != ';')|| (y != ';')|| (z != '}'))
0204 {
0205 is.setstate(is.failbit);
0206 }
0207 }
0208 };
0209 }
0210 template <class Rep1, class Rep2>
0211 struct common_type<
0212 chrono::process_times<Rep1>,
0213 chrono::process_times<Rep2>
0214 >
0215 {
0216 typedef chrono::process_times<typename common_type<Rep1, Rep2>::type> type;
0217 };
0218
0219 template <class Rep1, class Rep2>
0220 struct common_type<
0221 chrono::process_times<Rep1>,
0222 Rep2
0223 >
0224 {
0225 typedef chrono::process_times<typename common_type<Rep1, Rep2>::type> type;
0226 };
0227
0228 template <class Rep1, class Rep2>
0229 struct common_type<
0230 Rep1,
0231 chrono::process_times<Rep2>
0232 >
0233 {
0234 typedef chrono::process_times<typename common_type<Rep1, Rep2>::type> type;
0235 };
0236
0237
0238 namespace chrono
0239 {
0240 template <class Rep1, class Period1, class Rep2, class Period2>
0241 inline BOOST_CONSTEXPR
0242 bool
0243 operator==(const duration<process_times<Rep1>, Period1>& lhs,
0244 const duration<process_times<Rep2>, Period2>& rhs)
0245 {
0246 return boost::chrono::detail::duration_eq<
0247 duration<Rep1, Period1>, duration<Rep2, Period2>
0248 >()(duration<Rep1, Period1>(lhs.count().real), duration<Rep2, Period2>(rhs.count().real));
0249 }
0250
0251 template <class Rep1, class Period1, class Rep2, class Period2>
0252 inline BOOST_CONSTEXPR
0253 bool
0254 operator==(const duration<process_times<Rep1>, Period1>& lhs,
0255 const duration<Rep2, Period2>& rhs)
0256 {
0257 return boost::chrono::detail::duration_eq<
0258 duration<Rep1, Period1>, duration<Rep2, Period2> >()(duration<Rep1, Period1>(lhs.count().real), rhs);
0259 }
0260
0261 template <class Rep1, class Period1, class Rep2, class Period2>
0262 inline BOOST_CONSTEXPR
0263 bool
0264 operator==(const duration<Rep1, Period1>& lhs,
0265 const duration<process_times<Rep2>, Period2>& rhs)
0266 {
0267 return rhs == lhs;
0268 }
0269
0270
0271
0272
0273 template <class Rep1, class Period1, class Rep2, class Period2>
0274 inline BOOST_CONSTEXPR
0275 bool
0276 operator< (const duration<process_times<Rep1>, Period1>& lhs,
0277 const duration<Rep2, Period2>& rhs)
0278 {
0279 return boost::chrono::detail::duration_lt<
0280 duration<Rep1, Period1>, duration<Rep2, Period2> >()(duration<Rep1, Period1>(lhs.count().real), rhs);
0281 }
0282
0283 template <class Rep1, class Period1, class Rep2, class Period2>
0284 inline BOOST_CONSTEXPR
0285 bool
0286 operator< (const duration<Rep1, Period1>& lhs,
0287 const duration<process_times<Rep2>, Period2>& rhs)
0288 {
0289 return boost::chrono::detail::duration_lt<
0290 duration<Rep1, Period1>, duration<Rep2, Period2> >()(lhs, duration<Rep2, Period2>(rhs.count().real));
0291 }
0292
0293 template <class Rep1, class Period1, class Rep2, class Period2>
0294 inline BOOST_CONSTEXPR
0295 bool
0296 operator< (const duration<process_times<Rep1>, Period1>& lhs,
0297 const duration<process_times<Rep2>, Period2>& rhs)
0298 {
0299 return boost::chrono::detail::duration_lt<
0300 duration<Rep1, Period1>, duration<Rep2, Period2>
0301 >()(duration<Rep1, Period1>(lhs.count().real), duration<Rep2, Period2>(rhs.count().real));
0302 }
0303
0304
0305 typedef process_times<nanoseconds::rep> process_cpu_clock_times;
0306 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
0307 class BOOST_CHRONO_DECL process_cpu_clock
0308 {
0309 public:
0310
0311 typedef process_cpu_clock_times times;
0312 typedef boost::chrono::duration<times, nano> duration;
0313 typedef duration::rep rep;
0314 typedef duration::period period;
0315 typedef chrono::time_point<process_cpu_clock> time_point;
0316 BOOST_STATIC_CONSTEXPR bool is_steady = true;
0317
0318 static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT;
0319 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0320 static BOOST_CHRONO_INLINE time_point now(system::error_code & ec );
0321 #endif
0322 };
0323 #endif
0324
0325 template <class CharT, class Traits, typename Rep>
0326 std::basic_ostream<CharT, Traits>&
0327 operator<<(std::basic_ostream<CharT, Traits>& os,
0328 process_times<Rep> const& rhs)
0329 {
0330 rhs.print(os);
0331 return os;
0332 }
0333
0334 template <class CharT, class Traits, typename Rep>
0335 std::basic_istream<CharT, Traits>&
0336 operator>>(std::basic_istream<CharT, Traits>& is,
0337 process_times<Rep>& rhs)
0338 {
0339 rhs.read(is);
0340 return is;
0341 }
0342
0343 template <typename Rep>
0344 struct duration_values<process_times<Rep> >
0345 {
0346 typedef process_times<Rep> Res;
0347 public:
0348 static Res zero()
0349 {
0350 return Res();
0351 }
0352 static Res max BOOST_PREVENT_MACRO_SUBSTITUTION ()
0353 {
0354 return Res((std::numeric_limits<Rep>::max)(),
0355 (std::numeric_limits<Rep>::max)(),
0356 (std::numeric_limits<Rep>::max)());
0357 }
0358 static Res min BOOST_PREVENT_MACRO_SUBSTITUTION ()
0359 {
0360 return Res((std::numeric_limits<Rep>::min)(),
0361 (std::numeric_limits<Rep>::min)(),
0362 (std::numeric_limits<Rep>::min)());
0363 }
0364 };
0365
0366 template<class CharT>
0367 struct clock_string<process_real_cpu_clock, CharT>
0368 {
0369 static std::basic_string<CharT> name()
0370 {
0371 static const CharT
0372 u[] =
0373 { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 'r', 'e', 'a', 'l', '_', 'c', 'l', 'o', 'c', 'k' };
0374 static const std::basic_string<CharT> str(u, u + sizeof(u)
0375 / sizeof(u[0]));
0376 return str;
0377 }
0378 static std::basic_string<CharT> since()
0379 {
0380 const CharT
0381 u[] =
0382 { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' };
0383 const std::basic_string<CharT> str(u, u + sizeof(u) / sizeof(u[0]));
0384 return str;
0385 }
0386 };
0387
0388 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
0389 template<class CharT>
0390 struct clock_string<process_user_cpu_clock, CharT>
0391 {
0392 static std::basic_string<CharT> name()
0393 {
0394 static const CharT
0395 u[] =
0396 { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 'u', 's', 'e', 'r', '_', 'c', 'l', 'o', 'c', 'k' };
0397 static const std::basic_string<CharT> str(u, u + sizeof(u)
0398 / sizeof(u[0]));
0399 return str;
0400 }
0401 static std::basic_string<CharT> since()
0402 {
0403 const CharT
0404 u[] =
0405 { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' };
0406 const std::basic_string<CharT> str(u, u + sizeof(u) / sizeof(u[0]));
0407 return str;
0408 }
0409 };
0410
0411 template<class CharT>
0412 struct clock_string<process_system_cpu_clock, CharT>
0413 {
0414 static std::basic_string<CharT> name()
0415 {
0416 static const CharT
0417 u[] =
0418 { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 's', 'y', 's', 't', 'e', 'm', '_', 'c', 'l', 'o', 'c', 'k' };
0419 static const std::basic_string<CharT> str(u, u + sizeof(u)
0420 / sizeof(u[0]));
0421 return str;
0422 }
0423 static std::basic_string<CharT> since()
0424 {
0425 const CharT
0426 u[] =
0427 { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' };
0428 const std::basic_string<CharT> str(u, u + sizeof(u) / sizeof(u[0]));
0429 return str;
0430 }
0431 };
0432
0433 template<class CharT>
0434 struct clock_string<process_cpu_clock, CharT>
0435 {
0436 static std::basic_string<CharT> name()
0437 {
0438 static const CharT u[] =
0439 { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 'c', 'l', 'o', 'c', 'k' };
0440 static const std::basic_string<CharT> str(u, u + sizeof(u)
0441 / sizeof(u[0]));
0442 return str;
0443 }
0444 static std::basic_string<CharT> since()
0445 {
0446 const CharT
0447 u[] =
0448 { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' };
0449 const std::basic_string<CharT> str(u, u + sizeof(u) / sizeof(u[0]));
0450 return str;
0451 }
0452 };
0453 #endif
0454
0455 }
0456 }
0457
0458 namespace std {
0459
0460 template <typename Rep>
0461 struct numeric_limits<boost::chrono::process_times<Rep> >
0462 {
0463 typedef boost::chrono::process_times<Rep> Res;
0464
0465 public:
0466 static const bool is_specialized = true;
0467 static Res min BOOST_PREVENT_MACRO_SUBSTITUTION ()
0468 {
0469 return Res((std::numeric_limits<Rep>::min)(),
0470 (std::numeric_limits<Rep>::min)(),
0471 (std::numeric_limits<Rep>::min)());
0472 }
0473 static Res max BOOST_PREVENT_MACRO_SUBSTITUTION ()
0474 {
0475 return Res((std::numeric_limits<Rep>::max)(),
0476 (std::numeric_limits<Rep>::max)(),
0477 (std::numeric_limits<Rep>::max)());
0478 }
0479 static Res lowest() BOOST_NOEXCEPT_OR_NOTHROW
0480 {
0481 return (min)();
0482 }
0483 static const int digits = std::numeric_limits<Rep>::digits+
0484 std::numeric_limits<Rep>::digits+
0485 std::numeric_limits<Rep>::digits;
0486 static const int digits10 = std::numeric_limits<Rep>::digits10+
0487 std::numeric_limits<Rep>::digits10+
0488 std::numeric_limits<Rep>::digits10;
0489 static const bool is_signed = Rep::is_signed;
0490 static const bool is_integer = Rep::is_integer;
0491 static const bool is_exact = Rep::is_exact;
0492 static const int radix = 0;
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515 };
0516 }
0517
0518 #ifndef BOOST_CHRONO_HEADER_ONLY
0519 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
0520 #else
0521 #include <boost/chrono/detail/inlined/process_cpu_clocks.hpp>
0522 #endif
0523 #endif
0524
0525 #endif