VR-Vantage 2.6 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtProfiler.h
Go to the documentation of this file.
1 /*********************************************************************************
2 ** Copyright (c) 2019 MAK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************************/
5 
10 
11 #pragma once
12 
13 #include <vrvUtil/vrvUtil.h>
15 
16 //easy to use macro to profile a section
17 // should pass a "const char*" as name because the pointer is getting
18 // used to do the string compare (to be fast)
19 // if a std::string is passed instead it will cause a crashed when
20 // loading/unloading terrain with the performance/stats displayed
21 
22 #ifdef _WIN32
23 #define TRACY_ENABLE
24 //#define OPTICK_ENABLE
25 //#define NO_PROFILER
26 #else
27 #endif
28 
29 #ifndef TRACY_ENABLE
30 #ifndef OPTICK_ENABLE
31 #define NO_PROFILER
32 #endif
33 #endif
34 //optick
36 #ifdef OPTICK_ENABLE
37 #include <optick/optick.h>
38 //#pragma comment(lib, "OptickCore.lib")
39 
40 // win32 creates macros that work with our stats and tracy
41 #define DtPROFILE(name) OPTICK_EVENT(name); DtPROFILE_X(name, __LINE__);
42 #define DtPROFILEC(name, color) OPTICK_EVENT(name); DtPROFILE_X(name, __LINE__);
43 #define DtPROFILE_SECTION(name) {OPTICK_EVENT(name); makVrv::DtProfileSample _profileSample(name);
44 
45 #define DtProfilerFrameMark OPTICK_FRAME("MainThread")
46 #define DtProfilerThreadName(name) OPTICK_THREAD(name);
47 #define DtProfilerMessage(str, stringLen)
48 
49 #define DtProfilerPlot(x,y)
50 #define DtProfilerText(text)
51 
52 #endif
53 
55 //tracy
56 #ifdef TRACY_ENABLE
57 #define TRACY_ON_DEMAND
58 #define TRACY_DELAYED_INIT
59 //#define TRACY_NO_BROADCAST
60 // TO DO include tracy on linux just to get it's macros for throwing things out
61 #include <TracyClient/Tracy.hpp>
62 //#pragma comment(lib, "TracyClient.lib")
63 
64 #define ZoneScopedNA( name, active ) ZoneNamedN( ___tracy_scoped_zone, name, active )
65 #define ZoneScopedNCA( name, color, active ) ZoneNamedNC( ___tracy_scoped_zone, name, color, active )
66 
67 // win32 creates macros that work with our stats and tracy
68 #define DtPROFILEzone ZoneNamed(___tracy_scoped_zone, makVrv::DtProfileManager::collectTracyStats());
69 #define DtPROFILE(name) ZoneScopedNA(name, makVrv::DtProfileManager::collectTracyStats()); DtPROFILE_X(name, __LINE__);
70 #define DtPROFILEC(name, color) ZoneScopedNCA(name, color, makVrv::DtProfileManager::collectTracyStats()); DtPROFILE_X(name, __LINE__);
71 #define DtPROFILE_SECTION(name) {ZoneScopedNA(name, makVrv::DtProfileManager::collectTracyStats()); makVrv::DtProfileSample _profileSample(name);
72 // call stack version doesn't work RtlWalkFrameChain unresolved.
73 //#define DtPROFILE(name) ZoneScopedNS(name, 4); DtPROFILE_X(name, __LINE__);
74 #define DtProfilerFrameMark if(makVrv::DtProfileManager::collectTracyStats()) { FrameMark; }
75 #define DtProfilerPlot(x,y) TracyPlot(x,y)
76 #define DtProfilerThreadName(name) tracy::SetThreadName(name );
77 #define DtProfilerMessage(str, stringLen) TracyMessage(str, stringLen)
78 #define DtProfilerText(text) _zoneSetText(___tracy_scoped_zone, text)
79 
80 inline void _zoneSetText(tracy::ScopedZone& zone, const char* text) {
81  zone.Text(text, strlen(text));
82 }
83 inline void _zoneSetText(tracy::ScopedZone& zone, const std::string& text) {
84  zone.Text(text.c_str(), text.size());
85 }
86 #endif
87 
89 // linux
90 #ifdef NO_PROFILER
91 #define DtPROFILE(name) DtPROFILE_X(name, __LINE__);
92 #define DtPROFILEC(name, color) DtPROFILE_X(name, __LINE__);
93 #define DtPROFILE_SECTION(name) {makVrv::DtProfileSample _profileSample(name);
94 #define DtPROFILEzone DtPROFILE_X(__func__, __LINE__);
95 
96 #define DtProfilerPlot(x,y)
97 
98 #define DtProfilerFrameMark
99 #define DtProfilerThreadName(name)
100 #define DtProfilerPlot(x,y)
101 #define DtProfilerMessage(str, stringLen)
102 #define DtProfilerText(text)
103 #endif
104 
105 #define DtPROFILE_RESTRICTED(name, target) makVrv::DtProfileTarget<target> _profileTarget##line(name);
106 
107 #define DtPROFILE_X(name, line) DtPROFILE_ACTUAL(name, line)
108 #define DtPROFILE_ACTUAL(name, line) makVrv::DtProfileSample _profileSample##line(name);
109 //#define DtPROFILE_FUNCTION(name, func) {makVrv::DtProfileSample _profileSample(name); (func);}
110 #define DtPROFILE_SECTION_END }
111 
112 #define DtPERFORMANCE_STAT(name) DtPERFORMANCE_STAT_X(name, __LINE__)
113 #define DtPERFORMANCE_STAT_X(name, line) DtPERFORMANCE_STAT_ACTUAL(name, line)
114 #define DtPERFORMANCE_STAT_ACTUAL(name, line) makVrv::DtPerfomanceStatSample _performanceStatSample##line(name);
115 
116 
117 // These constants configure DtPROFILE_RESTRICTED
118 //
119 // Define them to boost::true_type to enable profiling of those sections
120 const bool Profile_DtSceneObjectUpdater = false;
122 const bool Profile_DtOsgCullVisitor = false;
123 
124 namespace makVrv
125 {
126  void DT_DLL_VRVUTIL SetThreadName(const char* name);
127 
133  {
134  public:
136  DtProfileSample(const char* name )
137  {
139  }
140 
143  {
145  }
146  };
147 
152  template <bool Enabled>
154  {
155  DtProfileTarget(const char* name) {}
156  };
157 
158  template <>
159  struct DtProfileTarget<true>
160  {
162  DtProfileTarget(const char* name )
163  {
165  }
166 
169  {
171  }
172  };
173 
179  {
180  public:
182  DtPerfomanceStatSample(const char* name )
183  {
185  }
186 
189  {
191  }
192  };
193 }
194 
const bool Profile_DtOsgCullVisitor
Definition: DtProfiler.h:122
#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:153
DtProfileSampleClass is used to start/stop a profiled section It is preferable to use the macro at th...
Definition: DtProfiler.h:178
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:136
const bool Profile_DtSurfaceClampingUpdater
Definition: DtProfiler.h:121
~DtPerfomanceStatSample()
DTOR stops profile section.
Definition: DtProfiler.h:188
DtProfileTarget(const char *name)
CTOR starts profile section.
Definition: DtProfiler.h:162
DtProfileSampleClass is used to start/stop a profiled section It is preferable to use the macro at th...
Definition: DtProfiler.h:132
Contains DLL export macros.
const bool Profile_DtSceneObjectUpdater
Definition: DtProfiler.h:120
void DT_DLL_VRVUTIL SetThreadName(const char *name)
~DtProfileTarget()
DTOR stops profile section.
Definition: DtProfiler.h:168
static void stopPerformanceStat()
begin stop a profile. This function is thread safe
DtProfileTarget(const char *name)
Definition: DtProfiler.h:155
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:182
~DtProfileSample()
DTOR stops profile section.
Definition: DtProfiler.h:142
static void stopProfile()
begin stop a profile. This function is thread safe


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