1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10
11#ifndef PX_PROFILE_SCOPED_EVENT_H
12#define PX_PROFILE_SCOPED_EVENT_H
13
14#include "physxprofilesdk/PxProfileBase.h"
15#include "physxprofilesdk/PxProfileEventId.h"
16#include "physxprofilesdk/PxProfileCompileTimeEventFilter.h"
17
18namespace physx { namespace profile {
19
20#define TO_PX_PROFILE_EVENT_ID( subsystem, eventId ) PxProfileEventId( SubsystemIds::subsystem, EventIds::subsystem##eventId );
21
22 template<bool TEnabled, typename TBufferType>
23 inline void startEvent( TBufferType* inBuffer, const PxProfileEventId& inId, PxU64 inContext )
24 {
25 if ( TEnabled && inBuffer ) inBuffer->startEvent( inId, inContext );
26 }
27
28 template<bool TEnabled, typename TBufferType>
29 inline void stopEvent( TBufferType* inBuffer, const PxProfileEventId& inId, PxU64 inContext )
30 {
31 if ( TEnabled && inBuffer ) inBuffer->stopEvent( inId, inContext );
32 }
33
34 template<typename TBufferType>
35 inline void startEvent( bool inEnabled, TBufferType* inBuffer, const PxProfileEventId& inId, PxU64 inContext )
36 {
37 if ( inEnabled && inBuffer ) inBuffer->startEvent( inId, inContext );
38 }
39
40 template<typename TBufferType>
41 inline void stopEvent( bool inEnabled, TBufferType* inBuffer, const PxProfileEventId& inId, PxU64 inContext )
42 {
43 if ( inEnabled && inBuffer ) inBuffer->stopEvent( inId, inContext );
44 }
45
46 template<typename TBufferType>
47 inline void eventValue( bool inEnabled, TBufferType* inBuffer, const PxProfileEventId& inId, PxU64 inContext, PxI64 inValue )
48 {
49 if ( inEnabled && inBuffer ) inBuffer->eventValue( inId, inContext, inValue );
50 }
51
52 template<bool TEnabled, typename TBufferType, PxU16 eventId>
53 struct ScopedEventWithContext
54 {
55 PxU64 mContext;
56 TBufferType* mBuffer;
57 ScopedEventWithContext( TBufferType* inBuffer, PxU64 inContext)
58 : mContext ( inContext )
59 , mBuffer( inBuffer )
60 {
61 startEvent<true>( mBuffer, PxProfileEventId(eventId), mContext );
62 }
63 ~ScopedEventWithContext()
64 {
65 stopEvent<true>( mBuffer, PxProfileEventId(eventId), mContext );
66 }
67 };
68
69 template<typename TBufferType, PxU16 eventId>
70 struct ScopedEventWithContext<false,TBufferType,eventId> { ScopedEventWithContext( TBufferType*, PxU64) {} };
71
72 template<typename TBufferType>
73 struct DynamicallyEnabledScopedEvent
74 {
75 TBufferType* mBuffer;
76 PxProfileEventId mId;
77 PxU64 mContext;
78 DynamicallyEnabledScopedEvent( TBufferType* inBuffer, const PxProfileEventId& inId, PxU64 inContext)
79 : mBuffer( inBuffer )
80 , mId( inId )
81 , mContext( inContext )
82 {
83 startEvent( mId.mCompileTimeEnabled, mBuffer, mId, mContext );
84 }
85 ~DynamicallyEnabledScopedEvent()
86 {
87 stopEvent( mId.mCompileTimeEnabled, mBuffer, mId, mContext );
88 }
89 };
90}}
91
92#define PX_PROFILE_SCOPED_EVENT_WITH_CONTEXT( TBufferType, subsystem, eventId, buffer, context ) \
93 physx::profile::ScopedEventWithContext<PX_PROFILE_EVENT_FILTER_VALUE(subsystem,eventId), TBufferType, physx::profile::EventIds::subsystem##eventId> profileScopedEvent( buffer, context );
94
95#define PX_PROFILE_EVENT_VALUE_WITH_CONTEXT( subsystem, eventId, buffer, context, value ) \
96 eventValue( PX_PROFILE_EVENT_FILTER_VALUE(subsystem,eventId), buffer, physx::profile::EventIds::subsystem##eventId, context, value );
97
98#endif // PX_PROFILE_SCOPED_EVENT_H
99