forked from qt-creator/qt-creator
qmljs: add ImportsBenchmarker
To see the results use QT_LOGGING_RULES=qtc.qmljs.imports.benchmark.*=true Change-Id: I07fe7b71d893423f3dfe5f9c0f1410bd29312943 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -32,11 +32,35 @@
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QElapsedTimer>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
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<QString, CoreImport> newCoreImports;
|
||||
QMap<ImportKey, QStringList> newImportCache;
|
||||
bool hasChanges = false;
|
||||
@@ -604,6 +629,7 @@ void ImportDependencies::filter(const ViewerContext &vContext)
|
||||
if (languageIsCompatible(vContext.language, cImport.language)) {
|
||||
QList<Export> 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<bool (const ImportMatchStrength &,const Export &,const CoreImport &)>
|
||||
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<ImportKey, QStringList>::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<ImportKey, QStringList>::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()) {
|
||||
|
Reference in New Issue
Block a user