15#if defined(JPH_EXTERNAL_PROFILE)
19#ifdef JPH_SHARED_LIBRARY
21using ProfileStartMeasurementFunction = void (*)(
const char *inName,
uint32 inColor,
uint8 *ioUserData);
22using ProfileEndMeasurementFunction = void (*)(
uint8 *ioUserData);
24JPH_EXPORT extern ProfileStartMeasurementFunction ProfileStartMeasurement;
25JPH_EXPORT extern ProfileEndMeasurementFunction ProfileEndMeasurement;
33class alignas(16) ExternalProfileMeasurement :
public NonCopyable
37#ifdef JPH_SHARED_LIBRARY
38 JPH_INLINE ExternalProfileMeasurement(
const char *inName,
uint32 inColor = 0) { ProfileStartMeasurement(inName, inColor, mUserData); }
39 JPH_INLINE ~ExternalProfileMeasurement() { ProfileEndMeasurement(mUserData); }
41 ExternalProfileMeasurement(
const char *inName,
uint32 inColor = 0);
42 ~ExternalProfileMeasurement();
59#define JPH_PROFILE_START(name)
60#define JPH_PROFILE_END()
61#define JPH_PROFILE_THREAD_START(name)
62#define JPH_PROFILE_THREAD_END()
63#define JPH_PROFILE_NEXTFRAME()
64#define JPH_PROFILE_DUMP(...)
67#define JPH_PROFILE_TAG2(line) profile##line
68#define JPH_PROFILE_TAG(line) JPH_PROFILE_TAG2(line)
79#define JPH_PROFILE(...) ExternalProfileMeasurement JPH_PROFILE_TAG(__LINE__)(__VA_ARGS__)
82#define JPH_PROFILE_FUNCTION() JPH_PROFILE(JPH_FUNCTION_NAME)
86#elif defined(JPH_PROFILE_ENABLED)
107 void Dump(
const string_view &inTag = string_view());
116 uint64 GetProcessorTicksPerSecond()
const;
135 Aggregator(
const char *inName) : mName(inName) { }
138 void AccumulateMeasurement(
uint64 inCyclesInCallWithChildren)
141 mTotalCyclesInCallWithChildren += inCyclesInCallWithChildren;
142 mMinCyclesInCallWithChildren = min(inCyclesInCallWithChildren, mMinCyclesInCallWithChildren);
143 mMaxCyclesInCallWithChildren = max(inCyclesInCallWithChildren, mMaxCyclesInCallWithChildren);
147 bool operator < (
const Aggregator &inRHS)
const
149 return mTotalCyclesInCallWithChildren > inRHS.mTotalCyclesInCallWithChildren;
157 uint64 mTotalCyclesInCallWithChildren = 0;
158 uint64 mMinCyclesInCallWithChildren = 0xffffffffffffffffUL;
159 uint64 mMaxCyclesInCallWithChildren = 0;
167 static void sAggregate(
int inDepth,
uint32 inColor,
ProfileSample *&ioSample,
const ProfileSample *inEnd, Aggregators &ioAggregators, KeyToAggregator &ioKeyToAggregator);
170 void UpdateReferenceTime();
174 void DumpChart(
const char *inTag,
const Threads &inThreads,
const KeyToAggregator &inKeyToAggregators,
const Aggregators &inAggregators);
214#ifdef JPH_SHARED_LIBRARY
238 static bool sOutOfSamplesReported;
253#define JPH_PROFILE_START(name) do { Profiler::sInstance = new Profiler; JPH_PROFILE_THREAD_START(name); } while (false)
256#define JPH_PROFILE_END() do { JPH_PROFILE_THREAD_END(); delete Profiler::sInstance; Profiler::sInstance = nullptr; } while (false)
259#define JPH_PROFILE_THREAD_START(name) do { if (Profiler::sInstance) ProfileThread::sSetInstance(new ProfileThread(name)); } while (false)
262#define JPH_PROFILE_THREAD_END() do { delete ProfileThread::sGetInstance(); ProfileThread::sSetInstance(nullptr); } while (false)
265#define JPH_PROFILE_TAG2(line) profile##line
266#define JPH_PROFILE_TAG(line) JPH_PROFILE_TAG2(line)
267#define JPH_PROFILE(...) ProfileMeasurement JPH_PROFILE_TAG(__LINE__)(__VA_ARGS__)
270#define JPH_PROFILE_FUNCTION() JPH_PROFILE(JPH_FUNCTION_NAME)
273#define JPH_PROFILE_NEXTFRAME() Profiler::sInstance->NextFrame()
276#define JPH_PROFILE_DUMP(...) Profiler::sInstance->Dump(__VA_ARGS__)
289#define JPH_PROFILE_START(name)
290#define JPH_PROFILE_END()
291#define JPH_PROFILE_THREAD_START(name)
292#define JPH_PROFILE_THREAD_END()
293#define JPH_PROFILE(...)
294#define JPH_PROFILE_FUNCTION()
295#define JPH_PROFILE_NEXTFRAME()
296#define JPH_PROFILE_DUMP(...)
std::uint8_t uint8
Definition Core.h:501
#define JPH_EXPORT
Definition Core.h:275
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition Core.h:430
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition Core.h:443
std::uint64_t uint64
Definition Core.h:504
unsigned int uint
Definition Core.h:500
#define JPH_NAMESPACE_END
Definition Core.h:425
#define JPH_CLANG_SUPPRESS_WARNING(w)
Definition Core.h:302
std::uint32_t uint32
Definition Core.h:503
#define JPH_EXPORT_GCC_BUG_WORKAROUND
Definition Core.h:279
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:50
std::basic_string< char, std::char_traits< char >, STLAllocator< char > > String
Definition STLAllocator.h:107
#define JPH_SUPPRESS_WARNING_POP
Definition ShaderCore.h:38
#define JPH_SUPPRESS_WARNING_PUSH
Definition ShaderCore.h:37
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:228
Definition Profiler.h:186
uint32 mColor
Color to use for this sample.
Definition Profiler.h:191
uint64 mEndCycle
Cycle counter at end of measurement.
Definition Profiler.h:195
JPH_OVERRIDE_NEW_DELETE const char * mName
User defined name of this item.
Definition Profiler.h:190
uint8 mDepth
Calculated depth.
Definition Profiler.h:192
uint64 mStartCycle
Cycle counter at start of measurement.
Definition Profiler.h:194
Collects all samples of a single thread.
Definition Profiler.h:200
ProfileSample mSamples[cMaxSamples]
Buffer of samples.
Definition Profiler.h:211
uint mCurrentSample
Next position to write a sample to.
Definition Profiler.h:212
~ProfileThread()
Definition Profiler.inl:17
JPH_OVERRIDE_NEW_DELETE ProfileThread(const string_view &inThreadName)
Constructor.
Definition Profiler.inl:11
static ProfileThread * sGetInstance()
Definition Profiler.h:219
String mThreadName
Name of the thread that we're collecting information for.
Definition Profiler.h:210
static void sSetInstance(ProfileThread *inInstance)
Definition Profiler.h:218
static const uint cMaxSamples
Definition Profiler.h:208
Singleton class for managing profiling information.
Definition Profiler.h:95
JPH_OVERRIDE_NEW_DELETE Profiler()
Constructor.
Definition Profiler.h:100
static Profiler * sInstance
Singleton instance.
Definition Profiler.h:119
Definition UnorderedMap.h:31