From c22e43bf4188903cbd34090136eedb98ee1c95c8 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 29 Aug 2023 11:36:56 +0200 Subject: [PATCH] ExtensionSystem: Factor out startup performance summary Makes it possible to potentially show it after the fact. Change-Id: I7c93a2a290bf1a3e096286a3d20fd4553757ad5c Reviewed-by: Cristian Adam Reviewed-by: Qt CI Bot --- src/libs/extensionsystem/pluginmanager.cpp | 51 ++++++++++++++-------- src/libs/extensionsystem/pluginmanager_p.h | 3 +- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/libs/extensionsystem/pluginmanager.cpp b/src/libs/extensionsystem/pluginmanager.cpp index a0a4d3d8c7b..959cfb7d284 100644 --- a/src/libs/extensionsystem/pluginmanager.cpp +++ b/src/libs/extensionsystem/pluginmanager.cpp @@ -947,7 +947,7 @@ void PluginManagerPrivate::nextDelayedInitialize() delayedInitializeTimer = nullptr; if (m_profileTimer) m_totalStartupMS = m_profileTimer->elapsed(); - profilingSummary(); + printProfilingSummary(); emit q->initializationDone(); #ifdef WITH_TESTS if (PluginManager::testRunRequested()) @@ -1787,25 +1787,40 @@ void PluginManagerPrivate::profilingReport(const char *what, const PluginSpec *s } } -void PluginManagerPrivate::profilingSummary() const +QString PluginManagerPrivate::profilingSummary(qint64 *totalOut) const +{ + QString summary; + const QVector specs = Utils::sorted(pluginSpecs, + [](PluginSpec *s1, PluginSpec *s2) { + return s1->performanceData().total() + < s2->performanceData().total(); + }); + const qint64 total + = std::accumulate(specs.constBegin(), specs.constEnd(), 0, [](qint64 t, PluginSpec *s) { + return t + s->performanceData().total(); + }); + for (PluginSpec *s : specs) { + if (!s->isEffectivelyEnabled()) + continue; + const qint64 t = s->performanceData().total(); + summary += QString("%1 %2ms ( %3% )\n") + .arg(s->name(), -22) + .arg(t, 8) + .arg(100.0 * t / total, 5, 'f', 2); + } + summary += QString("Total plugins: %1ms\n").arg(total, 8); + summary += QString("Total startup: %1ms\n").arg(m_totalStartupMS, 8); + if (totalOut) + *totalOut = total; + return summary; +} + +void PluginManagerPrivate::printProfilingSummary() const { if (m_profilingVerbosity > 0) { - const QVector specs - = Utils::sorted(pluginSpecs, [](PluginSpec *s1, PluginSpec *s2) { - return s1->performanceData().total() < s2->performanceData().total(); - }); - const qint64 total - = std::accumulate(specs.constBegin(), specs.constEnd(), 0, [](qint64 t, PluginSpec *s) { - return t + s->performanceData().total(); - }); - for (PluginSpec *s : specs) { - if (!s->isEffectivelyEnabled()) - continue; - const qint64 t = s->performanceData().total(); - qDebug("%-22s %8lldms ( %5.2f%% )", qPrintable(s->name()), t, 100.0 * t / total); - } - qDebug("Total plugins: %8lldms", total); - qDebug("Total startup: %8lldms", m_totalStartupMS); + qint64 total; + const QString summary = profilingSummary(&total); + qDebug() << qPrintable(summary); Utils::Benchmarker::report("loadPlugins", "Total", total); } } diff --git a/src/libs/extensionsystem/pluginmanager_p.h b/src/libs/extensionsystem/pluginmanager_p.h index 4b5f45cccbc..63d017ac556 100644 --- a/src/libs/extensionsystem/pluginmanager_p.h +++ b/src/libs/extensionsystem/pluginmanager_p.h @@ -59,7 +59,8 @@ public: void resolveDependencies(); void enableDependenciesIndirectly(); void increaseProfilingVerbosity(); - void profilingSummary() const; + QString profilingSummary(qint64 *totalOut = nullptr) const; + void printProfilingSummary() const; void profilingReport(const char *what, const PluginSpec *spec, qint64 *target = nullptr); void setSettings(Utils::QtcSettings *settings); void setGlobalSettings(Utils::QtcSettings *settings);