SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AverageTiming.h
Go to the documentation of this file.
1 /**
2  * \file AverageTiming.h
3  * \date March 2018
4  * \authors Michael Goettlicher, Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef AVERAGE_TIMING
11 #define AVERAGE_TIMING
12 
13 #include <string>
14 #include <map>
15 
16 #include <HighResTimer.h>
17 #include <Averaged.h>
18 #include <sstream>
19 #include <utility>
20 
21 namespace Utils
22 {
23 //! concatenation of average value and timer
24 /*!
25 Define a hierarchy by posV and posH which is used in ui to arrange the measurements.
26 The first found content with posV==0 is used as reference measurement for the percental value.
27 */
29 {
30  AverageTimingBlock(int averageNumValues, std::string name, int posV, int posH)
31  : val(averageNumValues, 0.0f),
32  name(std::move(name)),
33  posV(posV),
34  posH(posH)
35  {
36  }
38  std::string name;
40  int posV = 0;
41  int posH = 0;
42  int nCalls = 0;
43  bool isStarted = false;
44 };
45 
46 //-----------------------------------------------------------------------------
47 //! Singleton timing class for average measurement of different timing blocks in loops
48 /*!
49 Call start("name") to define a new timing block and start timing or start timing
50 of an existing block. Call stop("name") to finish measurement for this block.
51 Define a hierarchy by posV and posH which is used in ui to arrange the measurements.
52 The first found content with posV==0 is used as reference measurement for the percental value.
53 */
54 class AverageTiming : public std::map<std::string, AverageTimingBlock*>
55 {
56 public:
57  AverageTiming();
59 
60  //! start timer for a new or existing block
61  static void start(const std::string& name);
62  //! stop timer for a running block with name
63  static void stop(const std::string& name);
64  //! get time for block with name
65  static float getTime(const std::string& name);
66  //! get time for multiple blocks with given names
67  static float getTime(const std::vector<std::string>& names);
68  //! get timings formatted via string
69  static void getTimingMessage(char* m);
70 
71  //! singleton
73  {
74  static AverageTiming timing;
75  return timing;
76  }
77 
78 private:
79  //! do start timer for a new or existing block
80  void doStart(const std::string& name);
81  //! do stop timer for a running block with name
82  void doStop(const std::string& name);
83  //! do get time for block with name
84  float doGetTime(const std::string& name);
85  //! do get time for multiple blocks with given names
86  float doGetTime(const std::vector<std::string>& names) const;
87  //! do get timings formatted via string
88  void doGetTimingMessage(char* m);
89 
90  // average numValues
91  int _averageNumValues = 200;
92  int _currentPosV = 0;
93  int _currentPosH = 0;
94 };
95 
96 #define AVERAGE_TIMING_START(name) Utils::AverageTiming::start(name)
97 #define AVERAGE_TIMING_STOP(name) Utils::AverageTiming::stop(name)
98 //#define AVERAGE_TIMING_START
99 //#define AVERAGE_TIMING_STOP
100 //-----------------------------------------------------------------------------
101 };
102 #endif // AVERAGE_TIMING
High Resolution Timer class using C++11.
Definition: HighResTimer.h:31
Singleton timing class for average measurement of different timing blocks in loops.
Definition: AverageTiming.h:55
static float getTime(const std::string &name)
get time for block with name
void doStart(const std::string &name)
do start timer for a new or existing block
static void stop(const std::string &name)
stop timer for a running block with name
void doGetTimingMessage(char *m)
do get timings formatted via string
static AverageTiming & instance()
singleton
Definition: AverageTiming.h:72
float doGetTime(const std::string &name)
do get time for block with name
void doStop(const std::string &name)
do stop timer for a running block with name
static void getTimingMessage(char *m)
get timings formatted via string
static void start(const std::string &name)
start timer for a new or existing block
Utils provides utilities for string & file handling, logging and math functions.
Definition: Averaged.h:22
concatenation of average value and timer
Definition: AverageTiming.h:29
AverageTimingBlock(int averageNumValues, std::string name, int posV, int posH)
Definition: AverageTiming.h:30