clear up heartbeat code, improve logs in debug builds

This commit is contained in:
Lion Kortlepel 2021-02-28 10:44:35 +01:00 committed by Anonymous275
parent ab44ac8c15
commit 8e4006fc38
2 changed files with 39 additions and 11 deletions

View File

@ -76,15 +76,38 @@ static inline void luaprint(const std::string& str) {
} }
#else // DEBUG #else // DEBUG
#define warn(x) Application::Console().Write(std::string(__func__) + ":" + std::to_string(__LINE__) + std::string(" [WARN] ") + (x)) #define _file_basename std::filesystem::path(__FILE__).filename().string()
#define info(x) Application::Console().Write(std::string(__func__) + ":" + std::to_string(__LINE__) + std::string(" [INFO] ") + (x)) #define _line std::to_string(__LINE__)
#define error(x) Application::Console().Write(std::string(__func__) + ":" + std::to_string(__LINE__) + std::string(" [ERROR] ") + (x)) #define _in_lambda (std::string(__func__) == "operator()")
#define luaprint(x) Application::Console().Write(std::string(__func__) + ":" + std::to_string(__LINE__) + std::string(" [LUA] ") + (x))
#define debug(x) \ // we would like the full function signature 'void a::foo() const'
do { \ // on windows this is __FUNCSIG__, on GCC it's __PRETTY_FUNCTION__,
if (Application::Settings.DebugModeEnabled) { \ // feel free to add more
Application::Console().Write(std::string(__func__) + ":" + std::to_string(__LINE__) + std::string(" [DEBUG] ") + (x)); \ #if defined(WIN32)
} \ #define _function_name std::string(__FUNCSIG__)
#elif defined(__unix) || defined(__unix__)
#define _function_name std::string(__PRETTY_FUNCTION__)
#else
#define _function_name std::string(__func__)
#endif
// if this is defined, we will show the full function signature infront of
// each info/debug/warn... call instead of the 'filename:line' format.
#if defined(BMP_FULL_FUNCTION_NAMES)
#define _this_location (_function_name)
#else
#define _this_location (_file_basename + ":" + _line)
#endif
#define warn(x) Application::Console().Write(_this_location + std::string(" [WARN] ") + (x))
#define info(x) Application::Console().Write(_this_location + std::string(" [INFO] ") + (x))
#define error(x) Application::Console().Write(_this_location + std::string(" [ERROR] ") + (x))
#define luaprint(x) Application::Console().Write(_this_location + std::string(" [LUA] ") + (x))
#define debug(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
Application::Console().Write(_this_location + std::string(" [DEBUG] ") + (x)); \
} \
} while (false) } while (false)
#endif // DEBUG #endif // DEBUG

View File

@ -18,11 +18,16 @@ void THeartbeatThread::operator()() {
Body = GenerateCall(); Body = GenerateCall();
// a hot-change occurs when a setting has changed, to update the backend of that change. // a hot-change occurs when a setting has changed, to update the backend of that change.
auto Now = std::chrono::high_resolution_clock::now(); auto Now = std::chrono::high_resolution_clock::now();
if (((Now - LastNormalUpdateTime) < std::chrono::seconds(5)) bool Unchanged = Last == Body;
|| (Last == Body && (Now - LastNormalUpdateTime) < std::chrono::seconds(30))) { auto TimePassed = (Now - LastNormalUpdateTime);
auto Threshold = Unchanged ? 30 : 5;
if (TimePassed < std::chrono::seconds(Threshold)) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
continue; continue;
} }
#ifdef DEBUG
debug("heartbeat @ " + std::to_string(std::chrono::duration_cast<std::chrono::seconds>(TimePassed).count()));
#endif // DEBUG
Last = Body; Last = Body;
LastNormalUpdateTime = Now; LastNormalUpdateTime = Now;