Skip to content

Commit

Permalink
Move profiler instance to QgsApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 authored and nyalldawson committed Nov 23, 2016
1 parent ee80be4 commit 311f482
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 38 deletions.
4 changes: 4 additions & 0 deletions doc/api_break.dox
Expand Up @@ -1363,6 +1363,10 @@ QgsRuleBasedRendererWidget {#qgis_api_break_3_0_QgsRuleBasedRendererWidge

- refineRuleCategoriesGui() and refineRuleRangesGui() no longer take a QModelIndexList argument.

QgsRuntimeProfiler {#qgis_api_break_3_0_QgsRuntimeProfiler}
------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::profiler() to access an application-wide profiler.

QgsSimpleMarkerSymbolLayer {#qgis_api_break_3_0_QgsSimpleMarkerSymbolLayer}
--------------------------
Expand Down
6 changes: 6 additions & 0 deletions python/core/qgsapplication.sip
Expand Up @@ -385,6 +385,12 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
*/
static QgsActionScopeRegistry* actionScopeRegistry();

/**
* Returns the application runtime profiler.
* @note added in QGIS 3.0
*/
static QgsRuntimeProfiler* profiler();

public slots:

/** Causes the application instance to emit the settingsChanged() signal. This should
Expand Down
7 changes: 0 additions & 7 deletions python/core/qgsruntimeprofiler.sip
Expand Up @@ -11,13 +11,6 @@ class QgsRuntimeProfiler
*/
QgsRuntimeProfiler();

/**
* @brief Begin the group for the profiler. Groups will append {GroupName}/ to the
* front of the profile tag set using start.
* @param name The name of the group.
*/
static QgsRuntimeProfiler * instance();

/**
* @brief Begin the group for the profiler. Groups will append {GroupName}/ to the
* front of the profile tag set using start.
Expand Down
19 changes: 8 additions & 11 deletions src/app/qgisapp.cpp
Expand Up @@ -564,7 +564,6 @@ QgisApp *QgisApp::smInstance = nullptr;
// constructor starts here
QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCheck, QWidget * parent, Qt::WindowFlags fl )
: QMainWindow( parent, fl )
, mProfiler( nullptr )
, mNonEditMapTool( nullptr )
, mScaleWidget( nullptr )
, mMagnifierWidget( nullptr )
Expand Down Expand Up @@ -609,13 +608,13 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
}

smInstance = this;
mProfiler = QgsRuntimeProfiler::instance();
QgsRuntimeProfiler* profiler = QgsApplication::profiler();

namSetup();

// load GUI: actions, menus, toolbars
mProfiler->beginGroup( QStringLiteral( "qgisapp" ) );
mProfiler->beginGroup( QStringLiteral( "startup" ) );
profiler->beginGroup( QStringLiteral( "qgisapp" ) );
profiler->beginGroup( QStringLiteral( "startup" ) );
startProfile( QStringLiteral( "Setting up UI" ) );
setupUi( this );
endProfile();
Expand Down Expand Up @@ -1105,13 +1104,12 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
#ifdef ANDROID
toggleFullScreen();
#endif
mProfiler->endGroup();
mProfiler->endGroup();
profiler->endGroup();

QgsDebugMsg( "PROFILE TIMES" );
QgsDebugMsg( QString( "PROFILE TIMES TOTAL - %1 " ).arg( mProfiler->totalTime() ) );
QgsDebugMsg( QString( "PROFILE TIMES TOTAL - %1 " ).arg( profiler->totalTime() ) );
#ifdef QGISDEBUG
QList<QPair<QString, double> > profileTimes = mProfiler->profileTimes();
QList<QPair<QString, double> > profileTimes = profiler->profileTimes();
QList<QPair<QString, double> >::const_iterator it = profileTimes.constBegin();
for ( ; it != profileTimes.constEnd(); ++it )
{
Expand All @@ -1125,7 +1123,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

QgisApp::QgisApp()
: QMainWindow( nullptr, 0 )
, mProfiler( nullptr )
, mStyleSheetBuilder( nullptr )
, mActionPluginSeparator1( nullptr )
, mActionPluginSeparator2( nullptr )
Expand Down Expand Up @@ -11265,12 +11262,12 @@ void QgisApp::onSnappingConfigChanged()

void QgisApp::startProfile( const QString& name )
{
mProfiler->start( name );
QgsApplication::profiler()->start( name );
}

void QgisApp::endProfile()
{
mProfiler->end();
QgsApplication::profiler()->end();
}

void QgisApp::functionProfile( void ( QgisApp::*fnc )(), QgisApp* instance, QString name )
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgisapp.h
Expand Up @@ -1430,8 +1430,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void endProfile();
void functionProfile( void ( QgisApp::*fnc )(), QgisApp *instance, QString name );

QgsRuntimeProfiler* mProfiler;

/** This method will open a dialog so the user can select GDAL sublayers to load
* @returns true if any items were loaded
*/
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -24,6 +24,7 @@
#include "qgsproviderregistry.h"
#include "qgsexpression.h"
#include "qgsactionscoperegistry.h"
#include "qgsruntimeprofiler.h"

#include <QDir>
#include <QFile>
Expand Down Expand Up @@ -104,6 +105,7 @@ QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled, const
{
sPlatformName = platformName;

mProfiler = new QgsRuntimeProfiler();
mActionScopeRegistry = new QgsActionScopeRegistry();

init( customConfigPath ); // init can also be called directly by e.g. unit tests that don't inherit QApplication.
Expand Down Expand Up @@ -237,6 +239,7 @@ void QgsApplication::init( QString customConfigPath )
QgsApplication::~QgsApplication()
{
delete mActionScopeRegistry;
delete mProfiler;
}

QgsApplication* QgsApplication::instance()
Expand Down Expand Up @@ -310,6 +313,11 @@ bool QgsApplication::notify( QObject * receiver, QEvent * event )
return done;
}

QgsRuntimeProfiler *QgsApplication::profiler()
{
return instance()->mProfiler;
}

void QgsApplication::setFileOpenEventReceiver( QObject * receiver )
{
// Set receiver for FileOpen events
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsapplication.h
Expand Up @@ -23,6 +23,7 @@
#include <qgsconfig.h>

class QgsActionScopeRegistry;
class QgsRuntimeProfiler;

/** \ingroup core
* Extends QApplication to provide access to QGIS specific resources such
Expand Down Expand Up @@ -381,6 +382,12 @@ class CORE_EXPORT QgsApplication : public QApplication
*/
static QgsActionScopeRegistry* actionScopeRegistry();

/**
* Returns the application runtime profiler.
* @note added in QGIS 3.0
*/
static QgsRuntimeProfiler* profiler();

public slots:

/** Causes the application instance to emit the settingsChanged() signal. This should
Expand Down Expand Up @@ -448,6 +455,7 @@ class CORE_EXPORT QgsApplication : public QApplication
QMap<QString, QIcon> mIconCache;

QgsActionScopeRegistry* mActionScopeRegistry;
QgsRuntimeProfiler* mProfiler;
};

#endif
9 changes: 0 additions & 9 deletions src/core/qgsruntimeprofiler.cpp
Expand Up @@ -2,15 +2,6 @@
#include "qgslogger.h"


QgsRuntimeProfiler* QgsRuntimeProfiler::mInstance = nullptr;

QgsRuntimeProfiler* QgsRuntimeProfiler::instance()
{
if ( !mInstance )
mInstance = new QgsRuntimeProfiler();
return mInstance;
}

QgsRuntimeProfiler::QgsRuntimeProfiler()
{

Expand Down
9 changes: 0 additions & 9 deletions src/core/qgsruntimeprofiler.h
Expand Up @@ -17,13 +17,6 @@ class CORE_EXPORT QgsRuntimeProfiler
*/
QgsRuntimeProfiler();

/**
* @brief Instance of the run time profiler. To use the main profiler
* use this instance.
* @return The instance of the run time profiler
*/
static QgsRuntimeProfiler * instance();

/**
* @brief Begin the group for the profiler. Groups will append {GroupName}/ to the
* front of the profile tag set using start.
Expand Down Expand Up @@ -67,8 +60,6 @@ class CORE_EXPORT QgsRuntimeProfiler
double totalTime();

private:
static QgsRuntimeProfiler* mInstance;

QString mGroupPrefix;
QStack<QString> mGroupStack;
QTime mProfileTime;
Expand Down

0 comments on commit 311f482

Please sign in to comment.