VR-Vantage 3.2 API Documentation
 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) 2024 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_SILVERLINING 0x0b8bf8
18 #define DTPROFILE_TRACYCOLOR_TRITON 0x123f7b
19 #define DTPROFILE_TRACYCOLOR_SPEEDTREE 0x0f502d
20 #define DTPROFILE_TRACYCOLOR_INDIRECT 0x3333cc
21 #define DTPROFILE_TRACYCOLOR_LIGHTING 0xffaa00
22 #define DTPROFILE_TRACYCOLOR_POSTEFFECT 0xffb31a
23 #define DTPROFILE_TRACYCOLOR_VIRTUALREALITY 0xa3297a
24 #define DTPROFILE_TRACYCOLOR_GLCONTEXT 0xe68a00
25 #define DTPROFILE_TRACYCOLOR_RENDERER 0xb990000
26 
27 
28 
29 
30 //easy to use macro to profile a section
31 // should pass a "const char*" as name because the pointer is getting
32 // used to do the string compare (to be fast)
33 // if a std::string is passed instead it will cause a crashed when
34 // loading/unloading terrain with the performance/stats displayed
35 
36 #define TRACY_ENABLE
37 //#define OPTICK_ENABLE
38 //#define NO_PROFILER
39 
40 #ifndef TRACY_ENABLE
41 #ifndef OPTICK_ENABLE
42 #define NO_PROFILER
43 #endif
44 #endif
45 
46 //optick
47 #ifdef OPTICK_ENABLE
48 #include <optick/optick.h>
49 //#pragma comment(lib, "OptickCore.lib")
50 
51 // win32 creates macros that work with our stats and tracy
52 #define DtPROFILE(name) OPTICK_EVENT(name); DtPROFILE_X(name, __LINE__);
53 #define DtPROFILEC(name, color) OPTICK_EVENT(name); DtPROFILE_X(name, __LINE__);
54 #define DtPROFILE_SECTION(name) {OPTICK_EVENT(name); makVrv::DtProfileSample _profileSample(name);
55 
56 #define DtProfilerFrameMark OPTICK_FRAME("MainThread")
57 #define DtProfilerThreadName(name) OPTICK_THREAD(name);
58 #define DtProfilerMessage(str, stringLen)
59 
60 #define DtProfilerPlot(x,y)
61 #define DtProfilerText(text)
62 
63 #endif
64 
66 //tracy
67 #ifdef TRACY_ENABLE
68 
69 #include <tracy/MAKTracyDefines.h>
70 #include <tracy/Tracy.hpp>
71 #include <client/TracyProfiler.hpp>
72 
73 // Eventually we should switch over to 1 define with different number of args
74 //#define GET_MACRO(_0, _1, _2, NAME, ...) NAME
75 //#define PROFILE(...) GET_MACRO(_0, ##__VA_ARGS__, DtPROFILEC, DtPROFILE, DtPROFILEzone)(__VA_ARGS__)
76 
77 #define DtPROFILEzone ZoneNamedS(___tracy_scoped_zone, makVrv::DtProfileManager::tracyCallstackDepth(), makVrv::DtProfileManager::collectTracyStats());
78 #define DtPROFILE(name) ZoneNamedNS(___tracy_scoped_zone, name, makVrv::DtProfileManager::tracyCallstackDepth(), makVrv::DtProfileManager::collectTracyStats()); DtPROFILE_X(name, __LINE__);
79 #define DtPROFILEC(name, color) ZoneNamedNCS(___tracy_scoped_zone, name, color, makVrv::DtProfileManager::tracyCallstackDepth(), makVrv::DtProfileManager::collectTracyStats()); DtPROFILE_X(name, __LINE__);
80 #define DtPROFILE_SECTION(name) {ZoneNamedNS(___tracy_scoped_zone, name, makVrv::DtProfileManager::tracyCallstackDepth(), makVrv::DtProfileManager::collectTracyStats()); makVrv::DtProfileSample _profileSample(name);
81 
82 #define DtProfilerFrameMark if(makVrv::DtProfileManager::tracyProfilerInitialized()) { FrameMark; }
83 #define DtProfilerPlot(x,y) TracyPlot(x,y)
84 #define DtProfilerThreadName(name) tracy::SetThreadName(name );
85 #define DtProfilerMessage(str, stringLen) TracyMessage(str, stringLen)
86 #define DtProfilerText(text) _zoneSetText(___tracy_scoped_zone, text)
87 
88 inline void _zoneSetText(tracy::ScopedZone& zone, const char* text) {
89  zone.Text(text, strlen(text));
90 }
91 inline void _zoneSetText(tracy::ScopedZone& zone, const std::string& text) {
92  zone.Text(text.c_str(), text.size());
93 }
94 
95 #define DtProfilerName(text) _zoneSetName(___tracy_scoped_zone, text)
96 
97 inline void _zoneSetName(tracy::ScopedZone& zone, const char* text)
98 {
99  zone.Name(text, strlen(text));
100 }
101 inline void _zoneSetName(tracy::ScopedZone& zone, const std::string& text)
102 {
103  zone.Name(text.c_str(), text.size());
104 }
105 #endif
106 
108 
109 #ifdef NO_PROFILER
110 #define DtPROFILEzone
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 DtProfilerPlot(x,y)
117 
118 #define DtProfilerFrameMark
119 #define DtProfilerThreadName(name)
120 #define DtProfilerPlot(x,y)
121 #define DtProfilerMessage(str, stringLen)
122 #define DtProfilerText(text)
123 #endif
124 
125 #define DtPROFILE_RESTRICTED(name, target) makVrv::DtProfileTarget<target> _profileTarget##line(name);
126 
127 #define DtPROFILE_X(name, line) DtPROFILE_ACTUAL(name, line)
128 #define DtPROFILE_ACTUAL(name, line) makVrv::DtProfileSample _profileSample##line(name);
129 //#define DtPROFILE_FUNCTION(name, func) {makVrv::DtProfileSample _profileSample(name); (func);}
130 #define DtPROFILE_SECTION_END }
131 
132 #define DtPERFORMANCE_STAT(name) DtPERFORMANCE_STAT_X(name, __LINE__)
133 #define DtPERFORMANCE_STAT_X(name, line) DtPERFORMANCE_STAT_ACTUAL(name, line)
134 #define DtPERFORMANCE_STAT_ACTUAL(name, line) makVrv::DtPerfomanceStatSample _performanceStatSample##line(name);
135 
136 
137 // These constants configure DtPROFILE_RESTRICTED
138 //
139 // Define them to boost::true_type to enable profiling of those sections
140 const bool Profile_DtSceneObjectUpdater = false;
142 const bool Profile_DtOsgCullVisitor = false;
143 
144 namespace makVrv
145 {
146  void DT_DLL_VRVUTIL SetThreadName(const char* name);
147 
153  {
154  public:
156  DtProfileSample(const char* name)
157  {
159  }
160 
163  {
165  }
166  };
167 
172  template <bool Enabled>
174  {
175  DtProfileTarget(const char* name) {}
176  };
177 
178  template <>
179  struct DtProfileTarget<true>
180  {
182  DtProfileTarget(const char* name)
183  {
185  }
186 
189  {
191  }
192  };
193 
199  {
200  public:
202  DtPerfomanceStatSample(const char* name)
203  {
205  }
206 
209  {
211  }
212  };
213 }
214 


Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)