More perf work, need to switch branches.

This commit is contained in:
KimLS 2015-02-02 23:10:03 -08:00
parent b6a2ac05bf
commit 5747b3460f
10 changed files with 80 additions and 34 deletions

View File

@ -186,6 +186,8 @@ int main(int argc, char *argv[]) {
void CatchSignal(int sig_num) {
Log.Out(Logs::Detail, Logs::Launcher, "Caught signal %d", sig_num);
RunLoops = false;
}

View File

@ -8,10 +8,17 @@
#define eqp_comb_fin(x, y) x##y
#define eqp_comb(x, y) eqp_comb_fin(x, y)
#ifndef EQP_MULTITHREAD
#define _eqp EQP::CPU::ST::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__);
#define _eqpn(x) EQP::CPU::ST::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__, x);
#define _eqp_mt EQP::CPU::MT::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__);
#define _eqpn_mt(x) EQP::CPU::MT::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)
#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)
#endif
namespace EQP
{
@ -73,7 +80,7 @@ namespace EQP
#define _eqp
#define _eqpn(x)
#define _eqp_mt
#define _eqpn_mt(x)
#define _eqp_clear()
#define _eqp_dump(strm, count)
#endif

View File

@ -49,7 +49,7 @@ void CatchSignal(int sig_num)
std::ofstream profile_out(prof_name, std::ofstream::out);
if(profile_out.good()) {
EQP::CPU::ST::GetProfiler().Dump(profile_out, 10);
_eqp_dump(profile_out, 10);
}
#endif
}

View File

@ -26,10 +26,12 @@ TARGET_LINK_LIBRARIES(queryserv common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBUG}
IF(MSVC)
SET_TARGET_PROPERTIES(queryserv PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(queryserv "Ws2_32.lib")
TARGET_LINK_LIBRARIES(queryserv "rpcrt4")
ENDIF(MSVC)
IF(MINGW)
TARGET_LINK_LIBRARIES(queryserv "WS2_32")
TARGET_LINK_LIBRARIES(queryserv "rpcrt4")
ENDIF(MINGW)
IF(UNIX)
@ -40,7 +42,7 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(queryserv "rt")
ENDIF(NOT DARWIN)
TARGET_LINK_LIBRARIES(queryserv "pthread")
ADD_DEFINITIONS(-fPIC)
TARGET_LINK_LIBRARIES(queryserv "uuid")
ENDIF(UNIX)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

View File

@ -50,6 +50,7 @@
Database::Database ()
{
_eqp
DBInitVars();
}
@ -59,12 +60,14 @@ Establish a connection to a mysql database with the supplied parameters
Database::Database(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
{
_eqp
DBInitVars();
Connect(host, user, passwd, database, port);
}
bool Database::Connect(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
{
_eqp
uint32 errnum= 0;
char errbuf[MYSQL_ERRMSG_SIZE];
if (!Open(host, user, passwd, database, port, &errnum, errbuf))
@ -82,12 +85,13 @@ bool Database::Connect(const char* host, const char* user, const char* passwd, c
}
void Database::DBInitVars() {
_eqp
}
void Database::HandleMysqlError(uint32 errnum) {
_eqp
}
/*
@ -96,10 +100,11 @@ Close the connection to the database
*/
Database::~Database()
{
_eqp
}
void Database::AddSpeech(const char* from, const char* to, const char* message, uint16 minstatus, uint32 guilddbid, uint8 type) {
_eqp
char *escapedFrom = new char[strlen(from) * 2 + 1];
char *escapedTo = new char[strlen(to) * 2 + 1];
char *escapedMessage = new char[strlen(message) * 2 + 1];
@ -124,7 +129,7 @@ void Database::AddSpeech(const char* from, const char* to, const char* message,
}
void Database::LogPlayerTrade(QSPlayerLogTrade_Struct* QS, uint32 detailCount) {
_eqp
std::string query = StringFormat("INSERT INTO `qs_player_trade_record` SET `time` = NOW(), "
"`char1_id` = '%i', `char1_pp` = '%i', `char1_gp` = '%i', "
"`char1_sp` = '%i', `char1_cp` = '%i', `char1_items` = '%i', "
@ -165,7 +170,7 @@ void Database::LogPlayerTrade(QSPlayerLogTrade_Struct* QS, uint32 detailCount) {
}
void Database::LogPlayerHandin(QSPlayerLogHandin_Struct* QS, uint32 detailCount) {
_eqp
std::string query = StringFormat("INSERT INTO `qs_player_handin_record` SET `time` = NOW(), "
"`quest_id` = '%i', `char_id` = '%i', `char_pp` = '%i', "
"`char_gp` = '%i', `char_sp` = '%i', `char_cp` = '%i', "
@ -206,7 +211,7 @@ void Database::LogPlayerHandin(QSPlayerLogHandin_Struct* QS, uint32 detailCount)
}
void Database::LogPlayerNPCKill(QSPlayerLogNPCKill_Struct* QS, uint32 members){
_eqp
std::string query = StringFormat("INSERT INTO `qs_player_npc_kill_record` "
"SET `npc_id` = '%i', `type` = '%i', "
"`zone_id` = '%i', `time` = NOW()",
@ -237,7 +242,7 @@ void Database::LogPlayerNPCKill(QSPlayerLogNPCKill_Struct* QS, uint32 members){
}
void Database::LogPlayerDelete(QSPlayerLogDelete_Struct* QS, uint32 items) {
_eqp
std::string query = StringFormat("INSERT INTO `qs_player_delete_record` SET `time` = NOW(), "
"`char_id` = '%i', `stack_size` = '%i', `char_items` = '%i'",
QS->char_id, QS->stack_size, QS->char_count, QS->char_count);
@ -270,8 +275,8 @@ void Database::LogPlayerDelete(QSPlayerLogDelete_Struct* QS, uint32 items) {
}
void Database::LogPlayerMove(QSPlayerLogMove_Struct* QS, uint32 items) {
_eqp
/* These are item moves */
std::string query = StringFormat("INSERT INTO `qs_player_move_record` SET `time` = NOW(), "
"`char_id` = '%i', `from_slot` = '%i', `to_slot` = '%i', "
"`stack_size` = '%i', `char_items` = '%i', `postaction` = '%i'",
@ -306,6 +311,7 @@ void Database::LogPlayerMove(QSPlayerLogMove_Struct* QS, uint32 items) {
}
void Database::LogMerchantTransaction(QSMerchantLogTransaction_Struct* QS, uint32 items) {
_eqp
/* Merchant transactions are from the perspective of the merchant, not the player -U */
std::string query = StringFormat("INSERT INTO `qs_merchant_transaction_record` SET `time` = NOW(), "
"`zone_id` = '%i', `merchant_id` = '%i', `merchant_pp` = '%i', "
@ -347,6 +353,7 @@ void Database::LogMerchantTransaction(QSMerchantLogTransaction_Struct* QS, uint3
}
void Database::GeneralQueryReceive(ServerPacket *pack) {
_eqp
/*
These are general queries passed from anywhere in zone instead of packing structures and breaking them down again and again
*/
@ -364,7 +371,8 @@ void Database::GeneralQueryReceive(ServerPacket *pack) {
safe_delete(queryBuffer);
}
void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings){
void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings) {
_eqp
std::string query =
"SELECT "
"log_category_id, "

View File

@ -12,6 +12,7 @@ extern Database database;
PlayerLookingForGuild::PlayerLookingForGuild(char *Name, char *Comments, uint32 Level, uint32 Class, uint32 AACount, uint32 Timezone, uint32 TimePosted)
{
_eqp
this->Name = Name;
this->Comments = Comments;
this->Level = Level;
@ -23,6 +24,7 @@ PlayerLookingForGuild::PlayerLookingForGuild(char *Name, char *Comments, uint32
GuildLookingForPlayers::GuildLookingForPlayers(char *Name, char *Comments, uint32 FromLevel, uint32 ToLevel, uint32 Classes, uint32 AACount, uint32 Timezone, uint32 TimePosted)
{
_eqp
this->Name = Name;
this->Comments = Comments;
this->FromLevel = FromLevel;
@ -35,6 +37,7 @@ GuildLookingForPlayers::GuildLookingForPlayers(char *Name, char *Comments, uint3
bool LFGuildManager::LoadDatabase()
{
_eqp
std::string query = "SELECT `type`,`name`,`comment`, "
"`fromlevel`, `tolevel`, `classes`, "
"`aacount`, `timezone`, `timeposted` FROM `lfguild`";
@ -61,6 +64,7 @@ bool LFGuildManager::LoadDatabase()
void LFGuildManager::HandlePacket(ServerPacket *pack)
{
_eqp
char From[64];
pack->SetReadPosition(0);
@ -150,6 +154,7 @@ void LFGuildManager::HandlePacket(ServerPacket *pack)
void LFGuildManager::SendPlayerMatches(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 FromLevel, uint32 ToLevel, uint32 MinAA, uint32 TimeZone, uint32 Classes)
{
_eqp
std::list<PlayerLookingForGuild>::iterator it;
std::list<PlayerLookingForGuild> Matches;
@ -193,6 +198,7 @@ void LFGuildManager::SendPlayerMatches(uint32 FromZoneID, uint32 FromInstanceID,
void LFGuildManager::SendGuildMatches(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 Level, uint32 AAPoints, uint32 TimeZone, uint32 Class)
{
_eqp
std::list<GuildLookingForPlayers>::iterator it;
std::list<GuildLookingForPlayers> Matches;
@ -232,6 +238,7 @@ void LFGuildManager::SendGuildMatches(uint32 FromZoneID, uint32 FromInstanceID,
void LFGuildManager::TogglePlayer(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 Class, uint32 Level, uint32 AAPoints, char *Comments, uint32 Toggle, uint32 TimeZone)
{
_eqp
for(auto it = Players.begin(); it != Players.end(); ++it)
if(!strcasecmp((*it).Name.c_str(), From)) {
Players.erase(it);
@ -273,6 +280,7 @@ void LFGuildManager::TogglePlayer(uint32 FromZoneID, uint32 FromInstanceID, char
void LFGuildManager::ToggleGuild(uint32 FromZoneID, uint32 FromInstanceID, char *From, char* GuildName, char *Comments, uint32 FromLevel, uint32 ToLevel, uint32 Classes, uint32 AACount, uint32 Toggle, uint32 TimeZone)
{
_eqp
for(auto it = Guilds.begin(); it != Guilds.end(); ++it)
if(!strcasecmp((*it).Name.c_str(), GuildName))
{
@ -318,6 +326,7 @@ void LFGuildManager::ToggleGuild(uint32 FromZoneID, uint32 FromInstanceID, char
void LFGuildManager::ExpireEntries()
{
_eqp
for(auto it = Players.begin(); it != Players.end(); ++it)
{
if((*it).TimePosted + 604800 > (uint32)time(nullptr))
@ -345,7 +354,7 @@ void LFGuildManager::ExpireEntries()
void LFGuildManager::SendPlayerStatus(uint32 FromZoneID, uint32 FromInstanceID, char *From)
{
_eqp
std::list<PlayerLookingForGuild>::iterator it;
for(it = Players.begin(); it != Players.end(); ++it)
@ -373,6 +382,7 @@ void LFGuildManager::SendPlayerStatus(uint32 FromZoneID, uint32 FromInstanceID,
void LFGuildManager::SendGuildStatus(uint32 FromZoneID, uint32 FromInstanceID, char *From, char *GuildName)
{
_eqp
std::list<GuildLookingForPlayers>::iterator it;
for(it = Guilds.begin(); it != Guilds.end(); ++it)

View File

@ -46,6 +46,21 @@ void CatchSignal(int sig_num) {
RunLoops = false;
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
}
int main() {
@ -55,16 +70,6 @@ int main() {
Timer LFGuildExpireTimer(60000);
Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect
/* Load XML from eqemu_config.xml
<qsdatabase>
<host>127.0.0.1</host>
<port>3306</port>
<username>user</username>
<password>password</password>
<db>dbname</db>
</qsdatabase>
*/
Log.Out(Logs::General, Logs::QS_Server, "Starting EQEmu QueryServ.");
if (!queryservconfig::LoadConfig()) {
Log.Out(Logs::General, Logs::QS_Server, "Loading server configuration failed.");
@ -99,6 +104,10 @@ int main() {
Log.Out(Logs::General, Logs::QS_Server, "Could not set signal handler");
return 1;
}
if(signal(SIGBREAK, CatchSignal) == SIG_ERR) {
Log.Out(Logs::General, Logs::QS_Server, "Could not set signal handler");
return 1;
}
/* Initial Connection to Worldserver */
worldserver = new WorldServer;
@ -108,16 +117,19 @@ int main() {
lfguildmanager.LoadDatabase();
while(RunLoops) {
Timer::SetCurrentTime();
if(LFGuildExpireTimer.Check())
lfguildmanager.ExpireEntries();
{
_eqpn("Main loop")
Timer::SetCurrentTime();
if(LFGuildExpireTimer.Check())
lfguildmanager.ExpireEntries();
if (InterserverTimer.Check()) {
if (worldserver->TryReconnect() && (!worldserver->Connected()))
worldserver->AsyncConnect();
if (InterserverTimer.Check()) {
if (worldserver->TryReconnect() && (!worldserver->Connected()))
worldserver->AsyncConnect();
}
worldserver->Process();
timeout_manager.CheckTimeouts();
}
worldserver->Process();
timeout_manager.CheckTimeouts();
Sleep(100);
}
Log.CloseFileLogs();

View File

@ -23,6 +23,7 @@
queryservconfig *queryservconfig::_chat_config = nullptr;
std::string queryservconfig::GetByName(const std::string &var_name) const {
_eqp
return(EQEmuConfig::GetByName(var_name));
}

View File

@ -44,21 +44,25 @@ extern LFGuildManager lfguildmanager;
WorldServer::WorldServer()
: WorldConnection(EmuTCPConnection::packetModeQueryServ, Config->SharedKey.c_str())
{
_eqp
pTryReconnect = true;
}
WorldServer::~WorldServer()
{
_eqp
}
void WorldServer::OnConnected()
{
_eqp
Log.Out(Logs::Detail, Logs::QS_Server, "Connected to World.");
WorldConnection::OnConnected();
}
void WorldServer::Process()
{
_eqp
WorldConnection::Process();
if (!Connected())
return;

View File

@ -67,7 +67,7 @@ void CatchSignal(int sig_num) {
std::ofstream profile_out(prof_name, std::ofstream::out);
if(profile_out.good()) {
EQP::CPU::ST::GetProfiler().Dump(profile_out, 10);
_eqp_dump(profile_out, 10);
}
#endif
}