]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/timer/timer.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / timer / timer.hpp
1 // boost/timer/timer.hpp -------------------------------------------------------------//
2
3 // Copyright Beman Dawes 1994-2007, 2011
4
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
7
8 #ifndef BOOST_TIMER_TIMER_HPP
9 #define BOOST_TIMER_TIMER_HPP
10
11 #include <boost/timer/config.hpp>
12 #include <boost/cstdint.hpp>
13 #include <string>
14 #include <cstring>
15 #include <ostream>
16
17 #include <boost/config/abi_prefix.hpp> // must be the last #include
18
19 # if defined(_MSC_VER)
20 # pragma warning(push) // Save warning settings
21 # pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>'
22 # endif // needs to have dll-interface...
23
24 //--------------------------------------------------------------------------------------//
25
26 namespace boost
27 {
28 namespace timer
29 {
30 class cpu_timer;
31 class auto_cpu_timer;
32
33 typedef boost::int_least64_t nanosecond_type;
34
35 struct cpu_times
36 {
37 nanosecond_type wall;
38 nanosecond_type user;
39 nanosecond_type system;
40
41 void clear() { wall = user = system = 0; }
42 };
43
44 const short default_places = 6;
45
46 BOOST_TIMER_DECL
47 std::string format(const cpu_times& times, short places, const std::string& format);
48
49 BOOST_TIMER_DECL
50 std::string format(const cpu_times& times, short places = default_places);
51
52 // cpu_timer -------------------------------------------------------------------------//
53
54 class BOOST_TIMER_DECL cpu_timer
55 {
56 public:
57
58 // constructor
59 cpu_timer() BOOST_NOEXCEPT { start(); }
60
61 // observers
62 bool is_stopped() const BOOST_NOEXCEPT { return m_is_stopped; }
63 cpu_times elapsed() const BOOST_NOEXCEPT; // does not stop()
64 std::string format(short places, const std::string& format) const
65 { return ::boost::timer::format(elapsed(), places, format); }
66 std::string format(short places = default_places) const
67 { return ::boost::timer::format(elapsed(), places); }
68 // actions
69 void start() BOOST_NOEXCEPT;
70 void stop() BOOST_NOEXCEPT;
71 void resume() BOOST_NOEXCEPT;
72
73 private:
74 cpu_times m_times;
75 bool m_is_stopped;
76 };
77
78 // auto_cpu_timer --------------------------------------------------------------------//
79
80 class BOOST_TIMER_DECL auto_cpu_timer : public cpu_timer
81 {
82 public:
83
84 // Explicit defaults for os are not provided to avoid including <iostream>, which has
85 // high costs even when the standard streams are not actually used. Explicit defaults
86 // for format are not provided to avoid order-of-dynamic-initialization issues with a
87 // std::string.
88
89 explicit auto_cpu_timer(short places = default_places); // #1
90 auto_cpu_timer(short places, const std::string& format); // #2
91 explicit auto_cpu_timer(const std::string& format); // #3
92 auto_cpu_timer(std::ostream& os, short places,
93 const std::string& format) // #4
94 : m_places(places), m_os(&os), m_format(format)
95 { start(); }
96 explicit auto_cpu_timer(std::ostream& os, short places = default_places); // #5
97 auto_cpu_timer(std::ostream& os, const std::string& format) // #6
98 : m_places(default_places), m_os(&os), m_format(format)
99 { start(); }
100
101 ~auto_cpu_timer();
102
103 // observers
104 // not particularly useful to users, but allow testing of constructor
105 // postconditions and ease specification of other functionality without resorting
106 // to "for exposition only" private members.
107 std::ostream& ostream() const { return *m_os; }
108 short places() const { return m_places; }
109 const std::string& format_string() const { return m_format; }
110
111 // actions
112 void report();
113
114 private:
115 short m_places;
116 std::ostream* m_os; // stored as ptr so compiler can generate operator=
117 std::string m_format;
118 };
119
120 } // namespace timer
121 } // namespace boost
122
123 # if defined(_MSC_VER)
124 # pragma warning(pop) // restore warning settings.
125 # endif
126
127 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
128
129 #endif // BOOST_TIMER_TIMER_HPP