timer.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #ifndef BOOST_LOG_ATTRIBUTES_TIMER_HPP_INCLUDED_
  15. #define BOOST_LOG_ATTRIBUTES_TIMER_HPP_INCLUDED_
  16. #include <boost/log/detail/config.hpp>
  17. #include <boost/log/attributes/attribute.hpp>
  18. #include <boost/log/attributes/attribute_cast.hpp>
  19. #include <boost/log/attributes/time_traits.hpp>
  20. #include <boost/log/detail/header.hpp>
  21. #ifdef BOOST_HAS_PRAGMA_ONCE
  22. #pragma once
  23. #endif
  24. namespace boost {
  25. BOOST_LOG_OPEN_NAMESPACE
  26. namespace attributes {
  27. /*!
  28. * \brief A class of an attribute that makes an attribute value of the time interval since construction
  29. *
  30. * The timer attribute calculates the time passed since its construction and returns it on value acquisition.
  31. * The attribute value type is <tt>boost::posix_time::time_duration</tt>.
  32. *
  33. * On Windows platform there are two implementations of the attribute. The default one is more precise but
  34. * a bit slower. This version uses <tt>QueryPerformanceFrequence</tt>/<tt>QueryPerformanceCounter</tt> API
  35. * to calculate elapsed time.
  36. *
  37. * There are known problems with these functions when used with some CPUs, notably AMD Athlon with
  38. * Cool'n'Quiet technology enabled. See the following links for more information and possible resolutions:
  39. *
  40. * http://support.microsoft.com/?scid=kb;en-us;895980
  41. * http://support.microsoft.com/?id=896256
  42. *
  43. * In case if none of these solutions apply, you are free to define <tt>BOOST_LOG_NO_QUERY_PERFORMANCE_COUNTER</tt> macro to
  44. * fall back to another implementation based on Boost.DateTime.
  45. */
  46. class BOOST_LOG_API timer :
  47. public attribute
  48. {
  49. public:
  50. //! Attribute value type
  51. typedef utc_time_traits::time_type::time_duration_type value_type;
  52. private:
  53. //! Factory implementation
  54. class BOOST_SYMBOL_VISIBLE impl;
  55. public:
  56. /*!
  57. * Constructor. Starts time counting.
  58. */
  59. timer();
  60. /*!
  61. * Constructor for casting support
  62. */
  63. explicit timer(cast_source const& source);
  64. };
  65. } // namespace attributes
  66. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  67. } // namespace boost
  68. #include <boost/log/detail/footer.hpp>
  69. #endif // BOOST_LOG_ATTRIBUTES_TIMER_HPP_INCLUDED_