From 2d276cad0b46d68e6886645559cd47c0165392fe Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 19 Dec 2019 19:35:36 -0500 Subject: put expensive logging in an optional function --- src/shared/util.cpp | 21 +++++++++++++++++++++ src/shared/util.h | 14 ++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'src/shared') diff --git a/src/shared/util.cpp b/src/shared/util.cpp index 302dea7d..4ac95465 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -21,6 +21,7 @@ along with Mod Organizer. If not, see . #include "windows_error.h" #include "mainwindow.h" #include "env.h" +#include #include #include @@ -320,6 +321,26 @@ void SetThisThreadName(const QString& s) } // namespace MOShared +TimeThis::TimeThis(QString what) + : m_what(std::move(what)), m_start(Clock::now()) +{ +} + +TimeThis::~TimeThis() +{ + using namespace std::chrono; + + const auto end = Clock::now(); + const auto d = duration_cast(end - m_start).count(); + + if (m_what.isEmpty()) { + MOBase::log::debug("{} ms", d); + } else { + MOBase::log::debug("{} {} ms", m_what, d); + } +} + + static bool g_exiting = false; static bool g_canClose = false; diff --git a/src/shared/util.h b/src/shared/util.h index b6f898db..788d2444 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -52,6 +52,20 @@ void SetThisThreadName(const QString& s); } // namespace MOShared +class TimeThis +{ +public: + TimeThis(QString what={}); + ~TimeThis(); + +private: + using Clock = std::chrono::high_resolution_clock; + + QString m_what; + Clock::time_point m_start; +}; + + enum class Exit { None = 0x00, -- cgit v1.3.1