libcommonc++  0.7
StopWatch.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_StopWatch_hxx
24 #define __ccxx_StopWatch_hxx
25 
26 #include <commonc++/Common.h++>
27 
28 namespace ccxx {
29 
39 {
40  public:
41 
43  StopWatch();
44 
46  virtual ~StopWatch();
47 
52  void start();
53 
58  void stop();
59 
64  inline void pause()
65  { stop(); }
66 
71  inline void resume()
72  { start(); }
73 
75  void reset();
76 
81  inline uint64_t elapsedKernelTime() const
82  { return(_kernelElapsed); }
83 
88  inline uint64_t elapsedUserTime() const
89  { return(_userElapsed); }
90 
95  inline uint64_t elapsedRealTime() const
96  { return(_realElapsed); }
97 
99  inline bool isRunning() const
100  { return(_running); }
101 
102  private:
103 
104  time_ms_t _userTime;
105  time_ms_t _kernelTime;
106  time_ms_t _realTime;
107 
108  uint64_t _userElapsed;
109  uint64_t _kernelElapsed;
110  uint64_t _realElapsed;
111 
112  bool _running;
113 
115 };
116 
117 } // namespace ccxx
118 
119 #endif // __ccxx_StopWatch_hxx
uint64_t elapsedRealTime() const
Return the total elapsed real time for this timer (up to the point where the timer was last stopped) ...
Definition: StopWatch.h++:95
uint64_t elapsedUserTime() const
Return the total elapsed user time for this timer (up to the point where the timer was last stopped) ...
Definition: StopWatch.h++:88
void pause()
Pause the timer.
Definition: StopWatch.h++:64
int64_t time_ms_t
A time expressed in milliseconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:98
bool isRunning() const
Determine if this timer is running.
Definition: StopWatch.h++:99
uint64_t elapsedKernelTime() const
Return the total elapsed kernel time for this timer (up to the point where the timer was last stopped...
Definition: StopWatch.h++:81
void resume()
Resume the timer.
Definition: StopWatch.h++:71
#define COMMONCPP_API
Definition: Common.h++:126
#define CCXX_COPY_DECLS(CLASS)
Inlines declarations of a copy constructor and assignment operator for the class CLASS.
Definition: Common.h++:295
A stopwatch-style timer.
Definition: StopWatch.h++:38
Definition: AllocationMap.c++:25