Log sync db queries in World::Update() loop (#25174)

* Core/Misc: Log sync queries on critical path

* Fix build

* Rename

* Fix warning

* Fix no-pch

* Change WarnAboutSyncQueries() to be header-only

(cherry picked from commit deceb11b5f)
This commit is contained in:
Giacomo Pozzoni
2020-07-30 19:42:27 +00:00
committed by Shauren
parent 6d9a084036
commit 736b9ac112
4 changed files with 39 additions and 0 deletions

View File

@@ -34,6 +34,10 @@
#include "Transaction.h"
#include "MySQLWorkaround.h"
#include <mysqld_error.h>
#ifdef TRINITY_DEBUG
#include <sstream>
#include <boost/stacktrace.hpp>
#endif
#define MIN_MYSQL_SERVER_VERSION 50100u
#define MIN_MYSQL_CLIENT_VERSION 50100u
@@ -413,6 +417,15 @@ void DatabaseWorkerPool<T>::Enqueue(SQLOperation* op)
template <class T>
T* DatabaseWorkerPool<T>::GetFreeConnection()
{
#ifdef TRINITY_DEBUG
if (_warnSyncQueries)
{
std::ostringstream ss;
ss << boost::stacktrace::stacktrace();
TC_LOG_WARN("sql.performances", "Sync query at:\n%s", ss.str().c_str());
}
#endif
uint8 i = 0;
auto const num_cons = _connections[IDX_SYNCH].size();
T* connection = nullptr;

View File

@@ -206,6 +206,13 @@ class DatabaseWorkerPool
//! Keeps all our MySQL connections alive, prevent the server from disconnecting us.
void KeepAlive();
void WarnAboutSyncQueries([[maybe_unused]] bool warn)
{
#ifdef TRINITY_DEBUG
_warnSyncQueries = warn;
#endif
}
private:
uint32 OpenConnections(InternalIndex type, uint8 numConnections);
@@ -225,6 +232,9 @@ class DatabaseWorkerPool
std::unique_ptr<MySQLConnectionInfo> _connectionInfo;
std::vector<uint8> _preparedStatementSize;
uint8 _async_threads, _synch_threads;
#ifdef TRINITY_DEBUG
static inline thread_local bool _warnSyncQueries = false;
#endif
};
#endif

View File

@@ -16,6 +16,7 @@
*/
#include "MapUpdater.h"
#include "DatabaseEnv.h"
#include "Map.h"
#include "Metric.h"
@@ -102,6 +103,11 @@ void MapUpdater::update_finished()
void MapUpdater::WorkerThread()
{
LoginDatabase.WarnAboutSyncQueries(true);
CharacterDatabase.WarnAboutSyncQueries(true);
WorldDatabase.WarnAboutSyncQueries(true);
HotfixDatabase.WarnAboutSyncQueries(true);
while (1)
{
MapUpdateRequest* request = nullptr;

View File

@@ -481,6 +481,11 @@ void WorldUpdateLoop()
uint32 realCurrTime = 0;
uint32 realPrevTime = getMSTime();
LoginDatabase.WarnAboutSyncQueries(true);
CharacterDatabase.WarnAboutSyncQueries(true);
WorldDatabase.WarnAboutSyncQueries(true);
HotfixDatabase.WarnAboutSyncQueries(true);
///- While we have not World::m_stopEvent, update the world
while (!World::IsStopped())
{
@@ -506,6 +511,11 @@ void WorldUpdateLoop()
Sleep(1000);
#endif
}
LoginDatabase.WarnAboutSyncQueries(false);
CharacterDatabase.WarnAboutSyncQueries(false);
WorldDatabase.WarnAboutSyncQueries(false);
HotfixDatabase.WarnAboutSyncQueries(false);
}
void SignalHandler(boost::system::error_code const& error, int /*signalNumber*/)