Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Profiler.inl
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
6
8// ProfileThread
10
11ProfileThread::ProfileThread(const string_view &inThreadName) :
12 mThreadName(inThreadName)
13{
15}
16
21
23// ProfileMeasurement
25
27{
28 if (ProfileThread::sInstance == nullptr)
29 {
30 // Thread not instrumented
31 mSample = nullptr;
32 }
34 {
35 // Get pointer to write data to
37
38 // Start constructing sample (will end up on stack)
39 mTemp.mName = inName;
40 mTemp.mColor = inColor;
41
42 // Collect start sample last
44 }
45 else
46 {
47 // Out of samples
48 if (!sOutOfSamplesReported)
49 {
50 Trace("ProfileMeasurement: Too many samples, some data will be lost!");
51 sOutOfSamplesReported = true;
52 }
53 mSample = nullptr;
54 }
55}
56
58{
59 if (mSample != nullptr)
60 {
61 // Finalize sample
63
64 // Write it to the memory buffer bypassing the cache
65 static_assert(sizeof(ProfileSample) == 32, "Assume 32 bytes");
66 static_assert(alignof(ProfileSample) == 16, "Assume 16 byte alignment");
67 #if defined(JPH_USE_SSE)
68 const __m128i *src = reinterpret_cast<const __m128i *>(&mTemp);
69 __m128i *dst = reinterpret_cast<__m128i *>(mSample);
70 __m128i val = _mm_loadu_si128(src);
71 _mm_stream_si128(dst, val);
72 val = _mm_loadu_si128(src + 1);
73 _mm_stream_si128(dst + 1, val);
74 #elif defined(JPH_USE_NEON)
75 const int *src = reinterpret_cast<const int *>(&mTemp);
76 int *dst = reinterpret_cast<int *>(mSample);
77 int32x4_t val = vld1q_s32(src);
78 vst1q_s32(dst, val);
79 val = vld1q_s32(src + 4);
80 vst1q_s32(dst + 4, val);
81 #else
82 memcpy(mSample, &mTemp, sizeof(ProfileSample));
83 #endif
84 mSample = nullptr;
85 }
86}
87
uint32_t uint32
Definition Core.h:312
#define JPH_NAMESPACE_END
Definition Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition Core.h:234
TraceFunction Trace
Definition IssueReporting.cpp:18
JPH_NAMESPACE_BEGIN JPH_INLINE uint64 GetProcessorTickCount()
Functionality to get the processors cycle counter.
Definition TickCounter.h:24
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
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
uint64 mStartCycle
Cycle counter at start of measurement.
Definition Profiler.h:169
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
static const uint cMaxSamples
Definition Profiler.h:183
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