Mercurial > hg > svcore
changeset 1877:258e356b1a7b
Merge from branch startup-timing
author | Chris Cannam |
---|---|
date | Mon, 22 Jun 2020 16:57:09 +0100 |
parents | 9a288b9b7a72 (current diff) cb9209ef373a (diff) |
children | 231c6bcf0fa2 652c5360e682 |
files | |
diffstat | 4 files changed, 46 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/base/Debug.cpp Thu Jun 18 15:42:19 2020 +0100 +++ b/base/Debug.cpp Mon Jun 22 16:57:09 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 Thu Jun 18 15:42:19 2020 +0100 +++ b/base/Debug.h Mon Jun 22 16:57:09 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; };
--- a/transform/TransformFactory.cpp Thu Jun 18 15:42:19 2020 +0100 +++ b/transform/TransformFactory.cpp Mon Jun 22 16:57:09 2020 +0100 @@ -102,7 +102,9 @@ TransformFactory::UninstalledTransformsPopulateThread::run() { m_factory->m_populatingSlowly = true; - sleep(1); + while (!m_factory->havePopulated()) { + sleep(1); + } m_factory->populateUninstalledTransforms(); } @@ -324,6 +326,13 @@ return tr("Other"); } +bool +TransformFactory::havePopulated() +{ + MutexLocker locker(&m_transformsMutex, "TransformFactory::havePopulated"); + return m_transformsPopulated; +} + void TransformFactory::populateTransforms() { @@ -395,6 +404,12 @@ } m_transformsPopulated = true; + +#ifdef DEBUG_TRANSFORM_FACTORY + SVCERR << "populateTransforms exiting" << endl; +#endif + + emit transformsPopulated(); } void @@ -743,6 +758,8 @@ #ifdef DEBUG_TRANSFORM_FACTORY SVCERR << "populateUninstalledTransforms exiting" << endl; #endif + + emit uninstalledTransformsPopulated(); } Transform
--- a/transform/TransformFactory.h Thu Jun 18 15:42:19 2020 +0100 +++ b/transform/TransformFactory.h Mon Jun 22 16:57:09 2020 +0100 @@ -78,6 +78,13 @@ typedef std::map<TransformId, TextMatcher::Match> SearchResults; SearchResults search(QString keyword); SearchResults search(QStringList keywords); + + /** + * Return true if the transforms have been populated, i.e. a call + * to something like haveTransform() will return without having to + * do the work of scanning plugins + */ + bool havePopulated(); /** * Return true if the given transform is known. @@ -191,6 +198,10 @@ QString getStartupFailureReport() const { return m_errorString; } + +signals: + void transformsPopulated(); + void uninstalledTransformsPopulated(); protected: typedef std::map<TransformId, TransformDescription> TransformDescriptionMap;