15#if defined(JPH_EXTERNAL_PROFILE)
23class alignas(16) ExternalProfileMeasurement :
public NonCopyable
27 ExternalProfileMeasurement(
const char *inName,
uint32 inColor = 0);
28 ~ExternalProfileMeasurement();
40JPH_SUPPRESS_WARNING_PUSH
44#define JPH_PROFILE_THREAD_START(name)
45#define JPH_PROFILE_THREAD_END()
46#define JPH_PROFILE_NEXTFRAME()
47#define JPH_PROFILE_DUMP(...)
50#define JPH_PROFILE_TAG2(line) profile##line
51#define JPH_PROFILE_TAG(line) JPH_PROFILE_TAG2(line)
62#define JPH_PROFILE(...) ExternalProfileMeasurement JPH_PROFILE_TAG(__LINE__)(__VA_ARGS__)
65#define JPH_PROFILE_FUNCTION() JPH_PROFILE(JPH_FUNCTION_NAME)
67JPH_SUPPRESS_WARNING_POP
69#elif defined(JPH_PROFILE_ENABLED)
87 void Dump(
const string_view &inTag = string_view());
112 Aggregator(
const char *inName) : mName(inName) { }
115 void AccumulateMeasurement(
uint64 inCyclesInCallWithChildren,
uint64 inCyclesInChildren)
118 mTotalCyclesInCallWithChildren += inCyclesInCallWithChildren;
119 mTotalCyclesInChildren += inCyclesInChildren;
120 mMinCyclesInCallWithChildren = min(inCyclesInCallWithChildren, mMinCyclesInCallWithChildren);
121 mMaxCyclesInCallWithChildren = max(inCyclesInCallWithChildren, mMaxCyclesInCallWithChildren);
125 bool operator < (
const Aggregator &inRHS)
const
127 return mTotalCyclesInCallWithChildren > inRHS.mTotalCyclesInCallWithChildren;
135 uint64 mTotalCyclesInCallWithChildren = 0;
136 uint64 mTotalCyclesInChildren = 0;
137 uint64 mMinCyclesInCallWithChildren = 0xffffffffffffffffUL;
138 uint64 mMaxCyclesInCallWithChildren = 0;
146 static void sAggregate(
int inDepth,
uint32 inColor,
ProfileSample *&ioSample,
const ProfileSample *inEnd, Aggregators &ioAggregators, KeyToAggregator &ioKeyToAggregator);
150 void DumpList(
const char *inTag,
const Aggregators &inAggregators);
151 void DumpChart(
const char *inTag,
const Threads &inThreads,
const KeyToAggregator &inKeyToAggregators,
const Aggregators &inAggregators);
204 static bool sOutOfSamplesReported;
215JPH_SUPPRESS_WARNING_PUSH
219#define JPH_PROFILE_START(name) do { Profiler::sInstance = new Profiler; JPH_PROFILE_THREAD_START(name); } while (false)
222#define JPH_PROFILE_END() do { JPH_PROFILE_THREAD_END(); delete Profiler::sInstance; Profiler::sInstance = nullptr; } while (false)
225#define JPH_PROFILE_THREAD_START(name) do { if (Profiler::sInstance) ProfileThread::sInstance = new ProfileThread(name); } while (false)
228#define JPH_PROFILE_THREAD_END() do { delete ProfileThread::sInstance; ProfileThread::sInstance = nullptr; } while (false)
231#define JPH_PROFILE_TAG2(line) profile##line
232#define JPH_PROFILE_TAG(line) JPH_PROFILE_TAG2(line)
233#define JPH_PROFILE(...) ProfileMeasurement JPH_PROFILE_TAG(__LINE__)(__VA_ARGS__)
236#define JPH_PROFILE_FUNCTION() JPH_PROFILE(JPH_FUNCTION_NAME)
239#define JPH_PROFILE_NEXTFRAME() Profiler::sInstance->NextFrame()
242#define JPH_PROFILE_DUMP(...) Profiler::sInstance->Dump(__VA_ARGS__)
244JPH_SUPPRESS_WARNING_POP
252JPH_SUPPRESS_WARNING_PUSH
255#define JPH_PROFILE_START(name)
256#define JPH_PROFILE_END()
257#define JPH_PROFILE_THREAD_START(name)
258#define JPH_PROFILE_THREAD_END()
259#define JPH_PROFILE(...)
260#define JPH_PROFILE_FUNCTION()
261#define JPH_PROFILE_NEXTFRAME()
262#define JPH_PROFILE_DUMP(...)
264JPH_SUPPRESS_WARNING_POP
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition Core.h:245
uint32_t uint32
Definition Core.h:312
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition Core.h:255
unsigned int uint
Definition Core.h:309
#define JPH_NAMESPACE_END
Definition Core.h:240
#define JPH_CLANG_SUPPRESS_WARNING(w)
Definition Core.h:133
uint8_t uint8
Definition Core.h:310
uint64_t uint64
Definition Core.h:313
#define JPH_NAMESPACE_BEGIN
Definition Core.h:234
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:29
std::vector< T, STLAllocator< T > > Array
Definition STLAllocator.h:81
std::basic_string< char, std::char_traits< char >, STLAllocator< char > > String
Definition STLAllocator.h:82
std::unordered_map< Key, T, Hash, KeyEqual, STLAllocator< pair< const Key, T > > > UnorderedMap
Definition UnorderedMap.h:13
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Create this class on the stack to start sampling timing information of a particular scope.
Definition Profiler.h:194
ProfileMeasurement(const char *inName, uint32 inColor=0)
Constructor.
Definition Profiler.inl:26
~ProfileMeasurement()
Definition Profiler.inl:57
Definition Profiler.h:161
uint32 mColor
Color to use for this sample.
Definition Profiler.h:166
uint8 mUnused[3]
Definition Profiler.h:168
uint64 mEndCycle
Cycle counter at end of measurement.
Definition Profiler.h:170
JPH_OVERRIDE_NEW_DELETE const char * mName
User defined name of this item.
Definition Profiler.h:165
uint8 mDepth
Calculated depth.
Definition Profiler.h:167
uint64 mStartCycle
Cycle counter at start of measurement.
Definition Profiler.h:169
Collects all samples of a single thread.
Definition Profiler.h:175
ProfileSample mSamples[cMaxSamples]
Buffer of samples.
Definition Profiler.h:186
uint mCurrentSample
Next position to write a sample to.
Definition Profiler.h:187
~ProfileThread()
Definition Profiler.inl:17
JPH_OVERRIDE_NEW_DELETE ProfileThread(const string_view &inThreadName)
Constructor.
Definition Profiler.inl:11
static thread_local ProfileThread * sInstance
Definition Profiler.h:189
String mThreadName
Name of the thread that we're collecting information for.
Definition Profiler.h:185
static const uint cMaxSamples
Definition Profiler.h:183
Singleton class for managing profiling information.
Definition Profiler.h:78
void Dump(const string_view &inTag=string_view())
Definition Profiler.cpp:43
void RemoveThread(ProfileThread *inThread)
Remove a thread from being instrumented.
Definition Profiler.cpp:56
void AddThread(ProfileThread *inThread)
Add a thread to be instrumented.
Definition Profiler.cpp:49
static Profiler * sInstance
Singleton instance.
Definition Profiler.h:96
JPH_OVERRIDE_NEW_DELETE void NextFrame()
Increments the frame counter to provide statistics per frame.
Definition Profiler.cpp:29