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
This commit is contained in:
Giacomo Pozzoni
2020-07-30 19:42:27 +00:00
committed by GitHub
parent 0fc7b50c04
commit deceb11b5f
4 changed files with 36 additions and 0 deletions

View File

@@ -33,6 +33,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
@@ -412,6 +416,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,10 @@ void MapUpdater::update_finished()
void MapUpdater::WorkerThread()
{
LoginDatabase.WarnAboutSyncQueries(true);
CharacterDatabase.WarnAboutSyncQueries(true);
WorldDatabase.WarnAboutSyncQueries(true);
while (1)
{
MapUpdateRequest* request = nullptr;

View File

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