VR-Forces 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  static void DeleteInstance();
65 
67  static DtPerformanceMonitor* SetInstance(DtPerformanceMonitor*);
68 
69  virtual double meanFrameRate(int section = -1);
70 
71  virtual double medianFrameRate(int section = -1);
72 
73  virtual double standardDeviationFrameRate(int section = -1);
74 
75  virtual double minimumFrameRate(int section = -1);
76 
77  virtual double maximumFrameRate(int section = -1);
78 
81  virtual double lastSample(int section = -1);
82 
84  virtual void reset();
85 
87  virtual void setNumberOfFramesToAverage(unsigned int numFramesToAverage);
88  virtual unsigned int numberOfFramesToAverage();
89 
91  virtual int numSections() const;
92 
94  virtual int section(int index) const;
95 
97  virtual std::vector<int> sections() const;
98 
99  const SectionTimes& sectionTimes() const
100  {
101  return mySectionTimes;
102  }
103 
104  double currentFrameRate() const
105  {
106  return myCurrentFrameRate;
107  }
108 
109 protected:
110  static std::map<int, std::string>* theProfileContextStrings;
114 
116  unsigned int myMaxPopulationSize;
117 };
118 
121 #define PROFILE_CONTEXT_STRING(Context, Description) const int the##Context = DtPerformanceMonitor::AddProfileContextString(Context, Description);
122 
123 const int SIMULATION_FRAME_RATE = -1;
124 PROFILE_CONTEXT_STRING(SIMULATION_FRAME_RATE, "Simulation Frame Rate")
125 
126 const int SIMULATION_FRAME = 1;
128 PROFILE_CONTEXT_STRING(SIMULATION_FRAME, "Simulation")
129 
131 const int BEGIN_FRAME = 2;
132 PROFILE_CONTEXT_STRING(BEGIN_FRAME, "Begin")
133 
136 const int ADVANCE_FRAME = 3;
137 PROFILE_CONTEXT_STRING(ADVANCE_FRAME, "Advance")
138 
140 const int OBJECT_TICK = 4;
141 PROFILE_CONTEXT_STRING(OBJECT_TICK, "Object Tick")
142 
144 const int APPLICATION_TICK = 5;
145 PROFILE_CONTEXT_STRING(APPLICATION_TICK, "Application Tick")
146 
149 const int NETWORK_TICK = 6;
150 PROFILE_CONTEXT_STRING(NETWORK_TICK, "Network Tick")
151 
155 {
156 public:
158  : myContext(context)
159  {
160  start();
161  }
162 
164  {
165  stop();
166  }
167 
168  void start()
169  {
170  myPerformanceMarker.start();
171  }
172 
175  void stop()
176  {
177  myPerformanceMarker.stop();
178  DtPerformanceMonitor::Instance()->addSample(myPerformanceMarker.duration(), myContext);
179  }
180 
181 protected:
182  DtTimedSection myPerformanceMarker;
184 };
185 
186 #define DtVRF_PERFORMANCE_PROFILE(Context) DtPerformanceMonitorMarker frameRate##Context(Context);
static std::string ProfileContextString(int context)
Definition: performanceMonitor.h:34
const int OBJECT_TICK
The time it takes to tick the local object manager.
Definition: performanceMonitor.h:140
const SectionTimes & sectionTimes() const
Definition: performanceMonitor.h:99
void stop()
Stop will be called from the destructor and will record the sample time in the global frame frame mon...
Definition: performanceMonitor.h:175
Definition: performanceMonitor.h:14
const int SIMULATION_FRAME_RATE
Definition: performanceMonitor.h:123
static DtPerformanceMonitor * thePerformanceMonitor
Definition: performanceMonitor.h:115
static DtPerformanceMonitor * Instance()
double myCurrentFrameRate
Definition: performanceMonitor.h:113
const int APPLICATION_TICK
The time it takes to tick the cgf and to sleep until the next cgf tick. This is recorded in vrfApp...
Definition: performanceMonitor.h:144
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:183
unsigned int myMaxPopulationSize
Definition: performanceMonitor.h:116
const int BEGIN_FRAME
The time it takes to call beginFrame step.
Definition: performanceMonitor.h:131
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:154
const int SIMULATION_FRAME
The time it takes to tick the DtCgf (running the DtCgf tick() method)
Definition: performanceMonitor.h:127
double currentFrameRate() const
Definition: performanceMonitor.h:104
DtTimedSection myPerformanceMarker
Definition: performanceMonitor.h:182
const int ADVANCE_FRAME
The time it takes to advance the frame of the DtCgf in the advanceFrame section minus the time it tak...
Definition: performanceMonitor.h:136
#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:157
virtual ~DtPerformanceMonitorMarker()
Definition: performanceMonitor.h:163
bool myIsPaused
Definition: performanceMonitor.h:112
void start()
Definition: performanceMonitor.h:168
const int NETWORK_TICK
The time it takes to advance the frame of the network thread, which includes publishing of local obje...
Definition: performanceMonitor.h:149
static std::map< int, std::string > * theProfileContextStrings
Definition: performanceMonitor.h:110
SectionTimes mySectionTimes
Definition: performanceMonitor.h:111
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:121

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)