Skip to content
Permalink
Browse files

More fine tuned profiling for vector layer loading in projects

  • Loading branch information
nyalldawson committed Jun 28, 2020
1 parent ac1591a commit ae8dbd884ee0bc8d9689bdac5726061558e856ca
@@ -98,6 +98,14 @@ The current total time collected in the profiler.
QSet< QString > groups() const;
%Docstring
Returns the set of known groups.
%End

bool groupIsActive( const QString &group ) const;
%Docstring
Returns ``True`` if the specified ``group`` is currently being logged,
i.e. it has a entry which has started and not yet stopped.

.. versionadded:: 3.14
%End

static QString translateGroupName( const QString &group );
@@ -35,8 +35,8 @@ QgsProfilerPanelWidget::QgsProfilerPanelWidget( QgsRuntimeProfiler *profiler, QW
mTreeView->setModel( mProxyModel );
mTreeView->setSortingEnabled( true );

mTreeView->resizeColumnToContents( 0 );
mTreeView->resizeColumnToContents( 1 );
//mTreeView->resizeColumnToContents( 0 );
//mTreeView->resizeColumnToContents( 1 );

mTreeView->setItemDelegateForColumn( 1, new CostDelegate( QgsRuntimeProfilerNode::Elapsed, QgsRuntimeProfilerNode::ParentElapsed ) );

@@ -1162,6 +1162,8 @@ bool QgsProject::addLayer( const QDomElement &layerElem, QList<QDomNode> &broken

profile.switchTask( tr( "Load layer source" ) );
bool layerIsValid = mapLayer->readLayerXml( layerElem, context, layerFlags ) && mapLayer->isValid();

profile.switchTask( tr( "Add layer to project" ) );
QList<QgsMapLayer *> newLayers;
newLayers << mapLayer.get();
if ( layerIsValid || flags & QgsProject::ReadFlag::FlagDontResolveLayers )
@@ -288,6 +288,11 @@ double QgsRuntimeProfiler::totalTime( const QString &group )
return 0;
}

bool QgsRuntimeProfiler::groupIsActive( const QString &group ) const
{
return !mCurrentStack.value( group ).empty();
}

QString QgsRuntimeProfiler::translateGroupName( const QString &group )
{
if ( group == QLatin1String( "startup" ) )
@@ -235,6 +235,14 @@ class CORE_EXPORT QgsRuntimeProfiler : public QAbstractItemModel
*/
QSet< QString > groups() const { return mGroups; }

/**
* Returns TRUE if the specified \a group is currently being logged,
* i.e. it has a entry which has started and not yet stopped.
*
* \since QGIS 3.14
*/
bool groupIsActive( const QString &group ) const;

/**
* Returns the translated name of a standard profile \a group.
*/
@@ -99,6 +99,7 @@
#include "qgsauxiliarystorage.h"
#include "qgsgeometryoptions.h"
#include "qgsexpressioncontextutils.h"
#include "qgsruntimeprofiler.h"

#include "diagram/qgsdiagram.h"

@@ -1631,6 +1632,10 @@ void QgsVectorLayer::setDataSource( const QString &dataSource, const QString &ba
// reset style if loading default style, style is missing, or geometry type is has changed (and layer is valid)
if ( !renderer() || !legend() || ( mValid && geomType != geometryType() ) || loadDefaultStyleFlag )
{
std::unique_ptr< QgsScopedRuntimeProfile > profile;
if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
profile = qgis::make_unique< QgsScopedRuntimeProfile >( tr( "Load layer style" ), QStringLiteral( "projectload" ) );

bool defaultLoadedFlag = false;

if ( loadDefaultStyleFlag && isSpatial() && mDataProvider->capabilities() & QgsVectorDataProvider::CreateRenderer )
@@ -1714,6 +1719,10 @@ bool QgsVectorLayer::setDataProvider( QString const &provider, const QgsDataProv
}
}

std::unique_ptr< QgsScopedRuntimeProfile > profile;
if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
profile = qgis::make_unique< QgsScopedRuntimeProfile >( tr( "Create %1 provider" ).arg( provider ), QStringLiteral( "projectload" ) );

mDataProvider = qobject_cast<QgsVectorDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, mDataSource, options ) );
if ( !mDataProvider )
{
@@ -1734,6 +1743,8 @@ bool QgsVectorLayer::setDataProvider( QString const &provider, const QgsDataProv
return false;
}

if ( profile )
profile->switchTask( tr( "Read layer metadata" ) );
if ( mDataProvider->capabilities() & QgsVectorDataProvider::ReadLayerMetadata )
{
setMetadata( mDataProvider->layerMetadata() );
@@ -1746,6 +1757,8 @@ bool QgsVectorLayer::setDataProvider( QString const &provider, const QgsDataProv
// get and store the feature type
mWkbType = mDataProvider->wkbType();

if ( profile )
profile->switchTask( tr( "Read layer fields" ) );
updateFields();

if ( mProviderKey == QLatin1String( "postgres" ) )

0 comments on commit ae8dbd8

Please sign in to comment.
You can’t perform that action at this time.