comparison DEPENDENCIES/generic/include/boost/chrono/process_cpu_clocks.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 // boost/chrono/process_cpu_clocks.hpp -----------------------------------------------------------//
2
3 // Copyright 2009-2011 Vicente J. Botet Escriba
4
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
7
8 // See http://www.boost.org/libs/system for documentation.
9
10 #ifndef BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP
11 #define BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP
12
13 #include <boost/chrono/config.hpp>
14
15
16 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
17
18 #include <boost/chrono/duration.hpp>
19 #include <boost/chrono/time_point.hpp>
20 #include <boost/operators.hpp>
21 #include <boost/chrono/detail/system.hpp>
22 #include <iostream>
23 #include <boost/type_traits/common_type.hpp>
24 #include <boost/chrono/clock_string.hpp>
25
26 #ifndef BOOST_CHRONO_HEADER_ONLY
27 #include <boost/config/abi_prefix.hpp> // must be the last #include
28 #endif
29
30 namespace boost { namespace chrono {
31
32 class BOOST_CHRONO_DECL process_real_cpu_clock {
33 public:
34 typedef nanoseconds duration;
35 typedef duration::rep rep;
36 typedef duration::period period;
37 typedef chrono::time_point<process_real_cpu_clock> time_point;
38 BOOST_STATIC_CONSTEXPR bool is_steady = true;
39
40 static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT;
41 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
42 static BOOST_CHRONO_INLINE time_point now(system::error_code & ec );
43 #endif
44 };
45
46 class BOOST_CHRONO_DECL process_user_cpu_clock {
47 public:
48 typedef nanoseconds duration;
49 typedef duration::rep rep;
50 typedef duration::period period;
51 typedef chrono::time_point<process_user_cpu_clock> time_point;
52 BOOST_STATIC_CONSTEXPR bool is_steady = true;
53
54 static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT;
55 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
56 static BOOST_CHRONO_INLINE time_point now(system::error_code & ec );
57 #endif
58 };
59
60 class BOOST_CHRONO_DECL process_system_cpu_clock {
61 public:
62 typedef nanoseconds duration;
63 typedef duration::rep rep;
64 typedef duration::period period;
65 typedef chrono::time_point<process_system_cpu_clock> time_point;
66 BOOST_STATIC_CONSTEXPR bool is_steady = true;
67
68 static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT;
69 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
70 static BOOST_CHRONO_INLINE time_point now(system::error_code & ec );
71 #endif
72 };
73
74 template <typename Rep>
75 struct process_times
76 : arithmetic<process_times<Rep>,
77 multiplicative<process_times<Rep>, Rep,
78 less_than_comparable<process_times<Rep> > > >
79 {
80 //typedef process_real_cpu_clock::rep rep;
81 typedef Rep rep;
82 process_times()
83 : real(0)
84 , user(0)
85 , system(0){}
86 template <typename Rep2>
87 explicit process_times(
88 Rep2 r)
89 : real(r)
90 , user(r)
91 , system(r){}
92 template <typename Rep2>
93 explicit process_times(
94 process_times<Rep2> const& rhs)
95 : real(rhs.real)
96 , user(rhs.user)
97 , system(rhs.system){}
98 process_times(
99 rep r,
100 rep u,
101 rep s)
102 : real(r)
103 , user(u)
104 , system(s){}
105
106 rep real; // real (i.e wall clock) time
107 rep user; // user cpu time
108 rep system; // system cpu time
109
110 operator rep() const
111 {
112 return real;
113 }
114 template <typename Rep2>
115 bool operator==(process_times<Rep2> const& rhs) {
116 return (real==rhs.real &&
117 user==rhs.user &&
118 system==rhs.system);
119 }
120
121 process_times& operator+=(
122 process_times const& rhs)
123 {
124 real+=rhs.real;
125 user+=rhs.user;
126 system+=rhs.system;
127 return *this;
128 }
129 process_times& operator-=(
130 process_times const& rhs)
131 {
132 real-=rhs.real;
133 user-=rhs.user;
134 system-=rhs.system;
135 return *this;
136 }
137 process_times& operator*=(
138 process_times const& rhs)
139 {
140 real*=rhs.real;
141 user*=rhs.user;
142 system*=rhs.system;
143 return *this;
144 }
145 process_times& operator*=(rep const& rhs)
146 {
147 real*=rhs;
148 user*=rhs;
149 system*=rhs;
150 return *this;
151 }
152 process_times& operator/=(process_times const& rhs)
153 {
154 real/=rhs.real;
155 user/=rhs.user;
156 system/=rhs.system;
157 return *this;
158 }
159 process_times& operator/=(rep const& rhs)
160 {
161 real/=rhs;
162 user/=rhs;
163 system/=rhs;
164 return *this;
165 }
166 bool operator<(process_times const & rhs) const
167 {
168 if (real < rhs.real) return true;
169 if (real > rhs.real) return false;
170 if (user < rhs.user) return true;
171 if (user > rhs.user) return false;
172 if (system < rhs.system) return true;
173 else return false;
174 }
175
176 template <class CharT, class Traits>
177 void print(std::basic_ostream<CharT, Traits>& os) const
178 {
179 os << "{"<< real <<";"<< user <<";"<< system << "}";
180 }
181
182 template <class CharT, class Traits>
183 void read(std::basic_istream<CharT, Traits>& is) const
184 {
185 typedef std::istreambuf_iterator<CharT, Traits> in_iterator;
186 in_iterator i(is);
187 in_iterator e;
188 if (i == e || *i != '{') // mandatory '{'
189 {
190 is.setstate(is.failbit | is.eofbit);
191 return;
192 }
193 CharT x,y,z;
194 is >> real >> x >> user >> y >> system >> z;
195 if (!is.good() || (x != ';')|| (y != ';')|| (z != '}'))
196 {
197 is.setstate(is.failbit);
198 }
199 }
200 };
201 }
202 template <class Rep1, class Rep2>
203 struct common_type<
204 chrono::process_times<Rep1>,
205 chrono::process_times<Rep2>
206 >
207 {
208 typedef chrono::process_times<typename common_type<Rep1, Rep2>::type> type;
209 };
210
211 template <class Rep1, class Rep2>
212 struct common_type<
213 chrono::process_times<Rep1>,
214 Rep2
215 >
216 {
217 typedef chrono::process_times<typename common_type<Rep1, Rep2>::type> type;
218 };
219
220 template <class Rep1, class Rep2>
221 struct common_type<
222 Rep1,
223 chrono::process_times<Rep2>
224 >
225 {
226 typedef chrono::process_times<typename common_type<Rep1, Rep2>::type> type;
227 };
228
229
230 namespace chrono
231 {
232 template <class Rep1, class Period1, class Rep2, class Period2>
233 inline BOOST_CONSTEXPR
234 bool
235 operator==(const duration<process_times<Rep1>, Period1>& lhs,
236 const duration<process_times<Rep2>, Period2>& rhs)
237 {
238 return boost::chrono::detail::duration_eq<
239 duration<process_times<Rep1>, Period1>, duration<process_times<Rep2>, Period2> >()(lhs, rhs);
240 }
241
242 template <class Rep1, class Period1, class Rep2, class Period2>
243 inline BOOST_CONSTEXPR
244 bool
245 operator==(const duration<process_times<Rep1>, Period1>& lhs,
246 const duration<Rep2, Period2>& rhs)
247 {
248 return boost::chrono::detail::duration_eq<
249 duration<Rep1, Period1>, duration<Rep2, Period2> >()(duration<Rep1, Period1>(lhs.count().real), rhs);
250 }
251
252 template <class Rep1, class Period1, class Rep2, class Period2>
253 inline BOOST_CONSTEXPR
254 bool
255 operator==(const duration<Rep1, Period1>& lhs,
256 const duration<process_times<Rep2>, Period2>& rhs)
257 {
258 return rhs == lhs;
259 }
260
261
262 // Duration <
263
264 template <class Rep1, class Period1, class Rep2, class Period2>
265 inline BOOST_CONSTEXPR
266 bool
267 operator< (const duration<process_times<Rep1>, Period1>& lhs,
268 const duration<Rep2, Period2>& rhs)
269 {
270 return boost::chrono::detail::duration_lt<
271 duration<Rep1, Period1>, duration<Rep2, Period2> >()(duration<Rep1, Period1>(lhs.count().real), rhs);
272 }
273
274 template <class Rep1, class Period1, class Rep2, class Period2>
275 inline BOOST_CONSTEXPR
276 bool
277 operator< (const duration<Rep1, Period1>& lhs,
278 const duration<process_times<Rep2>, Period2>& rhs)
279 {
280 return rhs < lhs;
281 }
282
283 template <class Rep1, class Period1, class Rep2, class Period2>
284 inline BOOST_CONSTEXPR
285 bool
286 operator< (const duration<process_times<Rep1>, Period1>& lhs,
287 const duration<process_times<Rep2>, Period2>& rhs)
288 {
289 return boost::chrono::detail::duration_lt<
290 duration<Rep1, Period1>, duration<Rep2, Period2> >()(lhs, rhs);
291 }
292
293
294 typedef process_times<nanoseconds::rep> process_cpu_clock_times;
295 class BOOST_CHRONO_DECL process_cpu_clock
296 {
297 public:
298
299 typedef process_cpu_clock_times times;
300 typedef boost::chrono::duration<times, nano> duration;
301 typedef duration::rep rep;
302 typedef duration::period period;
303 typedef chrono::time_point<process_cpu_clock> time_point;
304 BOOST_STATIC_CONSTEXPR bool is_steady = true;
305
306 static BOOST_CHRONO_INLINE time_point now() BOOST_NOEXCEPT;
307 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
308 static BOOST_CHRONO_INLINE time_point now(system::error_code & ec );
309 #endif
310 };
311
312 template <class CharT, class Traits, typename Rep>
313 std::basic_ostream<CharT, Traits>&
314 operator<<(std::basic_ostream<CharT, Traits>& os,
315 process_times<Rep> const& rhs)
316 {
317 rhs.print(os);
318 return os;
319 }
320
321 template <class CharT, class Traits, typename Rep>
322 std::basic_istream<CharT, Traits>&
323 operator>>(std::basic_istream<CharT, Traits>& is,
324 process_times<Rep> const& rhs)
325 {
326 rhs.read(is);
327 return is;
328 }
329
330 template <typename Rep>
331 struct duration_values<process_times<Rep> >
332 {
333 typedef process_times<Rep> Res;
334 public:
335 static Res zero()
336 {
337 return Res();
338 }
339 static Res max BOOST_PREVENT_MACRO_SUBSTITUTION ()
340 {
341 return Res((std::numeric_limits<Rep>::max)(),
342 (std::numeric_limits<Rep>::max)(),
343 (std::numeric_limits<Rep>::max)());
344 }
345 static Res min BOOST_PREVENT_MACRO_SUBSTITUTION ()
346 {
347 return Res((std::numeric_limits<Rep>::min)(),
348 (std::numeric_limits<Rep>::min)(),
349 (std::numeric_limits<Rep>::min)());
350 }
351 };
352
353 template<class CharT>
354 struct clock_string<process_real_cpu_clock, CharT>
355 {
356 static std::basic_string<CharT> name()
357 {
358 static const CharT
359 u[] =
360 { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 'r', 'e', 'a', 'l', '_', 'c', 'l', 'o', 'c', 'k' };
361 static const std::basic_string<CharT> str(u, u + sizeof(u)
362 / sizeof(u[0]));
363 return str;
364 }
365 static std::basic_string<CharT> since()
366 {
367 const CharT
368 u[] =
369 { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' };
370 const std::basic_string<CharT> str(u, u + sizeof(u) / sizeof(u[0]));
371 return str;
372 }
373 };
374
375 template<class CharT>
376 struct clock_string<process_user_cpu_clock, CharT>
377 {
378 static std::basic_string<CharT> name()
379 {
380 static const CharT
381 u[] =
382 { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 'u', 's', 'e', 'r', '_', 'c', 'l', 'o', 'c', 'k' };
383 static const std::basic_string<CharT> str(u, u + sizeof(u)
384 / sizeof(u[0]));
385 return str;
386 }
387 static std::basic_string<CharT> since()
388 {
389 const CharT
390 u[] =
391 { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' };
392 const std::basic_string<CharT> str(u, u + sizeof(u) / sizeof(u[0]));
393 return str;
394 }
395 };
396
397 template<class CharT>
398 struct clock_string<process_system_cpu_clock, CharT>
399 {
400 static std::basic_string<CharT> name()
401 {
402 static const CharT
403 u[] =
404 { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 's', 'y', 's', 't', 't', 'e', 'm', '_', 'c', 'l', 'o', 'c', 'k' };
405 static const std::basic_string<CharT> str(u, u + sizeof(u)
406 / sizeof(u[0]));
407 return str;
408 }
409 static std::basic_string<CharT> since()
410 {
411 const CharT
412 u[] =
413 { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' };
414 const std::basic_string<CharT> str(u, u + sizeof(u) / sizeof(u[0]));
415 return str;
416 }
417 };
418
419 template<class CharT>
420 struct clock_string<process_cpu_clock, CharT>
421 {
422 static std::basic_string<CharT> name()
423 {
424 static const CharT u[] =
425 { 'p', 'r', 'o', 'c', 'e', 's', 's', '_', 'c', 'l', 'o', 'c', 'k' };
426 static const std::basic_string<CharT> str(u, u + sizeof(u)
427 / sizeof(u[0]));
428 return str;
429 }
430 static std::basic_string<CharT> since()
431 {
432 const CharT
433 u[] =
434 { ' ', 's', 'i', 'n', 'c', 'e', ' ', 'p', 'r', 'o', 'c', 'e', 's', 's', ' ', 's', 't', 'a', 'r', 't', '-', 'u', 'p' };
435 const std::basic_string<CharT> str(u, u + sizeof(u) / sizeof(u[0]));
436 return str;
437 }
438 };
439
440 } // namespace chrono
441 } // namespace boost
442
443 namespace std {
444
445 template <typename Rep>
446 struct numeric_limits<boost::chrono::process_times<Rep> >
447 {
448 typedef boost::chrono::process_times<Rep> Res;
449
450 public:
451 static const bool is_specialized = true;
452 static Res min BOOST_PREVENT_MACRO_SUBSTITUTION ()
453 {
454 return Res((std::numeric_limits<Rep>::min)(),
455 (std::numeric_limits<Rep>::min)(),
456 (std::numeric_limits<Rep>::min)());
457 }
458 static Res max BOOST_PREVENT_MACRO_SUBSTITUTION ()
459 {
460 return Res((std::numeric_limits<Rep>::max)(),
461 (std::numeric_limits<Rep>::max)(),
462 (std::numeric_limits<Rep>::max)());
463 }
464 static Res lowest() throw()
465 {
466 return (min)();
467 }
468 static const int digits = std::numeric_limits<Rep>::digits+
469 std::numeric_limits<Rep>::digits+
470 std::numeric_limits<Rep>::digits;
471 static const int digits10 = std::numeric_limits<Rep>::digits10+
472 std::numeric_limits<Rep>::digits10+
473 std::numeric_limits<Rep>::digits10;
474 static const bool is_signed = Rep::is_signed;
475 static const bool is_integer = Rep::is_integer;
476 static const bool is_exact = Rep::is_exact;
477 static const int radix = 0;
478 //~ static Res epsilon() throw() { return 0; }
479 //~ static Res round_error() throw() { return 0; }
480 //~ static const int min_exponent = 0;
481 //~ static const int min_exponent10 = 0;
482 //~ static const int max_exponent = 0;
483 //~ static const int max_exponent10 = 0;
484 //~ static const bool has_infinity = false;
485 //~ static const bool has_quiet_NaN = false;
486 //~ static const bool has_signaling_NaN = false;
487 //~ static const float_denorm_style has_denorm = denorm_absent;
488 //~ static const bool has_denorm_loss = false;
489 //~ static Res infinity() throw() { return 0; }
490 //~ static Res quiet_NaN() throw() { return 0; }
491 //~ static Res signaling_NaN() throw() { return 0; }
492 //~ static Res denorm_min() throw() { return 0; }
493 //~ static const bool is_iec559 = false;
494 //~ static const bool is_bounded = true;
495 //~ static const bool is_modulo = false;
496 //~ static const bool traps = false;
497 //~ static const bool tinyness_before = false;
498 //~ static const float_round_style round_style = round_toward_zero;
499
500 };
501 }
502
503 #ifndef BOOST_CHRONO_HEADER_ONLY
504 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
505 #else
506 #include <boost/chrono/detail/inlined/process_cpu_clocks.hpp>
507 #endif
508 #endif
509
510 #endif // BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP