29#ifndef PX_PROFILE_MEMORY_EVENTS_H
30#define PX_PROFILE_MEMORY_EVENTS_H
32#include "PxProfileEvents.h"
36namespace physx {
namespace profile {
49 template<
unsigned numBits,
typename TDataType>
50 inline unsigned char convertToNBits( TDataType inType )
52 uint8_t conversion =
static_cast<uint8_t
>( inType );
53 PX_ASSERT( conversion < (1 << numBits) );
57 template<
typename TDataType>
58 inline unsigned char convertToTwoBits( TDataType inType )
60 return convertToNBits<2>( inType );
63 template<
typename TDataType>
64 inline unsigned char convertToFourBits( TDataType inType )
66 return convertToNBits<4>( inType );
69 inline EventStreamCompressionFlags::Enum fromNumber( uint8_t inNum ) {
return static_cast<EventStreamCompressionFlags::Enum
>( inNum ); }
71 template<
unsigned lhs,
unsigned rhs>
72 inline void compileCheckSize()
78 template<
typename TDataType
81 ,
typename TInputType>
85 static TDataType createOffsetMask() {
return TDataType(createMask() << TOffset); }
87 static TDataType createMask() {
return static_cast<TDataType
>((1 << TNumBits) - 1); }
88 void setValue( TDataType& inCurrent, TInputType inData )
90 PX_ASSERT( inData < ( 1 << TNumBits ) );
93 TDataType theMask = TDataType(~(createOffsetMask()));
95 inCurrent = TDataType(inCurrent & theMask);
97 TDataType theAddition =
static_cast<TDataType
>( inData << TOffset );
99 inCurrent = TDataType(inCurrent | theAddition);
102 TInputType getValue( TDataType inCurrent )
104 return static_cast<TInputType
>( ( inCurrent >> TOffset ) & createMask() );
125 uint8_t defaultCompression( convertToTwoBits( EventStreamCompressionFlags::U64 ) );
126 TTypeBitmask().setValue( mValue, convertToFourBits( inType ) );
134 MemoryEventTypes::Enum getType()
const {
return static_cast<MemoryEventTypes::Enum
>(
TTypeBitmask().getValue( mValue ) ); }
136#define DEFINE_MEMORY_HEADER_COMPRESSION_ACCESSOR( name ) \
137 void set##name( EventStreamCompressionFlags::Enum inEnum ) { T##name##Bitmask().setValue( mValue, convertToTwoBits( inEnum ) ); } \
138 EventStreamCompressionFlags::Enum get##name() const { return fromNumber( T##name##Bitmask().getValue( mValue ) ); }
140 DEFINE_MEMORY_HEADER_COMPRESSION_ACCESSOR( AddrCompress )
141 DEFINE_MEMORY_HEADER_COMPRESSION_ACCESSOR( TypeCompress )
142 DEFINE_MEMORY_HEADER_COMPRESSION_ACCESSOR( FnameCompress )
143 DEFINE_MEMORY_HEADER_COMPRESSION_ACCESSOR( SizeCompress )
144 DEFINE_MEMORY_HEADER_COMPRESSION_ACCESSOR( LineCompress )
146#undef DEFINE_MEMORY_HEADER_COMPRESSION_ACCESSOR
150 return mValue == inOther.mValue;
152 template<
typename TStreamType>
153 void streamify( TStreamType& inStream )
155 inStream.streamify(
"Header", mValue );
160 template<
typename TDataType>
161 inline MemoryEventTypes::Enum getMemoryEventType() { PX_ASSERT(
false );
return MemoryEventTypes::Unknown; }
163 inline bool safeStrEq(
const char* lhs,
const char* rhs )
174 return ::strcmp( lhs, rhs ) == 0;
182 void init(
const char* inStr =
"", uint32_t inHdl = 0 )
190 mString = inData.mString;
191 mHandle = inData.mHandle;
196 return mHandle == inOther.mHandle
197 && safeStrEq( mString, inOther.mString );
202 template<
typename TStreamType>
205 inStream.streamify(
"String", mString );
206 inStream.streamify(
"Handle", mHandle );
209 template<>
inline MemoryEventTypes::Enum getMemoryEventType<StringTableEvent>() {
return MemoryEventTypes::StringTableEvent; }
214 void init( uint64_t addr )
221 mAddress = inData.mAddress;
226 return mAddress == inOther.mAddress;
231 inHeader.setAddrCompress( findCompressionValue( mAddress ) );
234 template<
typename TStreamType>
237 inStream.streamify(
"Address", mAddress, inHeader.getAddrCompress() );
247 void init(
size_t size = 0, uint32_t type = 0, uint32_t file = 0, uint32_t line = 0, uint64_t addr = 0 )
249 MemoryEventData::init( addr );
250 mSize =
static_cast<uint32_t
>( size );
258 MemoryEventData::init( inData );
259 mSize = inData.mSize;
260 mType = inData.mType;
261 mFile = inData.mFile;
262 mLine = inData.mLine;
267 return MemoryEventData::operator==( inOther )
268 && mSize == inOther.mSize
269 && mType == inOther.mType
270 && mFile == inOther.mFile
271 && mLine == inOther.mLine;
276 inHeader.setTypeCompress( findCompressionValue( mType ) );
277 inHeader.setFnameCompress( findCompressionValue( mFile ) );
278 inHeader.setSizeCompress( findCompressionValue( mSize ) );
279 inHeader.setLineCompress( findCompressionValue( mLine ) );
280 MemoryEventData::setup( inHeader );
283 template<
typename TStreamType>
286 inStream.streamify(
"Size", mSize, inHeader.getSizeCompress() );
287 inStream.streamify(
"Type", mType, inHeader.getTypeCompress() );
288 inStream.streamify(
"File", mFile, inHeader.getFnameCompress() );
289 inStream.streamify(
"Line", mLine, inHeader.getLineCompress() );
290 MemoryEventData::streamify( inStream, inHeader );
293 template<>
inline MemoryEventTypes::Enum getMemoryEventType<AllocationEvent>() {
return MemoryEventTypes::AllocationEvent; }
302 void init(
size_t size,
const char* type,
const char* file, uint32_t line, uint64_t addr )
304 MemoryEventData::init( addr );
313 MemoryEventData::init( inData );
314 mSize = inData.mSize;
315 mType = inData.mType;
316 mFile = inData.mFile;
317 mLine = inData.mLine;
322 return MemoryEventData::operator==( inOther )
323 && mSize == inOther.mSize
324 && safeStrEq( mType, inOther.mType )
325 && safeStrEq( mFile, inOther.mFile )
326 && mLine == inOther.mLine;
332 template<>
inline MemoryEventTypes::Enum getMemoryEventType<FullAllocationEvent>() {
return MemoryEventTypes::FullAllocationEvent; }
336 void init( uint64_t addr = 0 ) { MemoryEventData::init( addr ); }
337 void init(
const DeallocationEvent& inData ) { MemoryEventData::init( inData ); }
340 template<>
inline MemoryEventTypes::Enum getMemoryEventType<DeallocationEvent>() {
return MemoryEventTypes::DeallocationEvent; }
354 : mHeader( inHeader )
359 template<
typename TDataType>
361 : mHeader( getMemoryEventType<TDataType>() )
365 inType.setup( mHeader );
368 const EventData& getData()
const {
return mData; }
370 template<
typename TDataType>
371 const TDataType& getValue()
const { PX_ASSERT( mHeader.getType() == getMemoryEventType<TDataType>() );
return mData.toType<TDataType>(); }
373 template<
typename TDataType>
374 TDataType& getValue() { PX_ASSERT( mHeader.getType() == getMemoryEventType<TDataType>() );
return mData.toType<TDataType>(); }
376 template<
typename TRetVal,
typename TOperator>
377 inline TRetVal visit( TOperator inOp )
const;
379 bool operator==(
const MemoryEvent& inOther )
const
381 if ( !(mHeader == inOther.mHeader ) )
return false;
382 if ( mHeader.getType() )
388 template<
typename TRetVal,
typename TOperator>
389 inline TRetVal visit( MemoryEventTypes::Enum inEventType,
const MemoryEvent::EventData& inData, TOperator inOperator )
391 switch( inEventType )
397 case MemoryEventTypes::Unknown:
return inOperator(
static_cast<uint8_t
>( inEventType ) );
402 template<
typename TRetVal,
typename TOperator>
403 inline TRetVal MemoryEvent::visit( TOperator inOp )
const
405 return physx::profile::visit<TRetVal>( mHeader.getType(), mData, inOp );
Definition PxProfileMemoryEvents.h:343
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
uint8 uint8_t
Definition fwd.hpp:103
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:83
Definition PxProfileMemoryEvents.h:335
Definition PxProfileEvents.h:619
Definition PxProfileMemoryEvents.h:297
Definition PxProfileMemoryEvents.h:212
Definition PxProfileMemoryEvents.h:38
Definition PxProfileMemoryEvents.h:178
Definition PxProfileEvents.h:50