stopwatch.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <util/stopwatch.h>
  15. #include <util/stopwatch_impl.h>
  16. namespace isc {
  17. namespace util {
  18. using namespace boost::posix_time;
  19. Stopwatch::Stopwatch(const bool autostart)
  20. : impl_(new StopwatchImpl()) {
  21. // If the autostart has been specified, invoke start.
  22. if (autostart) {
  23. start();
  24. }
  25. }
  26. Stopwatch::~Stopwatch() {
  27. delete impl_;
  28. }
  29. void
  30. Stopwatch::start() {
  31. impl_->start();
  32. }
  33. void
  34. Stopwatch::stop() {
  35. impl_->stop();
  36. }
  37. void
  38. Stopwatch::reset() {
  39. impl_->reset();
  40. }
  41. boost::posix_time::time_duration
  42. Stopwatch::getLastDuration() const {
  43. return (impl_->getLastDuration());
  44. }
  45. boost::posix_time::time_duration
  46. Stopwatch::getTotalDuration() const {
  47. return (impl_->getTotalDuration());
  48. }
  49. long
  50. Stopwatch::getLastMilliseconds() const {
  51. return (getLastDuration().total_milliseconds());
  52. }
  53. long
  54. Stopwatch::getTotalMilliseconds() const {
  55. return (getTotalDuration().total_milliseconds());
  56. }
  57. long
  58. Stopwatch::getLastMicroseconds() const {
  59. return (getLastDuration().total_microseconds());
  60. }
  61. long
  62. Stopwatch::getTotalMicroseconds() const {
  63. return (getTotalDuration().total_microseconds());
  64. }
  65. std::string
  66. Stopwatch::logFormatLastDuration() const {
  67. return (StopwatchImpl::logFormat(getLastDuration()));
  68. }
  69. std::string
  70. Stopwatch::logFormatTotalDuration() const {
  71. return (StopwatchImpl::logFormat(getTotalDuration()));
  72. }
  73. } // end of isc::util
  74. } // end of isc