NvBlastExtCustomProfiler.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTDEFAULTPROFILER_H
30 #define NVBLASTDEFAULTPROFILER_H
31 
32 #include "NvBlastProfiler.h"
33 #include "PxProfiler.h"
34 #include <PxFoundation.h>
35 
36 #if NV_NVTX
37 #include "nvToolsExt.h"
38 NV_INLINE void platformZoneStart(const char* name) { nvtxRangePushA(name); }
39 NV_INLINE void platformZoneEnd() { nvtxRangePop(); }
40 
41 #elif NV_XBOXONE
42 #include "xboxone/NvBlastProfilerXB1.h"
43 
44 #elif NV_PS4
45 #include "ps4/NvBlastProfilerPS4.h"
46 
47 #else
48 NV_INLINE void platformZoneStart(const char*) { }
50 
51 #endif
52 
53 #define SUPPORTS_THREAD_LOCAL (!NV_VC || NV_VC > 12)
54 
55 namespace Nv
56 {
57 namespace Blast
58 {
59 
61 {
62  const char* name;
63  void* data;
64 };
65 
66 #if SUPPORTS_THREAD_LOCAL
67 static const int32_t PROFILER_MAX_NESTED_DEPTH = 64;
68 static thread_local ExtProfileData th_ProfileData[PROFILER_MAX_NESTED_DEPTH];
69 static thread_local int32_t th_depth = 0;
70 #endif
71 
72 
78 {
79 public:
83  ExtCustomProfiler() : m_platformEnabled(false) {}
84 
85 
87 
88  virtual void zoneStart(const char* name) override
89  {
90 
91 #if SUPPORTS_THREAD_LOCAL
92  if (PxGetProfilerCallback())
93  {
94  void* data = PxGetProfilerCallback()->zoneStart(name, false, 0xb1a57);
95 
96  if (th_depth < PROFILER_MAX_NESTED_DEPTH && th_depth >= 0)
97  {
98  th_ProfileData[th_depth].name = name;
99  th_ProfileData[th_depth].data = data;
100  th_depth++;
101  }
102  else
103  {
104  assert(th_depth < PROFILER_MAX_NESTED_DEPTH && th_depth >= 0);
105  }
106  }
107 #endif
108 
109  if (m_platformEnabled)
110  {
111  platformZoneStart(name);
112  }
113  }
114 
115  virtual void zoneEnd() override
116  {
117 
118 #if SUPPORTS_THREAD_LOCAL
119  if (PxGetProfilerCallback())
120  {
121  th_depth--;
122 
123  if (th_depth >= 0)
124  {
125  ExtProfileData& pd = th_ProfileData[th_depth];
126  PxGetProfilerCallback()->zoneEnd(pd.data, pd.name, false, 0xb1a57);
127  }
128  else
129  {
130  assert(th_depth >= 0);
131  }
132  }
133 #endif
134 
135  if (m_platformEnabled)
136  {
137  platformZoneEnd();
138  }
139  }
140 
141 
143 
149  void setPlatformEnabled(bool enabled)
150  {
151  m_platformEnabled = enabled;
152  }
153 
154 private:
155  bool m_platformEnabled;
156 };
157 
158 } // namespace Blast
159 } // namespace Nv
160 
161 
162 #endif // NVBLASTDEFAULTPROFILER_H
virtual void zoneStart(const char *name) override
Definition: NvBlastExtCustomProfiler.h:88
NV_INLINE void platformZoneEnd()
Definition: NvBlastExtCustomProfiler.h:49
Definition: NvBlastExtCustomProfiler.h:77
NV_INLINE void platformZoneStart(const char *)
Definition: NvBlastExtCustomProfiler.h:48
void setPlatformEnabled(bool enabled)
Definition: NvBlastExtCustomProfiler.h:149
ExtCustomProfiler()
Definition: NvBlastExtCustomProfiler.h:83
#define NV_INLINE
Definition: NvPreprocessor.h:350
virtual void zoneEnd() override
Definition: NvBlastExtCustomProfiler.h:115
Definition: NvBlastProfiler.h:44
void * data
Definition: NvBlastExtCustomProfiler.h:63
Definition: NvBlastExtCustomProfiler.h:60
Definition: NvBlastArray.h:37
const char * name
Definition: NvBlastExtCustomProfiler.h:62