# HG changeset patch # User Chris Cannam # Date 1591189057 -3600 # Node ID 166d7a4c2cd657f91542e5eb95903bacfbf6eb0f # Parent 4c5736a517e07d72c5523e5e5f2c358f233f6858 Add timings to debug output diff -r 4c5736a517e0 -r 166d7a4c2cd6 base/Debug.cpp --- a/base/Debug.cpp Mon May 18 14:06:30 2020 +0100 +++ b/base/Debug.cpp Wed Jun 03 13:57:37 2020 +0100 @@ -23,15 +23,16 @@ #include #include +#include -static SVDebug *svdebug = nullptr; -static SVCerr *svcerr = nullptr; +static std::unique_ptr svdebug = nullptr; +static std::unique_ptr svcerr = nullptr; static QMutex mutex; SVDebug &getSVDebug() { mutex.lock(); if (!svdebug) { - svdebug = new SVDebug(); + svdebug = std::make_unique(); } mutex.unlock(); return *svdebug; @@ -41,9 +42,9 @@ mutex.lock(); if (!svcerr) { if (!svdebug) { - svdebug = new SVDebug(); + svdebug = std::make_unique(); } - svcerr = new SVCerr(*svdebug); + svcerr = std::make_unique(*svdebug); } mutex.unlock(); return *svcerr; @@ -58,6 +59,8 @@ m_eol(true) { if (m_silenced) return; + + m_timer.start(); if (qApp->applicationName() == "") { cerr << "ERROR: Can't use SVDEBUG before setting application name" << endl; @@ -92,7 +95,10 @@ SVDebug::~SVDebug() { - if (m_stream) m_stream.close(); + if (m_stream) { + (*this) << "Debug log ends" << endl; + m_stream.close(); + } } QDebug & @@ -105,12 +111,12 @@ std::ostream & operator<<(std::ostream &target, const QString &str) { - return target << str.toStdString(); + return target << str.toUtf8().data(); } std::ostream & operator<<(std::ostream &target, const QUrl &u) { - return target << "<" << u.toString().toStdString() << ">"; + return target << "<" << u.toString() << ">"; } diff -r 4c5736a517e0 -r 166d7a4c2cd6 base/Debug.h --- a/base/Debug.h Mon May 18 14:06:30 2020 +0100 +++ b/base/Debug.h Wed Jun 03 13:57:37 2020 +0100 @@ -18,6 +18,7 @@ #include #include +#include #include "RealTime.h" @@ -46,7 +47,7 @@ if (m_silenced) return *this; if (m_ok) { if (m_eol) { - m_stream << m_prefix << " "; + m_stream << m_prefix << "/" << m_timer.elapsed() << ": "; } m_stream << t; m_eol = false; @@ -68,6 +69,7 @@ char *m_prefix; bool m_ok; bool m_eol; + QElapsedTimer m_timer; static bool m_silenced; };