Metrics for individual systems. Press N

This commit is contained in:
Stiffly
2015-09-24 17:25:14 +02:00
parent 086bdbce70
commit 14d133bd31
4 changed files with 49 additions and 10 deletions
+6
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.
+41 -8
View File
@@ -87,14 +87,7 @@ void dd::World::Update(double dt)
double t3 = stop - start;
m_typeToTimeMap[type.c_str()].RSystemTime += t3;
}
for (auto item : m_typeToTimeMap)
{
LOG_INFO("Type %s", item.first.c_str());
LOG_INFO("Events: %f", item.second.EventTime);
LOG_INFO("Systems: %f", item.second.SystemTime);
LOG_INFO("Recursive Systems: %f", item.second.RSystemTime);
}
EventBroker->Process<World>();
ProcessEntityRemovals();
}
@@ -193,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)
@@ -264,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
@@ -162,7 +162,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
es.Score = brick->Score;
EventBroker->Publish(es);
std::cout << "Score: " << Score() << std::endl;
//std::cout << "Score: " << Score() << std::endl;
return true;
}
+1 -1
View File
@@ -100,7 +100,7 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
//Play
//alSourcePlay(source);
alSourcePlay(source);
return true;
}