| Kea 3.0.2-git

stopwatch.cc
Go to the documentation of this file.
1// Copyright (C) 2015-2024 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
12 namespace isc {
13 namespace util {
14
15 using namespace boost::posix_time;
16
17 Stopwatch::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
25 Stopwatch::~Stopwatch() {
26}
27
28 void
29 Stopwatch::start() {
30 impl_->start();
31}
32
33 void
34 Stopwatch::stop() {
35 impl_->stop();
36}
37
38 void
39 Stopwatch::reset() {
40 impl_->reset();
41}
42
43boost::posix_time::time_duration
44 Stopwatch::getLastDuration() const {
45 return (impl_->getLastDuration());
46}
47
48boost::posix_time::time_duration
49 Stopwatch::getTotalDuration() const {
50 return (impl_->getTotalDuration());
51}
52
53 long
54 Stopwatch::getLastMilliseconds() const {
55 return (getLastDuration().total_milliseconds());
56}
57
58 long
59 Stopwatch::getTotalMilliseconds() const {
60 return (getTotalDuration().total_milliseconds());
61}
62
63 long
64 Stopwatch::getLastMicroseconds() const {
65 return (getLastDuration().total_microseconds());
66}
67
68 long
69 Stopwatch::getTotalMicroseconds() const {
70 return (getTotalDuration().total_microseconds());
71}
72
73std::string
74 Stopwatch::logFormatLastDuration() const {
75 return (StopwatchImpl::logFormat(getLastDuration()));
76}
77
78std::string
79 Stopwatch::logFormatTotalDuration() const {
80 return (StopwatchImpl::logFormat(getTotalDuration()));
81}
82
83} // end of isc::util
84} // end of isc
isc::util::StopwatchImpl
Stopwatch class implementation.
Definition stopwatch_impl.h:28
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::Stopwatch::getLastMilliseconds
long getLastMilliseconds() const
Retrieves the last measured duration in milliseconds.
Definition stopwatch.cc:54
isc::util::Stopwatch::getLastMicroseconds
long getLastMicroseconds() const
Retrieves the last measured duration in microseconds.
Definition stopwatch.cc:64
isc::util::Stopwatch::getTotalMilliseconds
long getTotalMilliseconds() const
Retrieves the total measured duration in milliseconds.
Definition stopwatch.cc:59
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:34
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:69
isc::util::Stopwatch::getLastDuration
boost::posix_time::time_duration getLastDuration() const
Retrieves last measured duration.
Definition stopwatch.cc:44
isc::util::Stopwatch::start
void start()
Starts the stopwatch.
Definition stopwatch.cc:29
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:79
isc::util::Stopwatch::reset
void reset()
Resets the stopwatch.
Definition stopwatch.cc:39
isc::util::Stopwatch::logFormatLastDuration
std::string logFormatLastDuration() const
Returns the last measured duration in the format directly usable in log messages.
Definition stopwatch.cc:74
isc::util::Stopwatch::getTotalDuration
boost::posix_time::time_duration getTotalDuration() const
Retrieves total measured duration.
Definition stopwatch.cc:49
isc::util
Definition time_utils.cc:43
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
stopwatch.h
stopwatch_impl.h