changeset 1864:166d7a4c2cd6 startup-timing

Add timings to debug output
author Chris Cannam
date Wed, 03 Jun 2020 13:57:37 +0100
parents 4c5736a517e0
children 7b6e18380e8f
files base/Debug.cpp base/Debug.h
diffstat 2 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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 <QDateTime>
 
 #include <stdexcept>
+#include <memory>
 
-static SVDebug *svdebug = nullptr;
-static SVCerr *svcerr = nullptr;
+static std::unique_ptr<SVDebug> svdebug = nullptr;
+static std::unique_ptr<SVCerr> svcerr = nullptr;
 static QMutex mutex;
 
 SVDebug &getSVDebug() {
     mutex.lock();
     if (!svdebug) {
-        svdebug = new SVDebug();
+        svdebug = std::make_unique<SVDebug>();
     }
     mutex.unlock();
     return *svdebug;
@@ -41,9 +42,9 @@
     mutex.lock();
     if (!svcerr) {
         if (!svdebug) {
-            svdebug = new SVDebug();
+            svdebug = std::make_unique<SVDebug>();
         }
-        svcerr = new SVCerr(*svdebug);
+        svcerr = std::make_unique<SVCerr>(*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() << ">";
 }
 
--- 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 <QDebug>
 #include <QTextStream>
+#include <QElapsedTimer>
 
 #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;
 };