6 Commits

Author SHA1 Message Date
Stiffly 89555fa0aa Merge remote-tracking branch 'origin/master' into Benchmarking
Conflicts:
	include/Core/Engine.h
	src/game/Game/LevelSystem.cpp
2015-09-24 20:41:53 +02:00
Stiffly c98887fa68 Time metrics for the Update-functions in Enginge::Tick(). 2015-09-24 20:34:21 +02:00
Stiffly 14d133bd31 Metrics for individual systems. Press N 2015-09-24 17:25:14 +02:00
Stiffly 086bdbce70 Accumulated measures of Events, Update, Recursive Updates. 2015-09-23 17:19:57 +02:00
Stiffly 2cf54819ae Printing some numbers 2015-09-23 15:37:14 +02:00
Stiffly 683b4cc3cf Printing system names. 2015-09-23 15:17:20 +02:00
4 changed files with 157 additions and 5 deletions
+72
View File
@@ -52,6 +52,7 @@
#include "Physics/CBoxShape.h"
#include "Physics/ESetImpulse.h"
#include "Core/EKeyDown.h"
namespace dd
{
@@ -227,6 +228,9 @@ public:
m_World->CommitEntity(ent);
}
//EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
m_EKeyDown = decltype(m_EKeyDown)(std::bind(&Engine::OnKeyDown, this, std::placeholders::_1));
m_EventBroker->Subscribe(m_EKeyDown);
m_LastTime = glfwGetTime();
}
@@ -238,12 +242,24 @@ public:
double dt = currentTime - m_LastTime;
m_LastTime = currentTime;
double start = glfwGetTime();
ResourceManager::Update();
double stop = glfwGetTime();
double time = stop - start;
tm.resourceManagerT += time;
// Update input
start = glfwGetTime();
m_InputManager->Update(dt);
stop = glfwGetTime();
time = stop - start;
tm.inputManagerT += time;
start = glfwGetTime();
m_World->Update(dt);
stop = glfwGetTime();
time = stop - start;
tm.worldT += time;
//
@@ -263,11 +279,21 @@ public:
}
//TODO Fill up the renderQueue with models (Temp fix)
start = glfwGetTime();
TEMPAddToRenderQueue();
stop = glfwGetTime();
time = stop - start;
tm.addToRenderQueueT += time;
// Render scene
//TODO send renderqueue to draw.
start = glfwGetTime();
m_Renderer->Draw(m_RendererQueue);
stop = glfwGetTime();
time = stop - start;
tm.rendererT += time;
m_EventBroker->Process<Engine>();
// Swap event queues
m_EventBroker->Clear();
@@ -416,6 +442,52 @@ private:
std::shared_ptr<InputManager> m_InputManager;
std::shared_ptr<World> m_World;
struct TickMetric
{
double resourceManagerT = 0;
double inputManagerT = 0;
double worldT = 0;
double addToRenderQueueT = 0;
double rendererT = 0;
double Total()
{
return resourceManagerT
+ inputManagerT
+ worldT
+ addToRenderQueueT
+ rendererT;
};
};
TickMetric tm;
dd::EventRelay<Engine, dd::Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const dd::Events::KeyDown &event)
{
if (event.KeyCode == 78)
{
double total = tm.Total();
std::ofstream outFile;
outFile.open("../tools/engine-metrics.txt");
outFile.clear();
outFile << "----------------------- Time measurements -----------------------\n";
outFile << "Type: ResourceManager->Update()" << std::endl;
outFile << "Total: " << tm.resourceManagerT / total * 100 << " %" << std::endl << std::endl;
outFile << "Type: InputManager->Update()" << std::endl;
outFile << "Total: " << tm.inputManagerT / total * 100 << " %" << std::endl << std::endl;
outFile << "Type: World->Update()" << std::endl;
outFile << "Total: " << tm.worldT / total * 100 << " %" << std::endl << std::endl;
outFile << "Type: AddToRenderQueue()" << std::endl;
outFile << "Total: " << tm.addToRenderQueueT / total * 100 << " %" << std::endl << std::endl;
outFile << "Type: Renderer->Draw()" << std::endl;
outFile << "Total: " << tm.rendererT / total * 100 << " %" << std::endl << std::endl;
outFile << "-----------------------------------------------------------------";
outFile.close();
return true;
}
};
double m_LastTime;
};
+15
View File
@@ -37,6 +37,8 @@
#include "EComponentCreated.h"
#include "ResourceManager.h"
#include "EKeyDown.h"
namespace dd
{
@@ -52,6 +54,10 @@ public:
, m_LastEntityID(0) { }
~World() { }
dd::EventRelay<World, dd::Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const dd::Events::KeyDown &event);
/** Initialize the world.
@@ -248,6 +254,15 @@ protected:
EntityID GenerateEntityID();
void RecycleEntityID(EntityID id);
private:
//Benchmarking
struct TimeMeasure {
double EventTime;
double SystemTime;
double RSystemTime;
};
std::map<std::string, TimeMeasure> m_typeToTimeMap;
};
template <class T>
+69 -4
View File
@@ -58,11 +58,36 @@ void dd::World::Update(double dt)
{
const std::string &type = pair.first;
auto system = pair.second;
EventBroker->Process(type);
system->Update(dt);
RecursiveUpdate(system, dt, 0);
}
std::map<std::string, TimeMeasure>::iterator it = m_typeToTimeMap.find(type.c_str());
if (it == m_typeToTimeMap.end()) {
//Does not contain item
TimeMeasure t;
t.EventTime = 0;
t.SystemTime = 0;
t.RSystemTime = 0;
m_typeToTimeMap[type.c_str()] = t;
}
double start = glfwGetTime();
EventBroker->Process(type);
double stop = glfwGetTime();
double t1 = stop - start;
m_typeToTimeMap[type.c_str()].EventTime += t1;
start = glfwGetTime();
system->Update(dt);
stop = glfwGetTime();
double t2 = stop - start;
m_typeToTimeMap[type.c_str()].SystemTime += t2;
start = glfwGetTime();
RecursiveUpdate(system, dt, 0);
stop = glfwGetTime();
double t3 = stop - start;
m_typeToTimeMap[type.c_str()].RSystemTime += t3;
}
EventBroker->Process<World>();
ProcessEntityRemovals();
}
@@ -161,6 +186,8 @@ void dd::World::Initialize()
system->RegisterResourceTypes(ResourceManager);
system->Initialize();
}
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &World::OnKeyDown);
}
int dd::World::CommitEntity(EntityID entity)
@@ -232,3 +259,41 @@ void dd::World::SetEntityParent(EntityID entity, EntityID newParent)
m_EntityParents[entity] = newParent;
m_EntityChildren[newParent].push_back(entity);
}
bool dd::World::OnKeyDown(const dd::Events::KeyDown &event)
{
if (event.KeyCode == 78)
{
double eventTot = 0;
double updateTot = 0;
double rUpdateTot = 0;
double total = 0;
for (auto item : m_typeToTimeMap)
{
eventTot += item.second.EventTime;
updateTot += item.second.SystemTime;
rUpdateTot += item.second.RSystemTime;
}
total = eventTot + updateTot + rUpdateTot;
std::ofstream outFile;
outFile.open("../tools/system-metrics.txt");
outFile.clear();
outFile << "----------------------- Time measurements -----------------------\n";
for (auto item : m_typeToTimeMap)
{
outFile << "Type: " << item.first.c_str() << std::endl;
outFile << "Events: " << item.second.EventTime << " s. " << item.second.EventTime / eventTot * 100 << " % of total event time.\n";
outFile << "Update: " << item.second.SystemTime << " s. " << item.second.SystemTime / updateTot * 100 << " % of total update time.\n";
outFile << "Recursive Update: " << item.second.RSystemTime << " s. " << item.second.RSystemTime / rUpdateTot * 100 << " % of total recursive update time.\n";
double totalComplexity = (item.second.EventTime + item.second.SystemTime + item.second.RSystemTime) / total * 100;
outFile << "Total: " << totalComplexity << "% total system time." << std::endl << std::endl;
}
outFile << "-----------------------------------------------------------------";
outFile.close();
return true;
}
//return false;
}
+1 -1
View File
@@ -275,7 +275,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
es.Score = brick->Score;
EventBroker->Publish(es);
std::cout << NumberOfBricks() << std::endl;
//std::cout << NumberOfBricks() << std::endl;
//std::cout << "Score: " << Score() << std::endl;
}