Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file timer.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 02.12.2007
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains implementation of a stop watch attribute.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_ATTRIBUTES_TIMER_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_ATTRIBUTES_TIMER_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/log/detail/config.hpp>
|
Chris@16
|
19 #include <boost/log/attributes/attribute.hpp>
|
Chris@16
|
20 #include <boost/log/attributes/attribute_cast.hpp>
|
Chris@16
|
21 #include <boost/log/attributes/time_traits.hpp>
|
Chris@16
|
22 #include <boost/log/detail/header.hpp>
|
Chris@16
|
23
|
Chris@16
|
24 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
25 #pragma once
|
Chris@16
|
26 #endif
|
Chris@16
|
27
|
Chris@16
|
28 namespace boost {
|
Chris@16
|
29
|
Chris@16
|
30 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
31
|
Chris@16
|
32 namespace attributes {
|
Chris@16
|
33
|
Chris@16
|
34 /*!
|
Chris@16
|
35 * \brief A class of an attribute that makes an attribute value of the time interval since construction
|
Chris@16
|
36 *
|
Chris@16
|
37 * The timer attribute calculates the time passed since its construction and returns it on value acquisition.
|
Chris@16
|
38 * The attribute value type is <tt>boost::posix_time::time_duration</tt>.
|
Chris@16
|
39 *
|
Chris@16
|
40 * On Windows platform there are two implementations of the attribute. The default one is more precise but
|
Chris@16
|
41 * a bit slower. This version uses <tt>QueryPerformanceFrequence</tt>/<tt>QueryPerformanceCounter</tt> API
|
Chris@16
|
42 * to calculate elapsed time.
|
Chris@16
|
43 *
|
Chris@16
|
44 * There are known problems with these functions when used with some CPUs, notably AMD Athlon with
|
Chris@16
|
45 * Cool'n'Quiet technology enabled. See the following links for more information and possible resolutions:
|
Chris@16
|
46 *
|
Chris@16
|
47 * http://support.microsoft.com/?scid=kb;en-us;895980
|
Chris@16
|
48 * http://support.microsoft.com/?id=896256
|
Chris@16
|
49 *
|
Chris@16
|
50 * In case if none of these solutions apply, you are free to define <tt>BOOST_LOG_NO_QUERY_PERFORMANCE_COUNTER</tt> macro to
|
Chris@16
|
51 * fall back to another implementation based on Boost.DateTime.
|
Chris@16
|
52 */
|
Chris@16
|
53 class BOOST_LOG_API timer :
|
Chris@16
|
54 public attribute
|
Chris@16
|
55 {
|
Chris@16
|
56 public:
|
Chris@16
|
57 //! Attribute value type
|
Chris@16
|
58 typedef utc_time_traits::time_type::time_duration_type value_type;
|
Chris@16
|
59
|
Chris@16
|
60 private:
|
Chris@16
|
61 //! Factory implementation
|
Chris@16
|
62 class BOOST_SYMBOL_VISIBLE impl;
|
Chris@16
|
63
|
Chris@16
|
64 public:
|
Chris@16
|
65 /*!
|
Chris@16
|
66 * Constructor. Starts time counting.
|
Chris@16
|
67 */
|
Chris@16
|
68 timer();
|
Chris@16
|
69 /*!
|
Chris@16
|
70 * Constructor for casting support
|
Chris@16
|
71 */
|
Chris@16
|
72 explicit timer(cast_source const& source);
|
Chris@16
|
73 };
|
Chris@16
|
74
|
Chris@16
|
75 } // namespace attributes
|
Chris@16
|
76
|
Chris@16
|
77 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
78
|
Chris@16
|
79 } // namespace boost
|
Chris@16
|
80
|
Chris@16
|
81 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
82
|
Chris@16
|
83 #endif // BOOST_LOG_ATTRIBUTES_TIMER_HPP_INCLUDED_
|