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