RavEngine
Loading...
Searching...
No Matches
PxProfileZoneManagerImpl.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_PROFILE_ZONE_MANAGER_IMPL_H
30#define PX_PROFILE_ZONE_MANAGER_IMPL_H
31
32#include "PxProfileZoneManager.h"
33#include "PxProfileScopedMutexLock.h"
34#include "PxPvdProfileZone.h"
35#include "PxProfileAllocatorWrapper.h"
36
37#include "foundation/PxArray.h"
38#include "foundation/PxMutex.h"
39
40namespace physx { namespace profile {
41
43 {
44 virtual PxProfileNames getProfileNames() const { return PxProfileNames( 0, 0 ); }
45 };
46
48 {
53 PxMutex mMutex;
54
55 ZoneManagerImpl( const ZoneManagerImpl& inOther );
56 ZoneManagerImpl& operator=( const ZoneManagerImpl& inOther );
57
58 public:
59
61 : mWrapper( inFoundation )
62 , mZones( mWrapper )
63 , mHandlers( mWrapper )
64 {}
65
66 virtual ~ZoneManagerImpl()
67 {
68 //This assert would mean that a profile zone is outliving us.
69 //This will cause a crash when the profile zone is released.
70 PX_ASSERT( mZones.size() == 0 );
71 while( mZones.size() )
72 removeProfileZone( *mZones.back() );
73 }
74
75 virtual void addProfileZone( PxProfileZone& inSDK )
76 {
77 TScopedLockType lock( &mMutex );
78
79 if ( inSDK.getProfileZoneManager() != NULL )
80 {
81 if ( inSDK.getProfileZoneManager() == this )
82 return;
83 else //there must be two managers in the system somehow.
84 {
85 PX_ASSERT( false );
87 }
88 }
89 mZones.pushBack( &inSDK );
90 inSDK.setProfileZoneManager( this );
91 for ( uint32_t idx =0; idx < mHandlers.size(); ++idx )
92 mHandlers[idx]->onZoneAdded( inSDK );
93 }
94
95 virtual void removeProfileZone( PxProfileZone& inSDK )
96 {
97 TScopedLockType lock( &mMutex );
98 if ( inSDK.getProfileZoneManager() == NULL )
99 return;
100
101 else if ( inSDK.getProfileZoneManager() != this )
102 {
103 PX_ASSERT( false );
105 return;
106 }
107
108 inSDK.setProfileZoneManager( NULL );
109 for ( uint32_t idx = 0; idx < mZones.size(); ++idx )
110 {
111 if ( mZones[idx] == &inSDK )
112 {
113 for ( uint32_t handler =0; handler < mHandlers.size(); ++handler )
114 mHandlers[handler]->onZoneRemoved( inSDK );
115 mZones.replaceWithLast( idx );
116 }
117 }
118 }
119
120 virtual void flushProfileEvents()
121 {
122 uint32_t sdkCount = mZones.size();
123 for ( uint32_t idx = 0; idx < sdkCount; ++idx )
124 mZones[idx]->flushProfileEvents();
125 }
126
128 {
129 TScopedLockType lock( &mMutex );
130 mHandlers.pushBack( &inHandler );
131 for ( uint32_t idx = 0; idx < mZones.size(); ++idx )
132 inHandler.onZoneAdded( *mZones[idx] );
133 }
134
136 {
137 TScopedLockType lock( &mMutex );
138 for( uint32_t idx = 0; idx < mZones.size(); ++idx )
139 inHandler.onZoneRemoved( *mZones[idx] );
140 for( uint32_t idx = 0; idx < mHandlers.size(); ++idx )
141 {
142 if ( mHandlers[idx] == &inHandler )
143 mHandlers.replaceWithLast( idx );
144 }
145 }
146
147 virtual PxProfileZone& createProfileZone( const char* inSDKName, PxProfileNameProvider* inProvider, uint32_t inEventBufferByteSize )
148 {
149 NullEventNameProvider nullProvider;
150 if ( inProvider == NULL )
151 inProvider = &nullProvider;
152 return createProfileZone( inSDKName, inProvider->getProfileNames(), inEventBufferByteSize );
153 }
154
155
156 virtual PxProfileZone& createProfileZone( const char* inSDKName, PxProfileNames inNames, uint32_t inEventBufferByteSize )
157 {
158 PxProfileZone& retval( PxProfileZone::createProfileZone( &mWrapper.getAllocator(), inSDKName, inNames, inEventBufferByteSize ) );
159 addProfileZone( retval );
160 return retval;
161 }
162
163 virtual void release()
164 {
165 PX_PROFILE_DELETE( mWrapper.getAllocator(), this );
166 }
167 };
168} }
169
170
171#endif
172
Abstract base class for an application defined memory allocator that can be used by the Nv library.
Definition PxAllocatorCallback.h:53
PX_FORCE_INLINE uint32_t size() const
Definition PxArray.h:242
PX_FORCE_INLINE T & pushBack(const T &a)
Definition PxArray.h:296
PX_INLINE void replaceWithLast(uint32_t i)
Definition PxArray.h:345
PX_FORCE_INLINE const T & back() const
Definition PxArray.h:224
Definition PxMutex.h:89
Provides a mapping from event ID -> name.
Definition PxProfileEventNames.h:74
virtual PxProfileNames getProfileNames() const =0
Returns profile event names.
Profile zone handler for zone add/remove notification.
Definition PxProfileZoneManager.h:46
virtual void onZoneAdded(PxProfileZone &inSDK)=0
On zone added notification
virtual void onZoneRemoved(PxProfileZone &inSDK)=0
On zone removed notification
The profiling system was setup in the expectation that there would be several systems that each had i...
Definition PxProfileZoneManager.h:86
virtual void removeProfileZone(PxProfileZone &inSDK)=0
Removes profile zone from the manager.
The profiling system was setup in the expectation that there would be several systems that each had i...
Definition PxPvdProfileZone.h:67
virtual void setProfileZoneManager(PxProfileZoneManager *inMgr)=0
Set profile zone manager for the zone.
static PxProfileZone & createProfileZone(PxAllocatorCallback *inAllocator, const char *inSDKName, PxProfileNames inNames=PxProfileNames(), uint32_t inEventBufferByteSize=0x10000)
Create a new profile zone.
Definition PxProfileEventImpl.cpp:45
virtual PxProfileZoneManager * getProfileZoneManager()=0
Get profile zone manager for the zone.
Definition PxProfileZoneManagerImpl.h:48
virtual PxProfileZone & createProfileZone(const char *inSDKName, PxProfileNames inNames, uint32_t inEventBufferByteSize)
Create a new profile zone. This means you don't need access to a PxFoundation to create your profile ...
Definition PxProfileZoneManagerImpl.h:156
virtual void addProfileZone(PxProfileZone &inSDK)
Add new profile zone for the manager.
Definition PxProfileZoneManagerImpl.h:75
virtual void addProfileZoneHandler(PxProfileZoneHandler &inHandler)
Add profile zone handler callback for the profile zone notifications.
Definition PxProfileZoneManagerImpl.h:127
virtual void removeProfileZoneHandler(PxProfileZoneHandler &inHandler)
Removes profile zone handler callback for the profile zone notifications.
Definition PxProfileZoneManagerImpl.h:135
virtual void release()
Releases the profile manager instance.
Definition PxProfileZoneManagerImpl.h:163
virtual void flushProfileEvents()
Flush profile events. Sends the profile event buffer to hooked clients.
Definition PxProfileZoneManagerImpl.h:120
virtual void removeProfileZone(PxProfileZone &inSDK)
Removes profile zone from the manager.
Definition PxProfileZoneManagerImpl.h:95
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxProfileZoneManagerImpl.h:43
virtual PxProfileNames getProfileNames() const
Returns profile event names.
Definition PxProfileZoneManagerImpl.h:44
Helper struct to encapsulate the user allocator callback Useful for array and hash templates.
Definition PxProfileAllocatorWrapper.h:46
Helper struct to encapsulate the array.
Definition PxProfileAllocatorWrapper.h:152
Aggregator of event id -> name mappings.
Definition PxProfileEventNames.h:54
Definition PxProfileScopedMutexLock.h:41