Kea 2.6.0
stopwatch.h
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#ifndef STOPWATCH_H
8#define STOPWATCH_H
9
10#include <boost/noncopyable.hpp>
11#include <boost/date_time/posix_time/posix_time.hpp>
12
13namespace isc {
14namespace util {
15
17class StopwatchImpl;
18
35class Stopwatch : boost::noncopyable {
36public:
37
45 Stopwatch(const bool autostart = true);
46
50 ~Stopwatch();
51
59 void start();
60
71 void stop();
72
78 void reset();
79
86 boost::posix_time::time_duration getLastDuration() const;
87
96 boost::posix_time::time_duration getTotalDuration() const;
97
99 long getLastMilliseconds() const;
100
102 long getTotalMilliseconds() const;
103
105 long getLastMicroseconds() const;
106
108 long getTotalMicroseconds() const;
109
112 std::string logFormatLastDuration() const;
113
116 std::string logFormatTotalDuration() const;
117
118private:
119
121 boost::shared_ptr<StopwatchImpl> impl_;
122
123};
124
125}
126}
127
128#endif // STOPWATCH_H
129
Utility class to measure code execution times.
Definition: stopwatch.h:35
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
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.