From cc5c56d545c0735d28a99b89d4970bd507608f7f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 28 Sep 2013 20:36:01 +0100 Subject: Minor startup streamlining * LOGD'd unneeded debugging messages, streamlining startup + Added a basic timer for how long in seconds it took to start up + Added two checks for plural (plugin/s, second/s) --- source/Root.cpp | 64 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'source/Root.cpp') diff --git a/source/Root.cpp b/source/Root.cpp index 3933535f1..24ff77e42 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -21,6 +21,7 @@ #include "../iniFile/iniFile.h" #include +#include @@ -91,6 +92,17 @@ void cRoot::InputThread(void * a_Params) void cRoot::Start(void) { + time_t timer; + struct tm y2k; + double seconds; + double finishseconds; + + y2k.tm_hour = 0; y2k.tm_min = 0; y2k.tm_sec = 0; + y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1; + + time(&timer); + seconds = difftime(timer,mktime(&y2k)); + cDeadlockDetect dd; delete m_Log; m_Log = new cMCLogger(); @@ -125,7 +137,7 @@ void cRoot::Start(void) LOG("Starting server..."); if (!m_Server->InitServer(IniFile)) { - LOGERROR("Failed to start server, shutting down."); + LOGERROR("Failure starting server, aborting..."); return; } IniFile.WriteFile(); @@ -138,45 +150,51 @@ void cRoot::Start(void) if (WebIniFile.GetValueB("WebAdmin", "Enabled", false)) { - LOG("Creating WebAdmin..."); + LOGD("Creating WebAdmin..."); m_WebAdmin = new cWebAdmin(8080); } - LOG("Loading settings..."); + LOGD("Loading settings..."); m_GroupManager = new cGroupManager(); m_CraftingRecipes = new cCraftingRecipes; m_FurnaceRecipe = new cFurnaceRecipe(); - LOG("Loading worlds..."); + LOGD("Loading worlds..."); LoadWorlds(); - LOG("Loading plugin manager..."); + LOGD("Loading plugin manager..."); m_PluginManager = new cPluginManager(); m_PluginManager->ReloadPluginsNow(); - LOG("Loading MonsterConfig..."); + LOGD("Loading MonsterConfig..."); m_MonsterConfig = new cMonsterConfig; // This sets stuff in motion - LOG("Starting Authenticator..."); + LOGD("Starting Authenticator..."); m_Authenticator.Start(); - LOG("Starting worlds..."); + LOGD("Starting worlds..."); StartWorlds(); - LOG("Starting deadlock detector..."); + LOGD("Starting deadlock detector..."); dd.Start(); - LOG("Starting server..."); + LOGD("Finalising startup..."); m_Server->Start(); #if !defined(ANDROID_NDK) - LOG("Starting InputThread..."); + LOGD("Starting InputThread..."); m_InputThread = new cThread( InputThread, this, "cRoot::InputThread" ); m_InputThread->Start( false ); // We should NOT wait? Otherwise we canīt stop the server from other threads than the input thread #endif - LOG("Initialization done, server running now."); + time(&timer); + finishseconds = difftime(timer,mktime(&y2k)); + finishseconds -= seconds; + + if ((finishseconds > 1) || (finishseconds == 0)) { LOG("Startup complete, took %.f seconds!", finishseconds); } + else { LOG("Startup complete, took 1 second!"); } + while (!m_bStop && !m_bRestart) // These are modified by external threads { cSleep::MilliSleep(1000); @@ -190,37 +208,37 @@ void cRoot::Start(void) LOG("Shutting down server..."); m_Server->Shutdown(); - LOG("Shutting down deadlock detector..."); + LOGD("Shutting down deadlock detector..."); dd.Stop(); - LOG("Stopping world threads..."); + LOGD("Stopping world threads..."); StopWorlds(); - LOG("Stopping authenticator..."); + LOGD("Stopping authenticator..."); m_Authenticator.Stop(); - LOG("Freeing MonsterConfig..."); + LOGD("Freeing MonsterConfig..."); delete m_MonsterConfig; m_MonsterConfig = NULL; - LOG("Stopping WebAdmin..."); + LOGD("Stopping WebAdmin..."); delete m_WebAdmin; m_WebAdmin = NULL; - LOG("Unloading recipes..."); + LOGD("Unloading recipes..."); delete m_FurnaceRecipe; m_FurnaceRecipe = NULL; delete m_CraftingRecipes; m_CraftingRecipes = NULL; - LOG("Forgetting groups..."); + LOGD("Forgetting groups..."); delete m_GroupManager; m_GroupManager = 0; - LOG("Unloading worlds..."); + LOGD("Unloading worlds..."); UnloadWorlds(); - LOG("Stopping plugin manager..."); + LOGD("Stopping plugin manager..."); delete m_PluginManager; m_PluginManager = NULL; cItemHandler::Deinit(); cBlockHandler::Deinit(); - LOG("Destroying server..."); + LOG("Cleaning up..."); //delete HeartBeat; HeartBeat = 0; delete m_Server; m_Server = 0; - LOG("Shutdown done."); + LOG("Shutdown successful!"); } delete m_Log; m_Log = 0; -- cgit v1.2.3 From 9c7cfd29ad435d98ab70ad32282b9ec4dac666cd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 29 Sep 2013 21:37:50 +0100 Subject: Improvements to startup timer As suggested by xoft. Also reverted changes of displayed protocol version. --- source/Root.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'source/Root.cpp') diff --git a/source/Root.cpp b/source/Root.cpp index 24ff77e42..c33af52ad 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -17,11 +17,11 @@ #include "Protocol/ProtocolRecognizer.h" // for protocol version constants #include "CommandOutput.h" #include "DeadlockDetect.h" +#include "OSSupport/Timer.h" #include "../iniFile/iniFile.h" #include -#include @@ -92,16 +92,9 @@ void cRoot::InputThread(void * a_Params) void cRoot::Start(void) { - time_t timer; - struct tm y2k; - double seconds; - double finishseconds; + cTimer Time; - y2k.tm_hour = 0; y2k.tm_min = 0; y2k.tm_sec = 0; - y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1; - - time(&timer); - seconds = difftime(timer,mktime(&y2k)); + long long mseconds = Time.GetNowTime(); cDeadlockDetect dd; delete m_Log; @@ -188,12 +181,11 @@ void cRoot::Start(void) m_InputThread->Start( false ); // We should NOT wait? Otherwise we canīt stop the server from other threads than the input thread #endif - time(&timer); - finishseconds = difftime(timer,mktime(&y2k)); - finishseconds -= seconds; + long long finishmseconds = Time.GetNowTime(); + finishmseconds -= mseconds; - if ((finishseconds > 1) || (finishseconds == 0)) { LOG("Startup complete, took %.f seconds!", finishseconds); } - else { LOG("Startup complete, took 1 second!"); } + if ((finishmseconds > 1) || (finishmseconds == 0)) { LOG("Startup complete, took %i miliseconds!", finishmseconds); } // Milisecs, why not :P + else { LOG("Startup complete, took 1 milisecond!"); } while (!m_bStop && !m_bRestart) // These are modified by external threads { -- cgit v1.2.3 From 20902e125c9b042ff77ddf4419e3eb9474de674e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 30 Sep 2013 21:17:52 +0100 Subject: Removed unneeded statement Also LOGINFO'd "Starting WebAdmin" --- source/Root.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source/Root.cpp') diff --git a/source/Root.cpp b/source/Root.cpp index c33af52ad..abe153b30 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -184,8 +184,7 @@ void cRoot::Start(void) long long finishmseconds = Time.GetNowTime(); finishmseconds -= mseconds; - if ((finishmseconds > 1) || (finishmseconds == 0)) { LOG("Startup complete, took %i miliseconds!", finishmseconds); } // Milisecs, why not :P - else { LOG("Startup complete, took 1 milisecond!"); } + LOG("Startup complete, took %i ms!", finishmseconds); while (!m_bStop && !m_bRestart) // These are modified by external threads { -- cgit v1.2.3