VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
performanceMonitor.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2015 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
9 #include "vrfutil/averager.h"
10 #include <vlutil/vlPerformanceStats.h>
11 
12 #include <map>
13 
15 {
16 public:
18  typedef std::map<int, DtAverager> SectionTimes;
19 
20 public:
22 
23  static int AddProfileContextString(int context, const char* str)
24  {
25  if (!theProfileContextStrings)
26  {
27  theProfileContextStrings = new std::map<int, std::string>();
28  }
29 
30  (*theProfileContextStrings)[context] = str;
31  return context;
32  }
33 
34  static std::string ProfileContextString(int context)
35  {
36  std::map<int, std::string>::const_iterator iter = (*theProfileContextStrings).find(context);
37 
38  if (iter != (*theProfileContextStrings).end())
39  {
40  return iter->second;
41  }
42 
43  return "";
44  }
45 
48  virtual void pause();
49  virtual void resume();
50 
52  virtual bool isPaused() const;
53 
58  virtual void addSample(double frameTime, int section = -1);
59 
61  virtual void adjustSample(int section, double frameTime);
62 
63  static DtPerformanceMonitor* Instance();
64 
66  static DtPerformanceMonitor* SetInstance(DtPerformanceMonitor*);
67 
68  virtual double meanFrameRate(int section = -1);
69 
70  virtual double medianFrameRate(int section = -1);
71 
72  virtual double standardDeviationFrameRate(int section = -1);
73 
74  virtual double minimumFrameRate(int section = -1);
75 
76  virtual double maximumFrameRate(int section = -1);
77 
80  virtual double lastSample(int section = -1);
81 
83  virtual void reset();
84 
86  virtual void setNumberOfFramesToAverage(unsigned int numFramesToAverage);
87  virtual unsigned int numberOfFramesToAverage();
88 
90  virtual int numSections() const;
91 
93  virtual int section(int index) const;
94 
96  virtual std::vector<int> sections() const;
97 
98  const SectionTimes& sectionTimes() const
99  {
100  return mySectionTimes;
101  }
102 
103  double currentFrameRate() const
104  {
105  return myCurrentFrameRate;
106  }
107 
108 protected:
109  static std::map<int, std::string>* theProfileContextStrings;
113 
115  unsigned int myMaxPopulationSize;
116 };
117 
120 #define PROFILE_CONTEXT_STRING(Context, Description) const int the##Context = DtPerformanceMonitor::AddProfileContextString(Context, Description);
121 
122 const int SIMULATION_FRAME_RATE = -1;
123 PROFILE_CONTEXT_STRING(SIMULATION_FRAME_RATE, "Simulation Frame Rate")
124 
125 const int SIMULATION_FRAME = 1;
126 PROFILE_CONTEXT_STRING(SIMULATION_FRAME, "Simulation")
127 
128 const int BEGIN_FRAME = 2;
129 PROFILE_CONTEXT_STRING(BEGIN_FRAME, "Begin")
130 
131 const int ADVANCE_FRAME = 3;
132 PROFILE_CONTEXT_STRING(ADVANCE_FRAME, "Advance")
133 
134 const int OBJECT_TICK = 4;
135 PROFILE_CONTEXT_STRING(OBJECT_TICK, "Object Tick")
136 
137 const int APPLICATION_TICK = 5;
138 PROFILE_CONTEXT_STRING(APPLICATION_TICK, "Application Tick")
139 
140 const int NETWORK_TICK = 6;
141 PROFILE_CONTEXT_STRING(NETWORK_TICK, "Network Tick")
142 
146 {
147 public:
149  : myContext(context)
150  {
151  start();
152  }
153 
155  {
156  stop();
157  }
158 
159  void start()
160  {
161  myPerformanceMarker.start();
162  }
163 
166  void stop()
167  {
168  myPerformanceMarker.stop();
169  DtPerformanceMonitor::Instance()->addSample(myPerformanceMarker.duration(), myContext);
170  }
171 
172 protected:
175 };
176 
177 #define DtVRF_PERFORMANCE_PROFILE(Context) DtPerformanceMonitorMarker frameRate##Context(Context);
static std::string ProfileContextString(int context)
Definition: performanceMonitor.h:34
const int OBJECT_TICK
Definition: performanceMonitor.h:134
const SectionTimes & sectionTimes() const
Definition: performanceMonitor.h:98
void stop()
Stop will be called from the destructor and will record the sample time in the global frame frame mon...
Definition: performanceMonitor.h:166
Definition: performanceMonitor.h:14
const int SIMULATION_FRAME_RATE
Definition: performanceMonitor.h:122
static DtPerformanceMonitor * thePerformanceMonitor
Definition: performanceMonitor.h:114
static DtPerformanceMonitor * Instance()
double myCurrentFrameRate
Definition: performanceMonitor.h:112
const int APPLICATION_TICK
Definition: performanceMonitor.h:137
std::map< int, DtAverager > SectionTimes
Given an identifier to identify a section of code tha will measure simulation time based on that sect...
Definition: performanceMonitor.h:18
static int AddProfileContextString(int context, const char *str)
Definition: performanceMonitor.h:23
int myContext
Definition: performanceMonitor.h:174
unsigned int myMaxPopulationSize
Definition: performanceMonitor.h:115
const int BEGIN_FRAME
Definition: performanceMonitor.h:128
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
The frame rate profile marker will add samples based no how long this marker is in scope or the stop ...
Definition: performanceMonitor.h:145
const int SIMULATION_FRAME
Definition: performanceMonitor.h:125
double currentFrameRate() const
Definition: performanceMonitor.h:103
DtTimedSection myPerformanceMarker
Definition: performanceMonitor.h:173
const int ADVANCE_FRAME
Definition: performanceMonitor.h:131
#define DT_DLL_vrfutil
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfutilDefines.h:34
DtPerformanceMonitorMarker(int context)
Definition: performanceMonitor.h:148
virtual ~DtPerformanceMonitorMarker()
Definition: performanceMonitor.h:154
bool myIsPaused
Definition: performanceMonitor.h:111
void start()
Definition: performanceMonitor.h:159
const int NETWORK_TICK
Definition: performanceMonitor.h:140
static std::map< int, std::string > * theProfileContextStrings
Definition: performanceMonitor.h:109
SectionTimes mySectionTimes
Definition: performanceMonitor.h:110
virtual void addSample(double frameTime, int section=-1)
If the frameTime is &gt; 0, it calculates the current frame rate as 1/frameTime. Then it adds this frame...
#define PROFILE_CONTEXT_STRING(Context, Description)
For VRF specific timers, these are the current section timers and the strings that describe that the ...
Definition: performanceMonitor.h:120

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)