Kea: stopwatch.cc Source File

| Kea 2.2.0

stopwatch.cc
Go to the documentation of this file.
1// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <util/stopwatch.h>
10#include <util/stopwatch_impl.h>
11
12namespace isc {
13namespace util {
14
15using namespace boost::posix_time;
16
17Stopwatch::Stopwatch(const bool autostart)
18 : impl_(new StopwatchImpl()) {
19 // If the autostart has been specified, invoke start.
20 if (autostart) {
21 start();
22 }
23}
24
25Stopwatch::~Stopwatch() {
26 delete impl_;
27}
28
29void
30Stopwatch::start() {
31 impl_->start();
32}
33
34void
35Stopwatch::stop() {
36 impl_->stop();
37}
38
39void
40Stopwatch::reset() {
41 impl_->reset();
42}
43
44boost::posix_time::time_duration
45Stopwatch::getLastDuration() const {
46 return (impl_->getLastDuration());
47}
48
49boost::posix_time::time_duration
50Stopwatch::getTotalDuration() const {
51 return (impl_->getTotalDuration());
52}
53
54long
55Stopwatch::getLastMilliseconds() const {
56 return (getLastDuration().total_milliseconds());
57}
58
59long
60Stopwatch::getTotalMilliseconds() const {
61 return (getTotalDuration().total_milliseconds());
62}
63
64long
65Stopwatch::getLastMicroseconds() const {
66 return (getLastDuration().total_microseconds());
67}
68
69long
70Stopwatch::getTotalMicroseconds() const {
71 return (getTotalDuration().total_microseconds());
72}
73
74std::string
75Stopwatch::logFormatLastDuration() const {
76 return (StopwatchImpl::logFormat(getLastDuration()));
77}
78
79std::string
80Stopwatch::logFormatTotalDuration() const {
81 return (StopwatchImpl::logFormat(getTotalDuration()));
82}
83
84} // end of isc::util
85} // end of isc
isc::util::StopwatchImpl
Stopwatch class implementation.
Definition: stopwatch_impl.h:28
isc::util::StopwatchImpl::start
void start()
Starts the stopwatch.
Definition: stopwatch_impl.cc:29
isc::util::StopwatchImpl::getTotalDuration
boost::posix_time::time_duration getTotalDuration() const
Retrieves the total measured duration.
Definition: stopwatch_impl.cc:70
isc::util::StopwatchImpl::logFormat
static std::string logFormat(const boost::posix_time::time_duration &duration)
Returns the duration in the textual format which can be directly used in log messages.
Definition: stopwatch_impl.cc:82
isc::util::StopwatchImpl::reset
void reset()
Reset the stopwatch.
Definition: stopwatch_impl.cc:49
isc::util::StopwatchImpl::stop
void stop()
Stop the stopwatch.
Definition: stopwatch_impl.cc:38
isc::util::StopwatchImpl::getLastDuration
boost::posix_time::time_duration getLastDuration() const
Retrieves the measured duration.
Definition: stopwatch_impl.cc:61
isc::util::Stopwatch::getLastMilliseconds
long getLastMilliseconds() const
Retrieves the last measured duration in milliseconds.
Definition: stopwatch.cc:55
isc::util::Stopwatch::getLastMicroseconds
long getLastMicroseconds() const
Retrieves the last measured duration in microseconds.
Definition: stopwatch.cc:65
isc::util::Stopwatch::getTotalMilliseconds
long getTotalMilliseconds() const
Retrieves the total measured duration in milliseconds.
Definition: stopwatch.cc:60
isc::util::Stopwatch::Stopwatch
Stopwatch(const bool autostart=true)
Constructor.
Definition: stopwatch.cc:17
isc::util::Stopwatch::stop
void stop()
Stops the stopwatch.
Definition: stopwatch.cc:35
isc::util::Stopwatch::~Stopwatch
~Stopwatch()
Destructor.
Definition: stopwatch.cc:25
isc::util::Stopwatch::getTotalMicroseconds
long getTotalMicroseconds() const
Retrieves the total measured duration in microseconds.
Definition: stopwatch.cc:70
isc::util::Stopwatch::getLastDuration
boost::posix_time::time_duration getLastDuration() const
Retrieves last measured duration.
Definition: stopwatch.cc:45
isc::util::Stopwatch::start
void start()
Starts the stopwatch.
Definition: stopwatch.cc:30
isc::util::Stopwatch::logFormatTotalDuration
std::string logFormatTotalDuration() const
Returns the total measured duration in the format directly usable in the log messages.
Definition: stopwatch.cc:80
isc::util::Stopwatch::reset
void reset()
Resets the stopwatch.
Definition: stopwatch.cc:40
isc::util::Stopwatch::logFormatLastDuration
std::string logFormatLastDuration() const
Returns the last measured duration in the format directly usable in log messages.
Definition: stopwatch.cc:75
isc::util::Stopwatch::getTotalDuration
boost::posix_time::time_duration getTotalDuration() const
Retrieves total measured duration.
Definition: stopwatch.cc:50
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143
stopwatch.h
stopwatch_impl.h