Kea  2.1.7-git
stopwatch.h
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 #ifndef STOPWATCH_H
8 #define STOPWATCH_H
9 
10 #include <boost/noncopyable.hpp>
11 #include <boost/date_time/posix_time/posix_time.hpp>
12 
13 namespace isc {
14 namespace util {
15 
17 class StopwatchImpl;
18 
35 class Stopwatch : boost::noncopyable {
36 public:
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 
118 private:
119 
121  StopwatchImpl* impl_;
122 
123 };
124 
125 }
126 }
127 
128 #endif // STOPWATCH_H
129 
void reset()
Resets the stopwatch.
Definition: stopwatch.cc:40
~Stopwatch()
Destructor.
Definition: stopwatch.cc:25
long getTotalMilliseconds() const
Retrieves the total measured duration in milliseconds.
Definition: stopwatch.cc:60
Stopwatch class implementation.
void stop()
Stops the stopwatch.
Definition: stopwatch.cc:35
Utility class to measure code execution times.
Definition: stopwatch.h:35
boost::posix_time::time_duration getTotalDuration() const
Retrieves total measured duration.
Definition: stopwatch.cc:50
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 getLastDuration() const
Retrieves last measured duration.
Definition: stopwatch.cc:45
Defines the logger used by the top-level component of kea-lfc.
std::string logFormatTotalDuration() const
Returns the total measured duration in the format directly usable in the log messages.
Definition: stopwatch.cc:80
Stopwatch(const bool autostart=true)
Constructor.
Definition: stopwatch.cc:17
long getLastMicroseconds() const
Retrieves the last measured duration in microseconds.
Definition: stopwatch.cc:65
long getTotalMicroseconds() const
Retrieves the total measured duration in microseconds.
Definition: stopwatch.cc:70
void start()
Starts the stopwatch.
Definition: stopwatch.cc:30
long getLastMilliseconds() const
Retrieves the last measured duration in milliseconds.
Definition: stopwatch.cc:55