Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some more detailed project loading time profiling for layout loading
  • Loading branch information
nyalldawson committed Jun 29, 2020
1 parent 8929837 commit de74ef6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/core/layout/qgslayout.cpp
Expand Up @@ -31,6 +31,7 @@
#include "qgsvectorlayer.h"
#include "qgsexpressioncontextutils.h"
#include "qgsstyleentityvisitor.h"
#include "qgsruntimeprofiler.h"

QgsLayout::QgsLayout( QgsProject *project )
: mProject( project )
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 ) )
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/core/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -43,6 +43,7 @@
#include "qgspointxy.h"
#include "qgssettings.h"
#include "qgsogrutils.h"
#include "qgsruntimeprofiler.h"

#include <QImage>
#include <QColor>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit de74ef6

Please sign in to comment.