VR-Vantage
Loading...
Searching...
No Matches
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
47//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
89inline void _zoneSetText(tracy::ScopedZone& zone, const char* text) {
90 zone.Text(text, strlen(text));
91}
92inline 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
98inline void _zoneSetName(tracy::ScopedZone& zone, const char* text)
99{
100 zone.Name(text, strlen(text));
101}
102inline 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
140const bool Profile_DtOsgCullVisitor = false;
141
142namespace makVrv
143{
144 void DT_DLL_VRVUTIL SetThreadName(const char* name);
145
151 {
152 public:
154 DtProfileSample(const char* name)
155 {
157 }
158
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
190 };
191
211}
212
const bool Profile_DtSceneObjectUpdater
Definition DtProfiler.h:138
void _zoneSetText(tracy::ScopedZone &zone, const char *text)
Definition DtProfiler.h:89
const bool Profile_DtOsgCullVisitor
Definition DtProfiler.h:140
const bool Profile_DtSurfaceClampingUpdater
Definition DtProfiler.h:139
void _zoneSetName(tracy::ScopedZone &zone, const char *text)
Definition DtProfiler.h:98
DtPerfomanceStatSample(const char *name)
CTOR starts profile section.
Definition DtProfiler.h:200
~DtPerfomanceStatSample()
DTOR stops profile section.
Definition DtProfiler.h:206
static void startPerformanceStat(const char *name)
begin a performance stat. This function is thread safe
static void stopPerformanceStat()
begin stop a profile. This function is thread safe
static void startProfile(const char *name)
begin a profile. This function is thread safe
static void stopProfile()
begin stop a profile. This function is thread safe
~DtProfileSample()
DTOR stops profile section.
Definition DtProfiler.h:160
DtProfileSample(const char *name)
CTOR starts profile section.
Definition DtProfiler.h:154
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
void DT_DLL_VRVUTIL SetThreadName(const char *name)
~DtProfileTarget()
DTOR stops profile section.
Definition DtProfiler.h:186
DtProfileTarget(const char *name)
CTOR starts profile section.
Definition DtProfiler.h:180
DtProfileTarget(const char *name)
Definition DtProfiler.h:173
Contains DLL export macros.
#define DT_DLL_VRVUTIL
Definition vrvUtil.h:34