Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timer.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_CORE_TIMER_H_)
21 #define __MITSUBA_CORE_TIMER_H_
22 
23 #include <mitsuba/mitsuba.h>
24 
26 
27 /** \brief Platform independent milli/micro/nanosecond timer
28  * \ingroup libcore
29  *
30  * This class implements a simple cross-platform timer with nanosecond resolution.
31  * It operates similarly to a good stop watch: it can be started and stopped and
32  * records both the time since the last \ref start() invocation, and the total time
33  * collected in separate intervals.
34  *
35  * \author Edgar Velazquez-Armendariz
36  */
37 class MTS_EXPORT_CORE Timer : public Object {
38 public:
39  /**
40  * \brief Create a new timer and start it unless the optional
41  * \c start argument is set to \c false.
42  */
43  Timer(bool start = true);
44 
45  /// Start the timer
46  void start();
47 
48  /**
49  * \brief Reset the timer, including the total elapsed time across
50  * all intervals (and restart it by default)
51  */
52  void reset(bool restart = true);
53 
54  /// Stop the timer and return the total elapsed time across all intervals in seconds
55  Float stop();
56 
57  /// Return the number of nanoseconds that the timer has ticked so far (in total)
58  uint64_t getNanoseconds() const;
59 
60  /// Return the number of microseconds that the timer has ticked so far (in total)
61  unsigned int getMicroseconds() const;
62 
63  /// Return the number of milliseconds that the timer has ticked so far (in total)
64  unsigned int getMilliseconds() const;
65 
66  /// Return the number of seconds that the timer has ticked so far (in total)
67  Float getSeconds() const;
68 
69  /// Return the number of nanoseconds that have elapsed since the \ref start() invocation
70  uint64_t getNanosecondsSinceStart() const;
71 
72  /// Return the number of microseconds that have elapsed since the last \ref start() invocation
73  unsigned int getMicrosecondsSinceStart() const;
74 
75  /// Return the number of milliseconds that have elapsed since the last \ref start() invocation
76  unsigned int getMillisecondsSinceStart() const;
77 
78  /// Return the number of seconds that have elapsed since the last \ref start() invocation
79  Float getSecondsSinceStart() const;
80 
81  /**
82  * \brief "Lap"-style interface
83  *
84  * This function is the atomic equivalent to stopping the
85  * timer, recording the time passed since it was started,
86  * and restarting it. The resulting time value in seconds
87  * is returned.
88  */
89  Float lap();
90 
91  /// Return a string representation
92  std::string toString() const;
93 
95 protected:
96  /// Virtual destructor
97  virtual ~Timer();
98 
99  /// Return the time in nanoseconds since the last \ref start() invocation
100  double timeSinceStart() const;
101 private:
102  /// Time since the last call to start() in nanoseconds
103  double m_startTime;
104 
105  /// Total time the timer has been active in nanoseconds
106  double m_elapsed;
107 
108  /// Is the timer currently active?
109  bool m_active;
110 };
111 
113 
114 #endif /* __MITSUBA_CORE_TIMER_H_ */
#define MTS_EXPORT_CORE
Definition: getopt.h:29
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Platform independent milli/micro/nanosecond timerThis class implements a simple cross-platform timer ...
Definition: timer.h:37
Parent of all Mitsuba classes.
Definition: object.h:38
virtual std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
#define MTS_NAMESPACE_END
Definition: platform.h:138