29#ifndef PX_PROFILE_ZONE_IMPL_H
30#define PX_PROFILE_ZONE_IMPL_H
32#include "PxPvdProfileZone.h"
33#include "PxProfileZoneManager.h"
34#include "PxProfileContextProviderImpl.h"
35#include "PxProfileScopedMutexLock.h"
36#include "PxProfileEventBufferAtomic.h"
37#include "foundation/PxMutex.h"
39namespace physx {
namespace profile {
55 template<
typename TNameProv
ider>
64 typedef TMutexType::ScopedLock TLockType;
79 volatile bool mEventsActive;
83 ZoneImpl(
PxAllocatorCallback* inAllocator,
const char* inName, uint32_t bufferSize = 0x10000 ,
const TNameProvider& inProvider = TNameProvider() )
87 , mEventNames( mWrapper )
88 , mNameToEvtIndexMapR( mWrapper )
89 , mNameToEvtIndexMapRW( mWrapper )
90 , mEvtIdToNameMap( mWrapper )
91 , mProfileZoneManager( NULL )
92 , mZoneClients( mWrapper )
93 , mEventsActive(
false )
95 TZoneEventBufferType::setBufferMutex( &mMutex );
98 for ( uint32_t idx = 0; idx < theNames.eventCount; ++idx )
101 doAddName( theName.name, theName.eventId.eventId, theName.eventId.compileTimeEnabled );
103 TZoneEventBufferType::addClient( *
this );
107 if ( mProfileZoneManager != NULL )
109 mProfileZoneManager = NULL;
110 TZoneEventBufferType::removeClient( *
this );
113 void doAddName(
const char* inName, uint16_t inEventId,
bool inCompileTimeEnabled )
115 TLockType theLocker( mMutex );
116 mEvtIdToNameMap.insert( inEventId, inName );
117 uint32_t idx =
static_cast<uint32_t
>( mEventNames.
size() );
118 mNameToEvtIndexMapRW.insert( inName, idx );
125 if (mNameToEvtIndexMapRW.size())
129 mNameToEvtIndexMapR.insert(iter->first, iter->second);
131 mNameToEvtIndexMapRW.clear();
148 return mEventNames[theEntry->second].eventId;
150 TLockType theLocker(mMutex);
154 return mEventNames[theReEntry->second].eventId;
157 uint16_t nameSize =
static_cast<uint16_t
>( mEventNames.
size() );
159 uint16_t eventId = nameSize;
161 bool foundAnEventId =
false;
164 foundAnEventId =
false;
166 for ( uint16_t idx = 0; idx < inLen && foundAnEventId ==
false; ++idx )
167 foundAnEventId = mEvtIdToNameMap.find( uint16_t(eventId + idx) ) != NULL;
169 while( foundAnEventId );
171 uint32_t clientCount = mZoneClients.
size();
172 for ( uint16_t nameIdx = 0; nameIdx < inLen; ++nameIdx )
174 uint16_t newId = uint16_t(eventId + nameIdx);
175 doAddName( inNames[nameIdx], newId,
true );
176 for( uint32_t clientIdx =0; clientIdx < clientCount; ++clientIdx )
185 mProfileZoneManager = inMgr;
190 return mProfileZoneManager;
203 TLockType lock( mMutex );
205 mEventsActive =
true;
210 TLockType lock( mMutex );
211 for ( uint32_t idx =0; idx < mZoneClients.
size(); ++idx )
213 if (mZoneClients[idx] == &inClient )
220 mEventsActive = mZoneClients.
size() != 0;
225 return mEventsActive;
230 TLockType theLocker( mMutex );
232 uint32_t theEventCount = uint32_t(mEventNames.
size());
238 PX_PROFILE_DELETE( mWrapper.getAllocator(),
this );
242 virtual void handleBufferFlush(
const uint8_t* inData, uint32_t inLength )
244 TLockType theLocker( mMutex );
246 uint32_t clientCount = mZoneClients.
size();
247 for( uint32_t idx =0; idx < clientCount; ++idx )
248 mZoneClients[idx]->handleBufferFlush( inData, inLength );
259 TZoneEventBufferType::startEvent( inId, contextId );
262 virtual void stopEvent( uint16_t inId, uint64_t contextId)
266 TZoneEventBufferType::stopEvent( inId, contextId );
270 virtual void startEvent( uint16_t inId, uint64_t contextId, uint32_t threadId)
274 TZoneEventBufferType::startEvent( inId, contextId, threadId );
277 virtual void stopEvent( uint16_t inId, uint64_t contextId, uint32_t threadId )
281 TZoneEventBufferType::stopEvent( inId, contextId, threadId );
285 virtual void atEvent(uint16_t inId, uint64_t contextId, uint32_t threadId, uint64_t start, uint64_t stop)
289 TZoneEventBufferType::startEvent(inId, threadId, contextId, 0, 0, start);
290 TZoneEventBufferType::stopEvent(inId, threadId, contextId, 0, 0, stop);
299 virtual void eventValue( uint16_t inId, uint64_t contextId, int64_t inValue )
303 TZoneEventBufferType::eventValue( inId, contextId, inValue );
308 TZoneEventBufferType::flushProfileEvents();
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 ConstIterator begin() const
Definition PxArray.h:176
PX_FORCE_INLINE T & pushBack(const T &a)
Definition PxArray.h:296
PX_INLINE void replaceWithLast(uint32_t i)
Definition PxArray.h:345
Definition PxHashInternals.h:453
Definition PxBasicTemplates.h:67
Definition PxProfileEventBuffer.h:109
Client handles the data when an event buffer flushes. This data can be parsed (PxProfileEventHandler....
Definition PxProfileEventBufferClient.h:39
virtual void handleClientRemoved()=0
Happens if something removes all the clients from the manager.
Helper class to encapsulate the reflection allocator.
Definition PxProfileAllocatorWrapper.h:71
Client handles new profile event add.
Definition PxProfileEventBufferClient.h:64
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
Definition PxProfileZoneImpl.h:59
virtual PxProfileNames getProfileNames() const
Returns profile event names.
Definition PxProfileZoneImpl.h:228
virtual void flushEventIdNameMap()
Specifies that it is a safe point to flush read-write name map into read-only map....
Definition PxProfileZoneImpl.h:122
virtual void stopEvent(uint16_t inId, uint64_t contextId)
Send a stop profile event, optionally with a context. Events are sorted by thread and context in the ...
Definition PxProfileZoneImpl.h:262
virtual void startEvent(uint16_t inId, uint64_t contextId)
Send a start profile event, optionally with a context. Events are sorted by thread and context in the...
Definition PxProfileZoneImpl.h:255
void addClient(PxProfileZoneClient &inClient)
Adds new client.
Definition PxProfileZoneImpl.h:201
virtual void stopEvent(uint16_t inId, uint64_t contextId, uint32_t threadId)
Send a stop profile event, optionally with a context. Events are sorted by thread and context in the ...
Definition PxProfileZoneImpl.h:277
const char * getName()
Get profile zone name.
Definition PxProfileZoneImpl.h:195
virtual void handleClientRemoved()
Happens if something removes all the clients from the manager.
Definition PxProfileZoneImpl.h:251
virtual void startEvent(uint16_t inId, uint64_t contextId, uint32_t threadId)
Send a start profile event, optionally with a context. Events are sorted by thread and context in the...
Definition PxProfileZoneImpl.h:270
virtual void eventValue(uint16_t inId, uint64_t contextId, int64_t inValue)
Definition PxProfileZoneImpl.h:299
virtual uint16_t getEventIdsForNames(const char **inNames, uint32_t inLen)
Reserve a contiguous set of profile event ids for a set of names.
Definition PxProfileZoneImpl.h:140
void removeClient(PxProfileZoneClient &inClient)
Removes a client.
Definition PxProfileZoneImpl.h:208
virtual uint16_t getEventIdForName(const char *inName)
Get or create a new event id for a given name. If you pass in a previously defined event name (includ...
Definition PxProfileZoneImpl.h:135
virtual void release()
Release the profile zone.
Definition PxProfileZoneImpl.h:236
virtual bool hasClients() const
Check if manager has clients.
Definition PxProfileZoneImpl.h:223
virtual void flushProfileEvents()
Flush profile events. Sends the profile event buffer to hooked clients.
Definition PxProfileZoneImpl.h:306
virtual void setProfileZoneManager(PxProfileZoneManager *inMgr)
Set profile zone manager for the zone.
Definition PxProfileZoneImpl.h:183
virtual PxProfileZoneManager * getProfileZoneManager()
Get profile zone manager for the zone.
Definition PxProfileZoneImpl.h:188
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxProfileContextProviderImpl.h:37
Helper struct to encapsulate the array.
Definition PxProfileAllocatorWrapper.h:152
A event id structure. Optionally includes information about if the event was enabled at compile time.
Definition PxProfileEventId.h:38
Mapping from event id to name.
Definition PxProfileEventNames.h:38
Helper struct to encapsulate the array.
Definition PxProfileAllocatorWrapper.h:171
Aggregator of event id -> name mappings.
Definition PxProfileEventNames.h:54
Simple event filter that enables all events.
Definition PxProfileZoneImpl.h:45
Definition PxProfileScopedMutexLock.h:41