Skip to content
Permalink
Browse files

Some more detailed project loading time profiling for layout loading

  • Loading branch information
nyalldawson committed Jun 29, 2020
1 parent 8929837 commit de74ef6d96e65ee8badf8391374b0373bf12703b
Showing with 58 additions and 0 deletions.
  1. +53 −0 src/core/layout/qgslayout.cpp
  2. +5 −0 src/core/providers/gdal/qgsgdalprovider.cpp
@@ -31,6 +31,7 @@
#include "qgsvectorlayer.h"
#include "qgsexpressioncontextutils.h"
#include "qgsstyleentityvisitor.h"
#include "qgsruntimeprofiler.h"

QgsLayout::QgsLayout( QgsProject *project )
: mProject( project )
@@ -957,13 +958,26 @@ bool QgsLayout::readXml( const QDomElement &layoutElement, const QDomDocument &d
return object->readXml( layoutElement, document, context );
};

std::unique_ptr< QgsScopedRuntimeProfile > profile;
if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
profile = qgis::make_unique< QgsScopedRuntimeProfile >( tr( "Read layout settings" ), QStringLiteral( "projectload" ) );

blockSignals( true ); // defer changed signal to end
readXmlLayoutSettings( layoutElement, document, context );
blockSignals( false );

if ( profile )
profile->switchTask( tr( "Load pages" ) );
restore( mPageCollection.get() );
if ( profile )
profile->switchTask( tr( "Load snapping settings" ) );
restore( &mSnapper );
if ( profile )
profile->switchTask( tr( "Load grid settings" ) );
restore( &mGridSettings );

if ( profile )
profile->switchTask( tr( "Restore items" ) );
addItemsFromXml( layoutElement, document, context );

emit changed();
@@ -997,6 +1011,11 @@ QList< QgsLayoutItem * > QgsLayout::addItemsFromXml( const QDomElement &parentEl
pageNumber = mPageCollection->pageNumberForPoint( *position );
}
}

std::unique_ptr< QgsScopedRuntimeProfile > profile;
if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
profile = qgis::make_unique< QgsScopedRuntimeProfile >( tr( "Read items" ), QStringLiteral( "projectload" ) );

// multiframes

//TODO - fix this. pasting multiframe frame items has no effect
@@ -1005,6 +1024,15 @@ QList< QgsLayoutItem * > QgsLayout::addItemsFromXml( const QDomElement &parentEl
{
const QDomElement multiFrameElem = multiFrameList.at( i ).toElement();
const int itemType = multiFrameElem.attribute( QStringLiteral( "type" ) ).toInt();

if ( profile )
{
if ( QgsLayoutMultiFrameAbstractMetadata *metadata = QgsApplication::layoutItemRegistry()->multiFrameMetadata( itemType ) )
{
profile->switchTask( tr( "Load %1" ).arg( metadata->visibleName() ) );
}
}

std::unique_ptr< QgsLayoutMultiFrame > mf( QgsApplication::layoutItemRegistry()->createMultiFrame( itemType, this ) );
if ( !mf )
{
@@ -1040,6 +1068,15 @@ QList< QgsLayoutItem * > QgsLayout::addItemsFromXml( const QDomElement &parentEl
continue;

const int itemType = currentItemElem.attribute( QStringLiteral( "type" ) ).toInt();

if ( profile )
{
if ( QgsLayoutItemAbstractMetadata *metadata = QgsApplication::layoutItemRegistry()->itemMetadata( itemType ) )
{
profile->switchTask( tr( "Load %1" ).arg( metadata->visibleName() ) );
}
}

std::unique_ptr< QgsLayoutItem > item( QgsApplication::layoutItemRegistry()->createItem( itemType, this ) );
if ( !item )
{
@@ -1071,13 +1108,26 @@ QList< QgsLayoutItem * > QgsLayout::addItemsFromXml( const QDomElement &parentEl
// to other items in the layout, which may not have existed at the time the
// item's state was restored. E.g. a scalebar may have been restored before the map
// it is linked to
std::unique_ptr< QgsScopedRuntimeProfile > itemProfile;
if ( profile )
{
profile->switchTask( tr( "Finalize restore" ) );
}
for ( QgsLayoutItem *item : qgis::as_const( newItems ) )
{
if ( profile )
itemProfile = qgis::make_unique< QgsScopedRuntimeProfile >( item->displayName(), QStringLiteral( "projectload" ) );
item->finalizeRestoreFromXml();
if ( itemProfile )
itemProfile.reset();
}
for ( QgsLayoutMultiFrame *mf : qgis::as_const( newMultiFrames ) )
{
if ( profile )
itemProfile = qgis::make_unique< QgsScopedRuntimeProfile >( mf->displayName(), QStringLiteral( "projectload" ) );
mf->finalizeRestoreFromXml();
if ( itemProfile )
itemProfile.reset();
}

for ( QgsLayoutItem *item : qgis::as_const( newItems ) )
@@ -1092,6 +1142,9 @@ QList< QgsLayoutItem * > QgsLayout::addItemsFromXml( const QDomElement &parentEl
//Since this function adds items in an order which isn't the z-order, and each item is added to end of
//z order list in turn, it will now be inconsistent with the actual order of items in the scene.
//Make sure z order list matches the actual order of items in the scene.

if ( profile )
profile->switchTask( tr( "Update model" ) );
mItemsModel->rebuildZList();

return newItems;
@@ -43,6 +43,7 @@
#include "qgspointxy.h"
#include "qgssettings.h"
#include "qgsogrutils.h"
#include "qgsruntimeprofiler.h"

#include <QImage>
#include <QColor>
@@ -164,6 +165,10 @@ QgsGdalProvider::QgsGdalProvider( const QString &uri, const ProviderOptions &opt
QgsGdalUtils::setupProxy();
#endif

std::unique_ptr< QgsScopedRuntimeProfile > profile;
if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
profile = qgis::make_unique< QgsScopedRuntimeProfile >( tr( "Open data source" ), QStringLiteral( "projectload" ) );

if ( !CPLGetConfigOption( "AAIGRID_DATATYPE", nullptr ) )
{
// GDAL tends to open AAIGrid as Float32 which results in lost precision

0 comments on commit de74ef6

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