VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtProfiler.h
Go to the documentation of this file.
1 /*********************************************************************************
2 ** Copyright (c) 2026 MAK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************************/
5 
10 
11 #pragma once
12 
13 #include <vrvUtil/vrvUtil.h>
15 
16 // Single location to define profiling colors
17 #define DTPROFILE_TRACYCOLOR_BALLISTICS 0x00bfff
18 #define DTPROFILE_TRACYCOLOR_SILVERLINING 0x0b8bf8
19 #define DTPROFILE_TRACYCOLOR_TRITON 0x123f7b
20 #define DTPROFILE_TRACYCOLOR_SPEEDTREE 0x0f502d
21 #define DTPROFILE_TRACYCOLOR_INDIRECT 0x3333cc
22 #define DTPROFILE_TRACYCOLOR_LIGHTING 0xffaa00
23 #define DTPROFILE_TRACYCOLOR_POSTEFFECT 0xffb31a
24 #define DTPROFILE_TRACYCOLOR_VIRTUALREALITY 0xa3297a
25 #define DTPROFILE_TRACYCOLOR_GLCONTEXT 0xe68a00
26 #define DTPROFILE_TRACYCOLOR_RENDERER 0x0b9900
27 
28 
29 
30 
31 //easy to use macro to profile a section
32 // should pass a "const char*" as name because the pointer is getting
33 // used to do the string compare (to be fast)
34 // if a std::string is passed instead it will cause a crashed when
35 // loading/unloading terrain with the performance/stats displayed
36 
37 #define TRACY_ENABLE
38 //#define OPTICK_ENABLE
39 //#define NO_PROFILER
40 
41 #ifndef TRACY_ENABLE
42 #ifndef OPTICK_ENABLE
43 #define NO_PROFILER
44 #endif
45 #endif
46 //optick
48 #ifdef OPTICK_ENABLE
49 #include <optick/optick.h>
50 //#pragma comment(lib, "OptickCore.lib")
51 
52 // win32 creates macros that work with our stats and tracy
53 #define DtPROFILE(name) OPTICK_EVENT(name); DtPROFILE_X(name, __LINE__);
54 #define DtPROFILEC(name, color) OPTICK_EVENT(name); DtPROFILE_X(name, __LINE__);
55 #define DtPROFILE_SECTION(name) {OPTICK_EVENT(name); makVrv::DtProfileSample _profileSample(name);
56 
57 #define DtProfilerFrameMark OPTICK_FRAME("MainThread")
58 #define DtProfilerThreadName(name) OPTICK_THREAD(name);
59 #define DtProfilerMessage(str, stringLen)
60 
61 #define DtProfilerPlot(x,y)
62 #define DtProfilerText(text)
63 
64 #endif
65 
67 //tracy
68 #ifdef TRACY_ENABLE
69 
70 #include <tracy/MAKTracyDefines.h>
71 #include <tracy/Tracy.hpp>
72 #include <client/TracyProfiler.hpp>
73 
74 // Eventually we should switch over to 1 define with different number of args
75 //#define GET_MACRO(_0, _1, _2, NAME, ...) NAME
76 //#define PROFILE(...) GET_MACRO(_0, ##__VA_ARGS__, DtPROFILEC, DtPROFILE, DtPROFILEzone)(__VA_ARGS__)
77 
78 #define DtPROFILEzone ZoneNamedS(___tracy_scoped_zone, makVrv::DtProfileManager::tracyCallstackDepth(), makVrv::DtProfileManager::collectTracyStats());
79 #define DtPROFILE(name) ZoneNamedNS(___tracy_scoped_zone, name, makVrv::DtProfileManager::tracyCallstackDepth(), makVrv::DtProfileManager::collectTracyStats()); DtPROFILE_X(name, __LINE__);
80 #define DtPROFILEC(name, color) ZoneNamedNCS(___tracy_scoped_zone, name, color, makVrv::DtProfileManager::tracyCallstackDepth(), makVrv::DtProfileManager::collectTracyStats()); DtPROFILE_X(name, __LINE__);
81 #define DtPROFILE_SECTION(name) {ZoneNamedNS(___tracy_scoped_zone, name, makVrv::DtProfileManager::tracyCallstackDepth(), makVrv::DtProfileManager::collectTracyStats()); makVrv::DtProfileSample _profileSample(name);
82 
83 #define DtProfilerFrameMark if(makVrv::DtProfileManager::tracyProfilerInitialized()) { FrameMark; }
84 #define DtProfilerPlot(x,y) if (makVrv::DtProfileManager::collectTracyStats()) TracyPlot(x,y)
85 #define DtProfilerThreadName(name) tracy::SetThreadName(name );
86 #define DtProfilerMessage(str, stringLen) TracyMessage(str, stringLen)
87 #define DtProfilerText(text) _zoneSetText(___tracy_scoped_zone, text)
88 
89 inline void _zoneSetText(tracy::ScopedZone& zone, const char* text) {
90  zone.Text(text, strlen(text));
91 }
92 inline void _zoneSetText(tracy::ScopedZone& zone, const std::string& text) {
93  zone.Text(text.c_str(), text.size());
94 }
95 
96 #define DtProfilerName(text) _zoneSetName(___tracy_scoped_zone, text)
97 
98 inline void _zoneSetName(tracy::ScopedZone& zone, const char* text)
99 {
100  zone.Name(text, strlen(text));
101 }
102 inline void _zoneSetName(tracy::ScopedZone& zone, const std::string& text)
103 {
104  zone.Name(text.c_str(), text.size());
105 }
106 #endif
107 
109 
110 #ifdef NO_PROFILER
111 #define DtPROFILE(name) DtPROFILE_X(name, __LINE__);
112 #define DtPROFILEC(name, color) DtPROFILE_X(name, __LINE__);
113 #define DtPROFILE_SECTION(name) {makVrv::DtProfileSample _profileSample(name);
114 #define DtPROFILEzone DtPROFILE_X(__func__, __LINE__);
115 
116 #define DtProfilerFrameMark
117 #define DtProfilerThreadName(name)
118 #define DtProfilerPlot(x,y)
119 #define DtProfilerMessage(str, stringLen)
120 #define DtProfilerText(text)
121 #endif
122 
123 #define DtPROFILE_RESTRICTED(name, target) makVrv::DtProfileTarget<target> _profileTarget##line(name);
124 
125 #define DtPROFILE_X(name, line) DtPROFILE_ACTUAL(name, line)
126 #define DtPROFILE_ACTUAL(name, line) makVrv::DtProfileSample _profileSample##line(name);
127 //#define DtPROFILE_FUNCTION(name, func) {makVrv::DtProfileSample _profileSample(name); (func);}
128 #define DtPROFILE_SECTION_END }
129 
130 #define DtPERFORMANCE_STAT(name) DtPERFORMANCE_STAT_X(name, __LINE__)
131 #define DtPERFORMANCE_STAT_X(name, line) DtPERFORMANCE_STAT_ACTUAL(name, line)
132 #define DtPERFORMANCE_STAT_ACTUAL(name, line) makVrv::DtPerfomanceStatSample _performanceStatSample##line(name);
133 
134 
135 // These constants configure DtPROFILE_RESTRICTED
136 //
137 // Define them to boost::true_type to enable profiling of those sections
138 const bool Profile_DtSceneObjectUpdater = false;
140 const bool Profile_DtOsgCullVisitor = false;
141 
142 namespace makVrv
143 {
144  void DT_DLL_VRVUTIL SetThreadName(const char* name);
145 
151  {
152  public:
154  DtProfileSample(const char* name)
155  {
157  }
158 
161  {
163  }
164  };
165 
170  template <bool Enabled>
172  {
173  DtProfileTarget(const char* name) {}
174  };
175 
176  template <>
177  struct DtProfileTarget<true>
178  {
180  DtProfileTarget(const char* name)
181  {
183  }
184 
187  {
189  }
190  };
191 
197  {
198  public:
200  DtPerfomanceStatSample(const char* name)
201  {
203  }
204 
207  {
209  }
210  };
211 }
212 
const bool Profile_DtOsgCullVisitor
Definition: DtProfiler.h:140
#define DT_DLL_VRVUTIL
Definition: vrvUtil.h:34
DtProfileTarget is used to start/stop a profiled section It is preferable to use the macro at the top...
Definition: DtProfiler.h:171
DtProfileSampleClass is used to start/stop a profiled section It is preferable to use the macro at th...
Definition: DtProfiler.h:196
void _zoneSetName(tracy::ScopedZone &zone, const char *text)
Definition: DtProfiler.h:98
static void startProfile(const char *name)
begin a profile. This function is thread safe
DtProfileSample(const char *name)
CTOR starts profile section.
Definition: DtProfiler.h:154
const bool Profile_DtSurfaceClampingUpdater
Definition: DtProfiler.h:139
~DtPerfomanceStatSample()
DTOR stops profile section.
Definition: DtProfiler.h:206
DtProfileTarget(const char *name)
CTOR starts profile section.
Definition: DtProfiler.h:180
DtProfileSampleClass is used to start/stop a profiled section It is preferable to use the macro at th...
Definition: DtProfiler.h:150
void _zoneSetText(tracy::ScopedZone &zone, const char *text)
Definition: DtProfiler.h:89
Contains DLL export macros.
const bool Profile_DtSceneObjectUpdater
Definition: DtProfiler.h:138
void DT_DLL_VRVUTIL SetThreadName(const char *name)
~DtProfileTarget()
DTOR stops profile section.
Definition: DtProfiler.h:186
static void stopPerformanceStat()
begin stop a profile. This function is thread safe
DtProfileTarget(const char *name)
Definition: DtProfiler.h:173
static void startPerformanceStat(const char *name)
begin a performance stat. This function is thread safe
DtPerfomanceStatSample(const char *name)
CTOR starts profile section.
Definition: DtProfiler.h:200
~DtProfileSample()
DTOR stops profile section.
Definition: DtProfiler.h:160
static void stopProfile()
begin stop a profile. This function is thread safe

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)