29#ifndef PX_PROFILE_MEMORY_EVENT_BUFFER_H
30#define PX_PROFILE_MEMORY_EVENT_BUFFER_H
32#include "PxProfileDataBuffer.h"
33#include "PxProfileMemoryEvents.h"
34#include "PxProfileMemory.h"
35#include "PxProfileScopedMutexLock.h"
36#include "PxProfileAllocatorWrapper.h"
37#include "PxProfileEventMutex.h"
39#include "foundation/PxHash.h"
40#include "foundation/PxHashMap.h"
41#include "foundation/PxUserAllocated.h"
43namespace physx {
namespace profile {
45 template<
typename TMutex,
51 typedef typename TBaseType::TMutexType TMutexType;
52 typedef typename TBaseType::TScopedLockType TScopedLockType;
64 , uint32_t inBufferFullAmount
65 , TMutexType* inBufferMutex )
66 :
TBaseType( &cback, inBufferFullAmount, inBufferMutex,
"struct physx::profile::MemoryEvent" )
67 , mStringTable(
TU8AllocatorType( TBaseType::getWrapper(),
"MemoryEventStringBuffer" ) )
71 uint32_t getHandle(
const char* inData )
73 if ( inData == NULL ) inData =
"";
76 return result->second;
77 uint32_t hdl = mStringTable.size() + 1;
78 mStringTable.insert( inData, hdl );
80 theEvent.init( inData, hdl );
81 sendEvent( theEvent );
85 void onAllocation(
size_t inSize,
const char* inType,
const char* inFile, uint32_t inLine, uint64_t addr )
89 uint32_t typeHdl( getHandle( inType ) );
90 uint32_t fileHdl( getHandle( inFile ) );
92 theEvent.init( inSize, typeHdl, fileHdl, inLine, addr );
93 sendEvent( theEvent );
96 void onDeallocation( uint64_t addr )
101 theEvent.init( addr );
102 sendEvent( theEvent );
105 void flushProfileEvents()
107 TBaseType::flushEvents();
112 template<
typename TDataType>
113 void sendEvent( TDataType inType )
116 inType.setup( theHeader );
117 theHeader.streamify( TBaseType::mSerializer );
118 inType.streamify( TBaseType::mSerializer, theHeader );
119 if ( TBaseType::mDataArray.size() >= TBaseType::mBufferFullAmount )
120 flushProfileEvents();
132 : mBuffer( alloc, inBufferFullAmount, NULL )
136 virtual void onAllocation(
size_t size,
const char* typeName,
const char* filename,
int line,
void* allocatedMemory )
138 mBuffer.onAllocation( size, typeName, filename, uint32_t(line),
static_cast<uint64_t
>(
reinterpret_cast<size_t>(allocatedMemory)) );
142 mBuffer.onDeallocation(
static_cast<uint64_t
>(
reinterpret_cast<size_t>(allocatedMemory)) );
147 virtual bool hasClients()
const {
return mBuffer.hasClients(); }
151 virtual void release(){ PX_PROFILE_DELETE( mBuffer.getWrapper().getAllocator(),
this ); }
Abstract base class for an application defined memory allocator that can be used by the Nv library.
Definition PxAllocatorCallback.h:53
Definition PxHashMap.h:78
Definition PxBasicTemplates.h:67
Definition PxUserAllocated.h:43
Definition PxProfileDataBuffer.h:41
Definition PxProfileMemoryEventBuffer.h:48
Client handles the data when an event buffer flushes. This data can be parsed (PxProfileEventHandler....
Definition PxProfileEventBufferClient.h:39
Definition PxProfileMemoryEventBuffer.h:126
virtual void onDeallocation(void *allocatedMemory)
callback when memory is deallocated.
Definition PxProfileMemoryEventBuffer.h:140
virtual bool hasClients() const
Check if manager has clients.
Definition PxProfileMemoryEventBuffer.h:147
virtual void onAllocation(size_t size, const char *typeName, const char *filename, int line, void *allocatedMemory)
callback when memory is allocated.
Definition PxProfileMemoryEventBuffer.h:136
virtual void removeClient(PxProfileEventBufferClient &inClient)
Removes a client.
Definition PxProfileMemoryEventBuffer.h:146
virtual void release()
Release the instance.
Definition PxProfileMemoryEventBuffer.h:151
virtual void flushProfileEvents()
Flush profile events. Sends the profile event buffer to hooked clients.
Definition PxProfileMemoryEventBuffer.h:149
virtual void addClient(PxProfileEventBufferClient &inClient)
Adds new client.
Definition PxProfileMemoryEventBuffer.h:145
Stores memory events into the memory buffer.
Definition PxProfileMemory.h:65
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxProfileMemoryEvents.h:242
Definition PxProfileMemoryEvents.h:335
Helper class to encapsulate the named allocator.
Definition PxProfileAllocatorWrapper.h:115
Definition PxProfileMemoryEvents.h:178