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 | |
12 | #ifndef PX_DEFAULT_BUFFERED_PROFILER_H |
13 | #define PX_DEFAULT_BUFFERED_PROFILER_H |
14 | /** \addtogroup extensions |
15 | @{ |
16 | */ |
17 | |
18 | #include "common/PxPhysXCommonConfig.h" |
19 | |
20 | #ifndef PX_DOXYGEN |
21 | namespace physx |
22 | { |
23 | #endif |
24 | class PxProfileZoneManager; |
25 | |
26 | /** |
27 | \brief Event structure for buffered profiler callback. |
28 | |
29 | \note This structure is used also for CUDA events, therefore some |
30 | members are not defined in case of a CUDA event. |
31 | |
32 | @see physx::PxBufferedProfilerCallback |
33 | */ |
34 | struct PxBufferedProfilerEvent |
35 | { |
36 | PxU64 startTimeNs; //!< the event start time in nanoseconds |
37 | PxU64 stopTimeNs; //!< the event end time in nanoseconds |
38 | const char* name; //!< the event name |
39 | const char* profileZoneName; //!< the name of the profile zone in which the event was generated |
40 | PxU16 id; //!< the event id |
41 | PxU64 contextId; //!< the optional contextId of the event set in start/endEvent, |
42 | //!< usually set to pointer inside the SDK. Not defined for CUDA events. |
43 | //!< @see physx::PxProfileEventSender |
44 | PxU32 threadId; //!< the thread in which the event was executed. Not defined for CUDA events. |
45 | PxU8 threadPriority; //!< the priority of the thread in which the event was executed. Not defined for CUDA events. |
46 | PxU8 cpuId; //!< the CPU on which the event was executed. Not defined for CUDA events. |
47 | }; |
48 | |
49 | /** |
50 | \brief A profiler callback that is called when the event buffer of a PxProfileZone fills up or is flushed. |
51 | |
52 | @see physx::PxProfileZone physx::PxProfileZoneManager physx::PxProfileZone |
53 | */ |
54 | class PxBufferedProfilerCallback |
55 | { |
56 | public: |
57 | /** |
58 | \brief Fixed ID for cross thread events. |
59 | */ |
60 | static const PxU32 CROSS_THREAD_ID = 99999789; |
61 | |
62 | /** |
63 | \brief Reports a start-stop event. |
64 | |
65 | \param[out] event the reported event. |
66 | |
67 | @see PxBufferedProfilerEvent |
68 | */ |
69 | virtual void onEvent(const PxBufferedProfilerEvent &event) = 0; |
70 | |
71 | protected: |
72 | virtual ~PxBufferedProfilerCallback(void) {} |
73 | }; |
74 | |
75 | ////////////////////////////////////////////////////////////////////////// |
76 | |
77 | /** |
78 | \brief Default implementation for profile event handler. |
79 | |
80 | The profile event handler listens for events from one or more profile zones, specified at creation time. It forwards those events |
81 | to one or more callbacks. |
82 | |
83 | Events will be reported when internal event buffers fill up. Calling flushEvents() result |
84 | in any unreported events being reported immediately. |
85 | |
86 | @see PxDefaultBufferedProfilerCreate physx::PxProfileZone physx::PxProfileZoneMananger |
87 | */ |
88 | class PxDefaultBufferedProfiler |
89 | { |
90 | public: |
91 | /** |
92 | \brief Flush all the event buffers to ensure that event callbacks see all events that have been issued. |
93 | |
94 | @see PxBufferedProfilerCallback |
95 | */ |
96 | virtual void flushEvents() = 0; |
97 | |
98 | /** |
99 | \brief Get the profile zone manager. |
100 | */ |
101 | virtual PxProfileZoneManager& getProfileZoneManager() = 0; |
102 | |
103 | /** |
104 | \brief add an event callback. |
105 | |
106 | \param[in] cb the callback to add. |
107 | */ |
108 | virtual void addBufferedProfilerCallback(PxBufferedProfilerCallback& cb) = 0; |
109 | |
110 | /** |
111 | \brief remove an event callback. |
112 | |
113 | \param[in] cb the event callback to remove. |
114 | */ |
115 | virtual void removeBufferedProfilerCallback(PxBufferedProfilerCallback& cb) = 0; |
116 | |
117 | /** |
118 | \brief Release the PxDefaultBufferedProfiler. |
119 | */ |
120 | virtual void release() = 0; |
121 | |
122 | protected: |
123 | virtual ~PxDefaultBufferedProfiler(void) {} |
124 | }; |
125 | |
126 | |
127 | /** |
128 | \brief Create default PxDefaultBufferedProfiler. |
129 | |
130 | Create a default buffered profiler. |
131 | |
132 | \param[in] foundation PxFoundation used for PxProfileZoneManager creation. |
133 | \param[in] profileZoneNames Space-separated names of PxProfileZones for which events should be reported to the callback. |
134 | |
135 | \note Example usage: PxDefaultBufferedProfilerCreate(*gFoundation, "PhysXSDK PxTaskManager"); |
136 | \note List of PhysX SDK profile zone names: PhysXSDK, PxTaskManager, PxGpuDispatcher (for CUDA GPU events) |
137 | |
138 | @see PxDefaultBufferedProfiler physx::PxProfileZoneManager physx::PxProfileZone |
139 | */ |
140 | PxDefaultBufferedProfiler* PxDefaultBufferedProfilerCreate(PxFoundation & foundation, const char * profileZoneNames ); |
141 | |
142 | |
143 | #ifndef PX_DOXYGEN |
144 | } // namespace physx |
145 | #endif |
146 | |
147 | /** @} */ |
148 | #endif // PX_DEFAULT_BUFFERED_PROFILER_H |
149 | |