removed a couple of bugs in the profiler
This commit is contained in:
parent
c0e324c988
commit
b48b16843a
@ -124,9 +124,13 @@ static void Run()
|
|||||||
for (u32 i = 0; i < records.Count(); ++i)
|
for (u32 i = 0; i < records.Count(); ++i)
|
||||||
{
|
{
|
||||||
const ProfilerRecord& r = records[i];
|
const ProfilerRecord& r = records[i];
|
||||||
|
|
||||||
|
if (r.elapsed > 0.0)
|
||||||
|
{
|
||||||
g_draw->DrawString(b3Color_white, "%s %.4f (%.4f) [ms]", r.name, r.elapsed, r.maxElapsed);
|
g_draw->DrawString(b3Color_white, "%s %.4f (%.4f) [ms]", r.name, r.elapsed, r.maxElapsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_view->Interface();
|
g_view->Interface();
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ Profiler::~Profiler()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Profiler::PushEvent(const char* name)
|
void Profiler::PushEvent(const char* name)
|
||||||
{
|
{
|
||||||
m_time.Update();
|
m_time.Update();
|
||||||
|
|
||||||
@ -43,12 +43,8 @@ bool Profiler::PushEvent(const char* name)
|
|||||||
e.parent = m_top;
|
e.parent = m_top;
|
||||||
|
|
||||||
ProfilerEvent* back = m_events.Push(e);
|
ProfilerEvent* back = m_events.Push(e);
|
||||||
if (back)
|
B3_ASSERT(back);
|
||||||
{
|
|
||||||
m_top = back;
|
m_top = back;
|
||||||
}
|
|
||||||
|
|
||||||
return back != NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Profiler::PopEvent()
|
void Profiler::PopEvent()
|
||||||
@ -66,26 +62,37 @@ void Profiler::Begin()
|
|||||||
{
|
{
|
||||||
// If this assert is hit then it means Profiler::End hasn't been called.
|
// If this assert is hit then it means Profiler::End hasn't been called.
|
||||||
B3_ASSERT(m_events.IsEmpty());
|
B3_ASSERT(m_events.IsEmpty());
|
||||||
|
B3_ASSERT(m_top == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Profiler::End(ProfilerListener* listener)
|
void Profiler::End(ProfilerListener* listener)
|
||||||
{
|
{
|
||||||
|
if (listener)
|
||||||
|
{
|
||||||
listener->BeginEvents();
|
listener->BeginEvents();
|
||||||
|
}
|
||||||
|
|
||||||
while (m_events.IsEmpty() == false)
|
while (m_events.IsEmpty() == false)
|
||||||
{
|
{
|
||||||
const ProfilerEvent& e = m_events.Front();
|
ProfilerEvent e = m_events.Front();
|
||||||
|
|
||||||
m_events.Pop();
|
m_events.Pop();
|
||||||
|
|
||||||
|
if (listener)
|
||||||
|
{
|
||||||
listener->BeginEvent(e.tid, e.pid, e.name, e.t0);
|
listener->BeginEvent(e.tid, e.pid, e.name, e.t0);
|
||||||
|
|
||||||
listener->EndEvent(e.tid, e.pid, e.name, e.t1);
|
listener->EndEvent(e.tid, e.pid, e.name, e.t1);
|
||||||
|
|
||||||
listener->Duration(e.name, e.t1 - e.t0);
|
listener->Duration(e.name, e.t1 - e.t0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
B3_ASSERT(m_events.IsEmpty());
|
B3_ASSERT(m_events.IsEmpty());
|
||||||
|
B3_ASSERT(m_top == NULL);
|
||||||
|
|
||||||
|
if (listener)
|
||||||
|
{
|
||||||
listener->EndEvents();
|
listener->EndEvents();
|
||||||
|
}
|
||||||
}
|
}
|
@ -59,11 +59,9 @@ public:
|
|||||||
void End(ProfilerListener* listener);
|
void End(ProfilerListener* listener);
|
||||||
|
|
||||||
// Add a profiler event to the queue.
|
// 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
|
// You can control the maximum number of profiler events using
|
||||||
// MAX_PROFILER_EVENTS.
|
// MAX_PROFILER_EVENTS.
|
||||||
bool PushEvent(const char* name);
|
void PushEvent(const char* name);
|
||||||
|
|
||||||
// Remove the top profiler event.
|
// Remove the top profiler event.
|
||||||
void PopEvent();
|
void PopEvent();
|
||||||
|
@ -22,18 +22,37 @@ RecorderProfiler* g_profilerRecorder = nullptr;
|
|||||||
|
|
||||||
void RecorderProfiler::BeginEvents()
|
void RecorderProfiler::BeginEvents()
|
||||||
{
|
{
|
||||||
|
m_count = 0;
|
||||||
for (u32 i = 0; i < m_records.Count(); ++i)
|
for (u32 i = 0; i < m_records.Count(); ++i)
|
||||||
{
|
{
|
||||||
m_records[i].elapsed = 0.0;
|
m_records[i].elapsed = 0.0;
|
||||||
|
m_records[i].call = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecorderProfiler::EndEvents()
|
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)
|
void RecorderProfiler::Add(const char* name, float64 elapsedTime)
|
||||||
{
|
{
|
||||||
|
m_count += 1;
|
||||||
|
|
||||||
for (u32 i = 0; i < m_records.Count(); ++i)
|
for (u32 i = 0; i < m_records.Count(); ++i)
|
||||||
{
|
{
|
||||||
ProfilerRecord& r = m_records[i];
|
ProfilerRecord& r = m_records[i];
|
||||||
@ -41,14 +60,16 @@ void RecorderProfiler::Add(const char* name, float64 elapsedTime)
|
|||||||
{
|
{
|
||||||
r.elapsed += elapsedTime;
|
r.elapsed += elapsedTime;
|
||||||
r.maxElapsed = b3Max(r.maxElapsed, elapsedTime);
|
r.maxElapsed = b3Max(r.maxElapsed, elapsedTime);
|
||||||
|
r.call = m_count;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfilerRecord r;
|
ProfilerRecord r;
|
||||||
r.name = name;
|
r.name = name;
|
||||||
r.elapsed = 0.0;
|
r.elapsed = elapsedTime;
|
||||||
r.maxElapsed = 0.0;
|
r.maxElapsed = elapsedTime;
|
||||||
|
r.call = m_count;
|
||||||
|
|
||||||
m_records.PushBack(r);
|
m_records.PushBack(r);
|
||||||
}
|
}
|
@ -28,6 +28,7 @@ struct ProfilerRecord
|
|||||||
float64 elapsed;
|
float64 elapsed;
|
||||||
float64 maxElapsed;
|
float64 maxElapsed;
|
||||||
const char* name;
|
const char* name;
|
||||||
|
u32 call;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The profiler recorder simply keeps profile events in an event buffer,
|
// The profiler recorder simply keeps profile events in an event buffer,
|
||||||
@ -45,6 +46,7 @@ public:
|
|||||||
const b3Array<ProfilerRecord>& GetRecords() const { return m_records; }
|
const b3Array<ProfilerRecord>& GetRecords() const { return m_records; }
|
||||||
private:
|
private:
|
||||||
b3StackArray<ProfilerRecord, 256> m_records;
|
b3StackArray<ProfilerRecord, 256> m_records;
|
||||||
|
u32 m_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern RecorderProfiler* g_profilerRecorder;
|
extern RecorderProfiler* g_profilerRecorder;
|
||||||
|
@ -25,20 +25,14 @@ extern u32 b3_convexCalls, b3_convexCacheHits;
|
|||||||
extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters;
|
extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters;
|
||||||
extern bool b3_convexCache;
|
extern bool b3_convexCache;
|
||||||
|
|
||||||
static bool push_ok = false;
|
|
||||||
|
|
||||||
void b3BeginProfileScope(const char* name)
|
void b3BeginProfileScope(const char* name)
|
||||||
{
|
{
|
||||||
push_ok = g_profiler->PushEvent(name);
|
g_profiler->PushEvent(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void b3EndProfileScope()
|
void b3EndProfileScope()
|
||||||
{
|
{
|
||||||
if (push_ok)
|
|
||||||
{
|
|
||||||
g_profiler->PopEvent();
|
g_profiler->PopEvent();
|
||||||
push_ok = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Test::Test() :
|
Test::Test() :
|
||||||
|
@ -509,7 +509,7 @@ bool b3Cloth::RayCast(b3RayCastOutput* output, const b3RayCastInput* input, u32
|
|||||||
|
|
||||||
void b3Cloth::UpdateBodyContacts()
|
void b3Cloth::UpdateBodyContacts()
|
||||||
{
|
{
|
||||||
B3_PROFILE("Update Body Contacts");
|
B3_PROFILE("Cloth Update Body Contacts");
|
||||||
|
|
||||||
// Clear buffer
|
// Clear buffer
|
||||||
b3BodyContact* c = m_bodyContactList.m_head;
|
b3BodyContact* c = m_bodyContactList.m_head;
|
||||||
@ -588,7 +588,7 @@ void b3Cloth::UpdateBodyContacts()
|
|||||||
|
|
||||||
void b3Cloth::UpdateParticleContacts()
|
void b3Cloth::UpdateParticleContacts()
|
||||||
{
|
{
|
||||||
B3_PROFILE("Update Particle Contacts");
|
B3_PROFILE("Cloth Update Particle Contacts");
|
||||||
|
|
||||||
// Clear buffer
|
// Clear buffer
|
||||||
b3ParticleContact* c = m_particleContactList.m_head;
|
b3ParticleContact* c = m_particleContactList.m_head;
|
||||||
@ -790,7 +790,7 @@ static B3_FORCE_INLINE void b3Solve3(float32 out[3],
|
|||||||
|
|
||||||
void b3Cloth::UpdateTriangleContacts()
|
void b3Cloth::UpdateTriangleContacts()
|
||||||
{
|
{
|
||||||
B3_PROFILE("Update Triangle Contacts");
|
B3_PROFILE("Cloth Update Triangle Contacts");
|
||||||
|
|
||||||
// Clear buffer
|
// Clear buffer
|
||||||
b3TriangleContact* c = m_triangleContactList.m_head;
|
b3TriangleContact* c = m_triangleContactList.m_head;
|
||||||
@ -883,7 +883,7 @@ void b3Cloth::UpdateTriangleContacts()
|
|||||||
|
|
||||||
void b3Cloth::Solve(float32 dt, const b3Vec3& gravity)
|
void b3Cloth::Solve(float32 dt, const b3Vec3& gravity)
|
||||||
{
|
{
|
||||||
B3_PROFILE("Solve");
|
B3_PROFILE("Cloth Solve");
|
||||||
|
|
||||||
// Solve
|
// Solve
|
||||||
b3ClothSolverDef solverDef;
|
b3ClothSolverDef solverDef;
|
||||||
@ -946,7 +946,7 @@ void b3Cloth::UpdateContacts()
|
|||||||
|
|
||||||
void b3Cloth::Step(float32 dt, const b3Vec3& gravity)
|
void b3Cloth::Step(float32 dt, const b3Vec3& gravity)
|
||||||
{
|
{
|
||||||
B3_PROFILE("Step");
|
B3_PROFILE("Cloth Step");
|
||||||
|
|
||||||
// Update contacts
|
// Update contacts
|
||||||
UpdateContacts();
|
UpdateContacts();
|
||||||
|
@ -359,7 +359,7 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
|
|||||||
void b3ClothSolver::Solve(b3DenseVec3& x, u32& iterations,
|
void b3ClothSolver::Solve(b3DenseVec3& x, u32& iterations,
|
||||||
const b3SparseSymMat33& A, const b3DenseVec3& b, const b3DiagMat33& S, const b3DenseVec3& z, const b3DenseVec3& y) const
|
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)
|
// P = diag(A)
|
||||||
b3DiagMat33 inv_P(m_particleCount);
|
b3DiagMat33 inv_P(m_particleCount);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user