removed a couple of bugs in the profiler

This commit is contained in:
Irlan 2018-10-07 20:48:26 -03:00
parent c0e324c988
commit b48b16843a
8 changed files with 60 additions and 34 deletions

View File

@ -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);
}
}
}

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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);
}

View File

@ -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<ProfilerRecord>& GetRecords() const { return m_records; }
private:
b3StackArray<ProfilerRecord, 256> m_records;
u32 m_count;
};
extern RecorderProfiler* g_profilerRecorder;

View File

@ -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() :

View File

@ -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();

View File

@ -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);