Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Profiler.h
Go to the documentation of this file.
1 /*
2 
3 License
4 
5 Menge
6 Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
7 All rights reserved.
8 
9 Permission to use, copy, modify, and distribute this software and its documentation
10 for educational, research, and non-profit purposes, without fee, and without a
11 written agreement is hereby granted, provided that the above copyright notice,
12 this paragraph, and the following four paragraphs appear in all copies.
13 
14 This software program and documentation are copyrighted by the University of North
15 Carolina at Chapel Hill. The software program and documentation are supplied "as is,"
16 without any accompanying services from the University of North Carolina at Chapel
17 Hill or the authors. The University of North Carolina at Chapel Hill and the
18 authors do not warrant that the operation of the program will be uninterrupted
19 or error-free. The end-user understands that the program was developed for research
20 purposes and is advised not to rely exclusively on the program for any reason.
21 
22 IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS
23 BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
24 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
25 DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
26 AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
29 DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY
31 OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
32 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS
33 TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
34 
35 Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
36 
37 */
38 
44 #ifndef __PROFILER_H__
45 #define __PROFILER_H__
46 
47 #define TIME_CROWD
48 #include <string>
49 
50 #ifdef _WIN32
51 #include "windows.h"
52 #else // _WIN32
53 #include <ctime>
54 #include "include/macros.h"
55 #endif // _WIN32
56 
57 namespace Menge {
58 
59  namespace Vis {
63  class Timer {
64  public:
68  Timer();
69 
73  void start();
74 
82  float elapsed( float scale );
83 
84  protected:
85  #ifdef _WIN32
86 
89  static __int64 FREQ;
90 
94  __int64 _start;
95 
96  #else // _WIN32
97 
100  struct timespec _start;
101 
102  #endif // _WIN32
103  };
104 
106 
112  class LapTimer: public Timer {
113  public:
117  LapTimer();
118 
127  float lap( float scale=1.f );
128 
136  float average( float scale=1.f );
137 
141  inline int laps() const { return _lapCount; }
142 
143  protected:
144  #ifdef _WIN32
145 
148  __int64 _total;
149  #else // _WIN32
150 
153  double _total;
154  #endif // _WIN32
155 
160  };
161 
163 
168  class SampleTimer: public Timer {
169  public:
176  SampleTimer( int sampleCount );
177 
185  float lap( float scale=1.f );
186 
187  protected:
192 
197 
198  #ifdef _WIN32
199 
202  __int64 _total;
203  #else // _WIN32
204 
207  float _total;
208  #endif // _WIN32
209 
213  float _cached;
214  };
215 
216  } // namespace Vis
217 
218  #ifdef TIME_CROWD
219 
227  size_t addTimer( const std::string & displayString );
228 
234  void startTimer( size_t index );
235 
241  void stopTimer( size_t index );
242 
248  void lapTimer( size_t index );
249 
256  float averageTime( size_t index );
257 
262  void printAverages();
263 
271  void setUnits( float scale, const std::string & unitString );
272 
273  #else // not defined TIME_CROWD
274 
275  #define addTimer( displayString ) (0)
276  #define startTimer( index )
277  #define stopTimer( index )
278  #define lapTimer( index )
279  #define averageTime( index )
280  #define printAverages()
281  #define setUnits( scale, unitString )
282 
283  #endif // TIME_CROWD
284 
285 } // namespace Menge
286 
287 #endif // __PROFILER_H__
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Basic timer.
Definition: Profiler.h:63
int _lapCount
The total number of calls to lap()
Definition: Profiler.h:159
void printAverages()
Prints the average times for all timers, displayed with the accompanying messages and set units...
Definition: Profiler.cpp:423
Timer()
Default constructor.
Definition: Profiler.cpp:85
Lap timer. A timer which supports "laps" i.e., single calls which measure from the last "tick" to thi...
Definition: Profiler.h:112
The namespace containing visualization functionality for the pedestrian simulation.
Definition: GLViewer.h:64
SampleTimer(int sampleCount)
Constructor.
Definition: Profiler.cpp:160
int _currSample
The curren total number of calls to lap.
Definition: Profiler.h:196
void lapTimer(size_t index)
Lap the ith timer.
Definition: Profiler.cpp:410
void startTimer(size_t index)
Starts the timer with the given identifier.
Definition: Profiler.cpp:398
float elapsed(float scale)
Reports the time elapsed between this call and the last start.
Definition: Profiler.cpp:96
float average(float scale=1.f)
Reports the average lap time across all recorded laps.
Definition: Profiler.cpp:148
void start()
Starts the timer running.
Definition: Profiler.cpp:90
int laps() const
Reports the number of calls to laps.
Definition: Profiler.h:141
A timer which uses a cache of values to only update its values every N calls to lap/elapsed. Useful for displaying frame rate.
Definition: Profiler.h:168
float _cached
The most recently defined elapsed lap time.
Definition: Profiler.h:213
float _total
The current accrual of time for the current cache (in seconds).
Definition: Profiler.h:207
void setUnits(float scale, const std::string &unitString)
Sets the internal units of the profiler.
Definition: Profiler.cpp:435
void stopTimer(size_t index)
Stops the timer with the given identifier.
Definition: Profiler.cpp:404
LapTimer()
Default constructor.
Definition: Profiler.cpp:108
double _total
The total accrued time of timed intervals (in seconds).
Definition: Profiler.h:153
float lap(float scale=1.f)
Reports the time elapsed from the previous call to lap() or start() to this call. The clock is still ...
Definition: Profiler.cpp:137
float lap(float scale=1.f)
Reports the average elapsed time of the last N calls to lap.
Definition: Profiler.cpp:183
struct timespec _start
The time (in clock cycles) at which the timer was started.
Definition: Profiler.h:100
size_t addTimer(const std::string &displayString)
Creates a lap timer which uses the given label for display.
Definition: Profiler.cpp:392
float averageTime(size_t index)
Reports the average time of the ith timer.
Definition: Profiler.cpp:416
int _totalSamples
The number of samples to compute the average over.
Definition: Profiler.h:191