1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Fixes excessive logging causing RMG slowdown

- Do not apply formatting on log entries that will be discarded due to
high log level
- Do not log incorrect access to visitablePos due to its numerous use by
RMG
This commit is contained in:
Ivan Savenko 2024-12-23 21:24:00 +00:00
parent 2272707175
commit 6da58a6871
4 changed files with 28 additions and 21 deletions

View File

@ -58,6 +58,7 @@ public:
virtual void log(ELogLevel::ELogLevel level, const std::string & message) const = 0;
virtual void log(ELogLevel::ELogLevel level, const boost::format & fmt) const = 0;
virtual ELogLevel::ELogLevel getEffectiveLevel() const = 0;
/// Returns true if a debug/trace log message will be logged, false if not.
/// Useful if performance is important and concatenating the log message is a expensive task.
@ -66,6 +67,8 @@ public:
template<typename T, typename ... Args>
void log(ELogLevel::ELogLevel level, const std::string & format, T t, Args ... args) const
{
if (getEffectiveLevel() <= level)
{
try
{
@ -79,6 +82,7 @@ public:
log(ELogLevel::ERROR, format);
}
}
}
/// Log methods for various log levels
inline void error(const std::string & message) const

View File

@ -146,14 +146,17 @@ void CLogger::log(ELogLevel::ELogLevel level, const std::string & message) const
void CLogger::log(ELogLevel::ELogLevel level, const boost::format & fmt) const
{
if (getEffectiveLevel() <= level)
{
try
{
log(level, fmt.str());
}
catch(...)
catch (...)
{
log(ELogLevel::ERROR, "Invalid log format!");
}
}
}
ELogLevel::ELogLevel CLogger::getLevel() const

View File

@ -46,7 +46,7 @@ private:
/// The logger is used to log messages to certain targets of a specific domain/name.
/// It is thread-safe and can be used concurrently by several threads.
class DLL_LINKAGE CLogger: public vstd::CLoggerBase
class DLL_LINKAGE CLogger final: public vstd::CLoggerBase
{
public:
ELogLevel::ELogLevel getLevel() const;
@ -70,7 +70,7 @@ public:
private:
explicit CLogger(const CLoggerDomain & domain);
inline ELogLevel::ELogLevel getEffectiveLevel() const; /// Returns the log level applied on this logger whether directly or indirectly.
inline ELogLevel::ELogLevel getEffectiveLevel() const override; /// Returns the log level applied on this logger whether directly or indirectly.
inline void callTargets(const LogRecord & record) const;
CLoggerDomain domain;

View File

@ -217,8 +217,8 @@ int CGObjectInstance::getSightRadius() const
int3 CGObjectInstance::getVisitableOffset() const
{
if (!isVisitable())
logGlobal->debug("Attempt to access visitable offset on a non-visitable object!");
// if (!isVisitable())
// logGlobal->debug("Attempt to access visitable offset on a non-visitable object!");
return appearance->getVisitableOffset();
}
@ -317,8 +317,8 @@ void CGObjectInstance::onHeroVisit( const CGHeroInstance * h ) const
int3 CGObjectInstance::visitablePos() const
{
if (!isVisitable())
logGlobal->debug("Attempt to access visitable position on a non-visitable object!");
// if (!isVisitable())
// logGlobal->debug("Attempt to access visitable position on a non-visitable object!");
return pos - getVisitableOffset();
}