diff --git a/eqlaunch/CMakeLists.txt b/eqlaunch/CMakeLists.txt index 86c9ae1a8..e2d81b334 100644 --- a/eqlaunch/CMakeLists.txt +++ b/eqlaunch/CMakeLists.txt @@ -20,10 +20,12 @@ TARGET_LINK_LIBRARIES(eqlaunch common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBUG} IF(MSVC) SET_TARGET_PROPERTIES(eqlaunch PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") TARGET_LINK_LIBRARIES(eqlaunch "Ws2_32.lib") + TARGET_LINK_LIBRARIES(eqlaunch "rpcrt4") ENDIF(MSVC) IF(MINGW) TARGET_LINK_LIBRARIES(eqlaunch "WS2_32") + TARGET_LINK_LIBRARIES(eqlaunch "rpcrt4") ENDIF(MINGW) IF(UNIX) @@ -34,6 +36,7 @@ IF(UNIX) TARGET_LINK_LIBRARIES(eqlaunch "rt") ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(eqlaunch "pthread") + TARGET_LINK_LIBRARIES(eqlaunch "uuid") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/eqlaunch/eqlaunch.cpp b/eqlaunch/eqlaunch.cpp index 0772fe543..e04f4d865 100644 --- a/eqlaunch/eqlaunch.cpp +++ b/eqlaunch/eqlaunch.cpp @@ -69,6 +69,10 @@ int main(int argc, char *argv[]) { Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler"); return 1; } + if (signal(SIGBREAK, CatchSignal) == SIG_ERR) { + Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler"); + return 1; + } #ifndef WIN32 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler"); @@ -187,7 +191,7 @@ void CatchSignal(int sig_num) { Log.Out(Logs::Detail, Logs::Launcher, "Caught signal %d", sig_num); RunLoops = false; - + _eqp_dump_file("eqlaunch"); } diff --git a/eqperf/eqp_profiler.h b/eqperf/eqp_profiler.h index d1989e066..be141940a 100644 --- a/eqperf/eqp_profiler.h +++ b/eqperf/eqp_profiler.h @@ -3,6 +3,8 @@ #ifdef EQPERF_ENABLED #include +#include +#include #include "eqp_profile_event.h" #include "eqp_profiler_node.h" @@ -13,11 +15,24 @@ #define _eqpn(x) EQP::CPU::ST::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__, x); #define _eqp_clear() EQP::CPU::ST::GetProfiler().Clear() #define _eqp_dump(strm, count) EQP::CPU::ST::GetProfiler().Dump(strm, count) +#define _eqp_dump_file(name) char time_str[128]; \ + time_t result = time(nullptr); \ + strftime(time_str, sizeof(time_str), "%Y_%m_%d_%H:%M:%S", localtime(&result)); \ + std::string prof_name = "./profile/"; \ + prof_name += name; \ + prof_name += "_"; \ + prof_name += time_str; \ + prof_name += ".log"; \ + std::ofstream profile_out(prof_name, std::ofstream::out); \ + if(profile_out.good()) { \ + _eqp_dump(profile_out, 10); \ + } #else #define _eqp EQP::CPU::MT::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__); #define _eqpn(x) EQP::CPU::MT::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__, x); #define _eqp_clear() EQP::CPU::MT::GetProfiler().Clear() #define _eqp_dump(strm, count) EQP::CPU::MT::GetProfiler().Dump(strm, count) +#define _eqp_dump_file() #endif namespace EQP diff --git a/loginserver/main.cpp b/loginserver/main.cpp index 275ce5b3f..b70f9348f 100644 --- a/loginserver/main.cpp +++ b/loginserver/main.cpp @@ -38,20 +38,7 @@ bool run_server = true; void CatchSignal(int sig_num) { -#ifdef EQPERF_ENABLED - char time_str[128]; - time_t result = time(nullptr); - strftime(time_str, sizeof(time_str), "%Y_%m_%d__%H_%M_%S", localtime(&result)); - - std::string prof_name = "./profile/login_"; - prof_name += time_str; - prof_name += ".log"; - - std::ofstream profile_out(prof_name, std::ofstream::out); - if(profile_out.good()) { - _eqp_dump(profile_out, 10); - } -#endif + _eqp_dump_file("loginserver"); } int main() diff --git a/queryserv/queryserv.cpp b/queryserv/queryserv.cpp index 9d1b50b40..0872aac1e 100644 --- a/queryserv/queryserv.cpp +++ b/queryserv/queryserv.cpp @@ -47,20 +47,7 @@ void CatchSignal(int sig_num) { if(worldserver) worldserver->Disconnect(); -#ifdef EQPERF_ENABLED - char time_str[128]; - time_t result = time(nullptr); - strftime(time_str, sizeof(time_str), "%Y_%m_%d__%H_%M_%S", localtime(&result)); - - std::string prof_name = "./profile/queryserv_"; - prof_name += time_str; - prof_name += ".log"; - - std::ofstream profile_out(prof_name, std::ofstream::out); - if(profile_out.good()) { - _eqp_dump(profile_out, 10); - } -#endif + _eqp_dump_file("queryserv"); } int main() { diff --git a/shared_memory/main.cpp b/shared_memory/main.cpp index 424431e25..ea3c92046 100644 --- a/shared_memory/main.cpp +++ b/shared_memory/main.cpp @@ -38,20 +38,7 @@ EQEmuLogSys Log; void CatchSignal(int sig_num) { -#ifdef EQPERF_ENABLED - char time_str[128]; - time_t result = time(nullptr); - strftime(time_str, sizeof(time_str), "%Y_%m_%d__%H_%M_%S", localtime(&result)); - - std::string prof_name = "./profile/shared_memory_"; - prof_name += time_str; - prof_name += ".log"; - - std::ofstream profile_out(prof_name, std::ofstream::out); - if(profile_out.good()) { - _eqp_dump(profile_out, 10); - } -#endif + _eqp_dump_file("shared_memory"); } void OnExit() { diff --git a/ucs/ucs.cpp b/ucs/ucs.cpp index 305068507..c7b6f4e26 100644 --- a/ucs/ucs.cpp +++ b/ucs/ucs.cpp @@ -19,13 +19,13 @@ #include "../common/eqemu_logsys.h" #include "../common/global_define.h" -#include "clientlist.h" #include "../common/opcodemgr.h" #include "../common/eq_stream_factory.h" #include "../common/rulesys.h" #include "../common/servertalk.h" #include "../common/platform.h" #include "../common/crash.h" +#include "clientlist.h" #include "database.h" #include "ucsconfig.h" #include "chatchannel.h" @@ -56,20 +56,7 @@ void CatchSignal(int sig_num) { if(worldserver) worldserver->Disconnect(); -#ifdef EQPERF_ENABLED - char time_str[128]; - time_t result = time(nullptr); - strftime(time_str, sizeof(time_str), "%Y_%m_%d__%H_%M_%S", localtime(&result)); - - std::string prof_name = "./profile/ucs_"; - prof_name += time_str; - prof_name += ".log"; - - std::ofstream profile_out(prof_name, std::ofstream::out); - if(profile_out.good()) { - _eqp_dump(profile_out, 10); - } -#endif + _eqp_dump_file("ucs"); } std::string GetMailPrefix() { diff --git a/world/net.cpp b/world/net.cpp index 434491a0a..9c82d5b22 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -21,9 +21,7 @@ #include #include #include - #include - #include "../common/global_define.h" #include "../common/eqemu_logsys.h" #include "../common/queue.h" @@ -34,7 +32,6 @@ #include "../common/version.h" #include "../common/eqtime.h" #include "../common/timeoutmgr.h" - #include "../common/opcodemgr.h" #include "../common/guilds.h" #include "../common/eq_stream_ident.h" @@ -43,6 +40,7 @@ #include "../common/crash.h" #include "client.h" #include "worlddb.h" + #ifdef _WINDOWS #include #define snprintf _snprintf @@ -147,6 +145,10 @@ int main(int argc, char** argv) { Log.Out(Logs::General, Logs::World_Server, "Could not set signal handler"); return 1; } + if (signal(SIGBREAK, CatchSignal) == SIG_ERR) { + Log.Out(Logs::General, Logs::World_Server, "Could not set signal handler"); + return 1; + } #ifndef WIN32 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { Log.Out(Logs::General, Logs::World_Server, "Could not set signal handler"); @@ -511,6 +513,8 @@ void CatchSignal(int sig_num) { if(zoneserver_list.worldclock.saveFile(WorldConfig::get()->EQTimeFile.c_str())==false) Log.Out(Logs::General, Logs::World_Server,"Failed to save time file."); RunLoops = false; + + _eqp_dump_file("world"); } void UpdateWindowTitle(char* iNewTitle) {