Kea 2.5.7
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
26 delete impl_;
27}
28
29void
31 impl_->start();
32}
33
34void
36 impl_->stop();
37}
38
39void
41 impl_->reset();
42}
43
44boost::posix_time::time_duration
46 return (impl_->getLastDuration());
47}
48
49boost::posix_time::time_duration
51 return (impl_->getTotalDuration());
52}
53
54long
56 return (getLastDuration().total_milliseconds());
57}
58
59long
61 return (getTotalDuration().total_milliseconds());
62}
63
64long
66 return (getLastDuration().total_microseconds());
67}
68
69long
71 return (getTotalDuration().total_microseconds());
72}
73
74std::string
77}
78
79std::string
82}
83
84} // end of isc::util
85} // end of isc
Stopwatch class implementation.
void start()
Starts the stopwatch.
boost::posix_time::time_duration getTotalDuration() const
Retrieves the total measured duration.
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.
void reset()
Reset the stopwatch.
void stop()
Stop the stopwatch.
boost::posix_time::time_duration getLastDuration() const
Retrieves the measured duration.
long getLastMilliseconds() const
Retrieves the last measured duration in milliseconds.
Definition: stopwatch.cc:55
long getLastMicroseconds() const
Retrieves the last measured duration in microseconds.
Definition: stopwatch.cc:65
long getTotalMilliseconds() const
Retrieves the total measured duration in milliseconds.
Definition: stopwatch.cc:60
Stopwatch(const bool autostart=true)
Constructor.
Definition: stopwatch.cc:17
void stop()
Stops the stopwatch.
Definition: stopwatch.cc:35
~Stopwatch()
Destructor.
Definition: stopwatch.cc:25
long getTotalMicroseconds() const
Retrieves the total measured duration in microseconds.
Definition: stopwatch.cc:70
boost::posix_time::time_duration getLastDuration() const
Retrieves last measured duration.
Definition: stopwatch.cc:45
void start()
Starts the stopwatch.
Definition: stopwatch.cc:30
std::string logFormatTotalDuration() const
Returns the total measured duration in the format directly usable in the log messages.
Definition: stopwatch.cc:80
void reset()
Resets the stopwatch.
Definition: stopwatch.cc:40
std::string logFormatLastDuration() const
Returns the last measured duration in the format directly usable in log messages.
Definition: stopwatch.cc:75
boost::posix_time::time_duration getTotalDuration() const
Retrieves total measured duration.
Definition: stopwatch.cc:50
Defines the logger used by the top-level component of kea-lfc.