diff --git a/examples/testbed/framework/main.cpp b/examples/testbed/framework/main.cpp index 22ff529..9cd3863 100644 --- a/examples/testbed/framework/main.cpp +++ b/examples/testbed/framework/main.cpp @@ -124,7 +124,11 @@ static void Run() for (u32 i = 0; i < records.Count(); ++i) { const ProfilerRecord& r = records[i]; - g_draw->DrawString(b3Color_white, "%s %.4f (%.4f) [ms]", r.name, r.elapsed, r.maxElapsed); + + if (r.elapsed > 0.0) + { + g_draw->DrawString(b3Color_white, "%s %.4f (%.4f) [ms]", r.name, r.elapsed, r.maxElapsed); + } } } diff --git a/examples/testbed/framework/profiler.cpp b/examples/testbed/framework/profiler.cpp index bc72572..8a47078 100644 --- a/examples/testbed/framework/profiler.cpp +++ b/examples/testbed/framework/profiler.cpp @@ -30,7 +30,7 @@ Profiler::~Profiler() { } -bool Profiler::PushEvent(const char* name) +void Profiler::PushEvent(const char* name) { m_time.Update(); @@ -43,12 +43,8 @@ bool Profiler::PushEvent(const char* name) e.parent = m_top; ProfilerEvent* back = m_events.Push(e); - if (back) - { - m_top = back; - } - - return back != NULL; + B3_ASSERT(back); + m_top = back; } void Profiler::PopEvent() @@ -66,26 +62,37 @@ void Profiler::Begin() { // If this assert is hit then it means Profiler::End hasn't been called. B3_ASSERT(m_events.IsEmpty()); + B3_ASSERT(m_top == NULL); } void Profiler::End(ProfilerListener* listener) { - listener->BeginEvents(); + if (listener) + { + listener->BeginEvents(); + } while (m_events.IsEmpty() == false) { - const ProfilerEvent& e = m_events.Front(); + ProfilerEvent e = m_events.Front(); m_events.Pop(); - listener->BeginEvent(e.tid, e.pid, e.name, e.t0); + if (listener) + { + listener->BeginEvent(e.tid, e.pid, e.name, e.t0); - listener->EndEvent(e.tid, e.pid, e.name, e.t1); - - listener->Duration(e.name, e.t1 - e.t0); + listener->EndEvent(e.tid, e.pid, e.name, e.t1); + + listener->Duration(e.name, e.t1 - e.t0); + } } B3_ASSERT(m_events.IsEmpty()); + B3_ASSERT(m_top == NULL); - listener->EndEvents(); + if (listener) + { + listener->EndEvents(); + } } \ No newline at end of file diff --git a/examples/testbed/framework/profiler.h b/examples/testbed/framework/profiler.h index f5c2d8b..b54384d 100644 --- a/examples/testbed/framework/profiler.h +++ b/examples/testbed/framework/profiler.h @@ -59,11 +59,9 @@ public: void End(ProfilerListener* listener); // Add a profiler event to the queue. - // Return true if the even has been added to the event queue - // or false if the queue is full. // You can control the maximum number of profiler events using // MAX_PROFILER_EVENTS. - bool PushEvent(const char* name); + void PushEvent(const char* name); // Remove the top profiler event. void PopEvent(); diff --git a/examples/testbed/framework/recorder_profiler.cpp b/examples/testbed/framework/recorder_profiler.cpp index 8b126cb..886689c 100644 --- a/examples/testbed/framework/recorder_profiler.cpp +++ b/examples/testbed/framework/recorder_profiler.cpp @@ -22,18 +22,37 @@ RecorderProfiler* g_profilerRecorder = nullptr; void RecorderProfiler::BeginEvents() { + m_count = 0; for (u32 i = 0; i < m_records.Count(); ++i) { m_records[i].elapsed = 0.0; + m_records[i].call = 0; } } void RecorderProfiler::EndEvents() { + for (u32 i = 0; i < m_records.Count(); ++i) + { + ProfilerRecord& r1 = m_records[i]; + + for (u32 j = i + 1; j < m_records.Count(); ++j) + { + ProfilerRecord& r2 = m_records[j]; + + if (r2.call < r1.call) + { + b3Swap(r1, r2); + break; + } + } + } } void RecorderProfiler::Add(const char* name, float64 elapsedTime) { + m_count += 1; + for (u32 i = 0; i < m_records.Count(); ++i) { ProfilerRecord& r = m_records[i]; @@ -41,14 +60,16 @@ void RecorderProfiler::Add(const char* name, float64 elapsedTime) { r.elapsed += elapsedTime; r.maxElapsed = b3Max(r.maxElapsed, elapsedTime); + r.call = m_count; return; } } ProfilerRecord r; r.name = name; - r.elapsed = 0.0; - r.maxElapsed = 0.0; + r.elapsed = elapsedTime; + r.maxElapsed = elapsedTime; + r.call = m_count; m_records.PushBack(r); } \ No newline at end of file diff --git a/examples/testbed/framework/recorder_profiler.h b/examples/testbed/framework/recorder_profiler.h index 5291901..0c74e41 100644 --- a/examples/testbed/framework/recorder_profiler.h +++ b/examples/testbed/framework/recorder_profiler.h @@ -28,6 +28,7 @@ struct ProfilerRecord float64 elapsed; float64 maxElapsed; const char* name; + u32 call; }; // The profiler recorder simply keeps profile events in an event buffer, @@ -45,6 +46,7 @@ public: const b3Array& GetRecords() const { return m_records; } private: b3StackArray m_records; + u32 m_count; }; extern RecorderProfiler* g_profilerRecorder; diff --git a/examples/testbed/framework/test.cpp b/examples/testbed/framework/test.cpp index 39170c1..befad6c 100644 --- a/examples/testbed/framework/test.cpp +++ b/examples/testbed/framework/test.cpp @@ -25,20 +25,14 @@ extern u32 b3_convexCalls, b3_convexCacheHits; extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters; extern bool b3_convexCache; -static bool push_ok = false; - void b3BeginProfileScope(const char* name) { - push_ok = g_profiler->PushEvent(name); + g_profiler->PushEvent(name); } void b3EndProfileScope() { - if (push_ok) - { - g_profiler->PopEvent(); - push_ok = false; - } + g_profiler->PopEvent(); } Test::Test() : diff --git a/src/bounce/dynamics/cloth/cloth.cpp b/src/bounce/dynamics/cloth/cloth.cpp index 95632c0..bd526a9 100644 --- a/src/bounce/dynamics/cloth/cloth.cpp +++ b/src/bounce/dynamics/cloth/cloth.cpp @@ -509,7 +509,7 @@ bool b3Cloth::RayCast(b3RayCastOutput* output, const b3RayCastInput* input, u32 void b3Cloth::UpdateBodyContacts() { - B3_PROFILE("Update Body Contacts"); + B3_PROFILE("Cloth Update Body Contacts"); // Clear buffer b3BodyContact* c = m_bodyContactList.m_head; @@ -588,7 +588,7 @@ void b3Cloth::UpdateBodyContacts() void b3Cloth::UpdateParticleContacts() { - B3_PROFILE("Update Particle Contacts"); + B3_PROFILE("Cloth Update Particle Contacts"); // Clear buffer b3ParticleContact* c = m_particleContactList.m_head; @@ -790,7 +790,7 @@ static B3_FORCE_INLINE void b3Solve3(float32 out[3], void b3Cloth::UpdateTriangleContacts() { - B3_PROFILE("Update Triangle Contacts"); + B3_PROFILE("Cloth Update Triangle Contacts"); // Clear buffer b3TriangleContact* c = m_triangleContactList.m_head; @@ -883,7 +883,7 @@ void b3Cloth::UpdateTriangleContacts() void b3Cloth::Solve(float32 dt, const b3Vec3& gravity) { - B3_PROFILE("Solve"); + B3_PROFILE("Cloth Solve"); // Solve b3ClothSolverDef solverDef; @@ -946,7 +946,7 @@ void b3Cloth::UpdateContacts() void b3Cloth::Step(float32 dt, const b3Vec3& gravity) { - B3_PROFILE("Step"); + B3_PROFILE("Cloth Step"); // Update contacts UpdateContacts(); diff --git a/src/bounce/dynamics/cloth/cloth_solver.cpp b/src/bounce/dynamics/cloth/cloth_solver.cpp index 763031f..e4d66b2 100644 --- a/src/bounce/dynamics/cloth/cloth_solver.cpp +++ b/src/bounce/dynamics/cloth/cloth_solver.cpp @@ -359,7 +359,7 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity) void b3ClothSolver::Solve(b3DenseVec3& x, u32& iterations, const b3SparseSymMat33& A, const b3DenseVec3& b, const b3DiagMat33& S, const b3DenseVec3& z, const b3DenseVec3& y) const { - B3_PROFILE("Solve Ax = b"); + B3_PROFILE("Cloth Solve Ax = b"); // P = diag(A) b3DiagMat33 inv_P(m_particleCount);