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