added performance info for various game sections using: ShowInGamePerformance=true

This commit is contained in:
Mark Vejvoda
2013-11-11 01:42:27 +00:00
parent d32de80491
commit ed94e9578c
4 changed files with 113 additions and 2 deletions

View File

@@ -1777,6 +1777,7 @@ void Game::update() {
perfList.push_back(perfBuf); perfList.push_back(perfBuf);
} }
Chrono chronoGamePerformanceCounts;
Chrono chrono; Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
@@ -1851,6 +1852,7 @@ void Game::update() {
//updateLoops = 80; //updateLoops = 80;
} }
chronoGamePerformanceCounts.start();
//NetworkManager &networkManager= NetworkManager::getInstance(); //NetworkManager &networkManager= NetworkManager::getInstance();
bool enableServerControlledAI = this->gameSettings.getEnableServerControlledAI(); bool enableServerControlledAI = this->gameSettings.getEnableServerControlledAI();
//bool isNetworkGame = this->gameSettings.isNetworkGame(); //bool isNetworkGame = this->gameSettings.isNetworkGame();
@@ -1983,6 +1985,10 @@ void Game::update() {
} }
} }
gamePerformanceCounts["CalculateNetorkUpdateLoops"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["CalculateNetorkUpdateLoops"] / 2;
chronoGamePerformanceCounts.stop();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
@@ -2033,8 +2039,13 @@ void Game::update() {
//AiInterface //AiInterface
if(commander.hasReplayCommandListForFrame() == false) { if(commander.hasReplayCommandListForFrame() == false) {
chronoGamePerformanceCounts.start();
processNetworkSynchChecksIfRequired(); processNetworkSynchChecksIfRequired();
gamePerformanceCounts["CalculateNetorkCRCSynchChecks"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["CalculateNetorkCRCSynchChecks"] / 2;
chronoGamePerformanceCounts.stop();
/* /*
for(int j = 0; j < world.getFactionCount(); ++j) { for(int j = 0; j < world.getFactionCount(); ++j) {
Faction *faction = world.getFaction(j); Faction *faction = world.getFaction(j);
@@ -2063,6 +2074,8 @@ void Game::update() {
} }
else { else {
// Signal the faction threads to do any pre-processing // Signal the faction threads to do any pre-processing
chronoGamePerformanceCounts.start();
bool hasAIPlayer = false; bool hasAIPlayer = false;
for(int j = 0; j < world.getFactionCount(); ++j) { for(int j = 0; j < world.getFactionCount(); ++j) {
Faction *faction = world.getFaction(j); Faction *faction = world.getFaction(j);
@@ -2113,6 +2126,9 @@ void Game::update() {
} }
} }
} }
gamePerformanceCounts["ProcessAIWorkerThreads"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessAIWorkerThreads"] / 2;
chronoGamePerformanceCounts.stop();
} }
if(showPerfStats) { if(showPerfStats) {
@@ -2173,7 +2189,13 @@ void Game::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
//World //World
chronoGamePerformanceCounts.start();
if(pendingQuitError == false) world.update(); if(pendingQuitError == false) world.update();
gamePerformanceCounts["ProcessWorldUpdate"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessWorldUpdate"] / 2;
chronoGamePerformanceCounts.stop();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [world update i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [world update i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@@ -2182,7 +2204,7 @@ void Game::update() {
perfList.push_back(perfBuf); perfList.push_back(perfBuf);
} }
if(currentCameraFollowUnit!=NULL){ if(currentCameraFollowUnit != NULL) {
Vec3f c=currentCameraFollowUnit->getCurrVector(); Vec3f c=currentCameraFollowUnit->getCurrVector();
int rotation=currentCameraFollowUnit->getRotation(); int rotation=currentCameraFollowUnit->getRotation();
float angle=rotation+180; float angle=rotation+180;
@@ -2209,9 +2231,13 @@ void Game::update() {
} }
// Commander // Commander
//commander.updateNetwork(); chronoGamePerformanceCounts.start();
if(pendingQuitError == false) commander.signalNetworkUpdate(this); if(pendingQuitError == false) commander.signalNetworkUpdate(this);
gamePerformanceCounts["ProcessNetworkUpdate"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessNetworkUpdate"] / 2;
chronoGamePerformanceCounts.stop();
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf); perfList.push_back(perfBuf);
@@ -2221,7 +2247,13 @@ void Game::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
//Gui //Gui
chronoGamePerformanceCounts.start();
gui.update(); gui.update();
gamePerformanceCounts["ProcessGUIUpdate"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessGUIUpdate"] / 2;
chronoGamePerformanceCounts.stop();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [gui updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [gui updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@@ -2244,7 +2276,14 @@ void Game::update() {
} }
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
chronoGamePerformanceCounts.start();
renderer.updateParticleManager(rsGame,avgRenderFps); renderer.updateParticleManager(rsGame,avgRenderFps);
gamePerformanceCounts["ProcessParticleManager"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessParticleManager"] / 2;
chronoGamePerformanceCounts.stop();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [particle manager updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [particle manager updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@@ -2275,6 +2314,8 @@ void Game::update() {
perfList.push_back(perfBuf); perfList.push_back(perfBuf);
} }
chronoGamePerformanceCounts.start();
//call the chat manager //call the chat manager
chatManager.updateNetwork(); chatManager.updateNetwork();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [chatManager.updateNetwork]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [chatManager.updateNetwork]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
@@ -2309,6 +2350,9 @@ void Game::update() {
perfList.push_back(perfBuf); perfList.push_back(perfBuf);
} }
gamePerformanceCounts["ProcessMiscNetwork"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessMiscNetwork"] / 2;
chronoGamePerformanceCounts.stop();
// START - Handle joining in progress games // START - Handle joining in progress games
if(role == nrServer) { if(role == nrServer) {
ServerInterface *server = NetworkManager::getInstance().getServerInterface(); ServerInterface *server = NetworkManager::getInstance().getServerInterface();
@@ -2756,6 +2800,22 @@ void Game::update() {
} }
} }
string Game::getGamePerformanceCounts() const {
if(gamePerformanceCounts.empty() == true) {
return "";
}
string result = "";
for(std::map<string,int64>::const_iterator iterMap = gamePerformanceCounts.begin();
iterMap != gamePerformanceCounts.end(); ++iterMap) {
if(result != "") {
result += "\n";
}
result += iterMap->first + " = avg millis: " + intToStr(iterMap->second);
}
return result;
}
bool Game::switchSetupForSlots(ServerInterface *& serverInterface, bool Game::switchSetupForSlots(ServerInterface *& serverInterface,
int startIndex, int endIndex, bool onlyNetworkUnassigned) { int startIndex, int endIndex, bool onlyNetworkUnassigned) {
bool switchRequested = false; bool switchRequested = false;
@@ -5500,6 +5560,8 @@ void Game::render2d() {
renderer.renderClock(); renderer.renderClock();
} }
renderer.renderPerformanceStats();
//resource info //resource info
if(photoModeEnabled == false) { if(photoModeEnabled == false) {
if(this->masterserverMode == false) { if(this->masterserverMode == false) {

View File

@@ -211,6 +211,8 @@ private:
bool quitGameCalled; bool quitGameCalled;
bool disableSpeedChange; bool disableSpeedChange;
std::map<string,int64> gamePerformanceCounts;
public: public:
Game(); Game();
Game(Program *program, const GameSettings *gameSettings, bool masterserverMode); Game(Program *program, const GameSettings *gameSettings, bool masterserverMode);
@@ -336,6 +338,8 @@ public:
bool getDisableSpeedChange() const { return disableSpeedChange; } bool getDisableSpeedChange() const { return disableSpeedChange; }
void setDisableSpeedChange(bool value) { disableSpeedChange = value; } void setDisableSpeedChange(bool value) { disableSpeedChange = value; }
string getGamePerformanceCounts() const;
private: private:
//render //render
void render3d(); void render3d();

View File

@@ -2217,6 +2217,50 @@ void Renderer::renderChatManager(const ChatManager *chatManager) {
} }
} }
void Renderer::renderPerformanceStats() {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
return;
}
Config &config= Config::getInstance();
if(config.getBool("ShowInGamePerformance","false") == false) {
return;
}
const Metrics &metrics = Metrics::getInstance();
const World *world = game->getWorld();
const Vec4f fontColor = game->getGui()->getDisplay()->getColor();
char szBuf[200]="";
snprintf(szBuf,200,"Frame: %d",game->getWorld()->getFrameCount() / 20);
string str = string(szBuf) + string("\n");
static time_t lastGamePerfCheck = time(NULL);
static string gamePerfStats = "";
if(difftime((long int)time(NULL),lastGamePerfCheck) > 3) {
lastGamePerfCheck = time(NULL);
gamePerfStats = game->getGamePerformanceCounts();
}
if(gamePerfStats != "") {
str += gamePerfStats + "\n";
}
if(renderText3DEnabled == true) {
renderTextShadow3D(
str, CoreData::getInstance().getDisplayFontSmall3D(),
fontColor,
10, metrics.getVirtualH()-180, false);
}
else {
renderTextShadow(
str, CoreData::getInstance().getDisplayFontSmall(),
fontColor,
10, metrics.getVirtualH()-180, false);
}
}
void Renderer::renderClock() { void Renderer::renderClock() {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
return; return;

View File

@@ -502,6 +502,7 @@ public:
void renderChatManager(const ChatManager *chatManager); void renderChatManager(const ChatManager *chatManager);
void renderClock(); void renderClock();
void renderPerformanceStats();
void renderResourceStatus(); void renderResourceStatus();
void renderSelectionQuad(); void renderSelectionQuad();
void renderText(const string &text, Font2D *font, float alpha, int x, int y, bool centered= false); void renderText(const string &text, Font2D *font, float alpha, int x, int y, bool centered= false);