From e809f665e4d079bc08cbaf60a19006a5beda0ce3 Mon Sep 17 00:00:00 2001 From: Tim Jenssen Date: Tue, 5 Jan 2021 17:41:35 +0100 Subject: [PATCH] qmljs: add ImportsBenchmarker To see the results use QT_LOGGING_RULES=qtc.qmljs.imports.benchmark.*=true Change-Id: I07fe7b71d893423f3dfe5f9c0f1410bd29312943 Reviewed-by: Thomas Hartmann --- src/libs/qmljs/qmljsimportdependencies.cpp | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/libs/qmljs/qmljsimportdependencies.cpp b/src/libs/qmljs/qmljsimportdependencies.cpp index eb4b0b649ab..9059478687b 100644 --- a/src/libs/qmljs/qmljsimportdependencies.cpp +++ b/src/libs/qmljs/qmljsimportdependencies.cpp @@ -32,11 +32,35 @@ #include #include +#include #include #include static Q_LOGGING_CATEGORY(importsLog, "qtc.qmljs.imports", QtWarningMsg) +static Q_LOGGING_CATEGORY(importsBenchmark, "qtc.qmljs.imports.benchmark", QtDebugMsg) + + +class ImportsBenchmarker +{ +public: + ImportsBenchmarker(const QString &functionName) + : m_functionName(functionName) + { + m_timer.start(); + } + + ~ImportsBenchmarker() + { + if (importsBenchmark().isDebugEnabled()) { + qCDebug(importsBenchmark).noquote().nospace() << m_functionName << " executed nPossibleExports: " << nPossibleExports << " in " << m_timer.elapsed() << "ms"; + } + } + int nPossibleExports = 0; + + QElapsedTimer m_timer; + QString m_functionName; +}; namespace QmlJS { @@ -596,6 +620,7 @@ ImportDependencies::~ImportDependencies() void ImportDependencies::filter(const ViewerContext &vContext) { + ImportsBenchmarker benchMark("filter()"); QMap newCoreImports; QMap newImportCache; bool hasChanges = false; @@ -604,6 +629,7 @@ void ImportDependencies::filter(const ViewerContext &vContext) if (languageIsCompatible(vContext.language, cImport.language)) { QList newExports; foreach (const Export &e, cImport.possibleExports) { + ++benchMark.nPossibleExports; if (e.visibleInVContext(vContext)) { newExports.append(e); QStringList &candidateImports = newImportCache[e.exportName]; @@ -641,6 +667,7 @@ void ImportDependencies::iterateOnCandidateImports( std::function const &iterF) const { + ImportsBenchmarker benchMark("iterateOnCandidateImports()"); switch (key.type) { case ImportType::Directory: case ImportType::QrcDirectory: @@ -653,6 +680,7 @@ void ImportDependencies::iterateOnCandidateImports( CoreImport cImport = coreImport(cImportName); if (languageIsCompatible(vContext.language, cImport.language)) { foreach (const Export e, cImport.possibleExports) { + ++benchMark.nPossibleExports; if (e.visibleInVContext(vContext)) { ImportMatchStrength m = e.exportName.matchImport(key, vContext); if (m.hasMatch()) { @@ -675,6 +703,7 @@ void ImportDependencies::iterateOnCandidateImports( CoreImport cImport = coreImport(cImportName); if (languageIsCompatible(vContext.language, cImport.language)) { foreach (const Export e, cImport.possibleExports) { + ++benchMark.nPossibleExports; if (e.visibleInVContext(vContext)) { ImportMatchStrength m = e.exportName.matchImport(key, vContext); if (m.hasMatch()) { @@ -840,6 +869,8 @@ void ImportDependencies::iterateOnLibraryImports( const Export &, const CoreImport &)> const &iterF) const { + ImportsBenchmarker benchMark("iterateOnLibraryImports()"); + typedef QMap::const_iterator iter_t; ImportKey firstLib; firstLib.type = ImportType::Library; @@ -851,6 +882,7 @@ void ImportDependencies::iterateOnLibraryImports( CoreImport cImport = coreImport(cImportName); if (languageIsCompatible(vContext.language, cImport.language)) { foreach (const Export &e, cImport.possibleExports) { + ++benchMark.nPossibleExports; if (e.visibleInVContext(vContext) && e.exportName.type == ImportType::Library) { ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext); if (m.hasMatch()) { @@ -874,6 +906,7 @@ void ImportDependencies::iterateOnSubImports( const Export &, const CoreImport &)> const &iterF) const { + ImportsBenchmarker benchMark("iterateOnSubImports()"); typedef QMap::const_iterator iter_t; iter_t i = m_importCache.lowerBound(baseKey); iter_t end = m_importCache.constEnd(); @@ -885,6 +918,7 @@ void ImportDependencies::iterateOnSubImports( CoreImport cImport = coreImport(cImportName); if (languageIsCompatible(vContext.language, cImport.language)) { foreach (const Export &e, cImport.possibleExports) { + ++benchMark.nPossibleExports; if (e.visibleInVContext(vContext)) { ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext); if (m.hasMatch()) {