Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiler #2797

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/inputhelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,14 @@ QVector<QString> InputHelp::logHeader( bool isHtml )
{
retLines.push_back( QStringLiteral( "%1Mergin User Profile not available. To include it, open you Profile Page in InputApp%2" ).arg( isHtml ? "<b>" : "" ).arg( isHtml ? "</b>" : "" ) );
}
retLines.push_back( QStringLiteral( "------------------------------------------" ) );
retLines.push_back( QStringLiteral( "Screen Info:" ) );
retLines.append( InputUtils().dumpScreenInfo().split( "\n" ).toVector() );
retLines.push_back( QStringLiteral( "------------------------------------------" ) );
retLines.push_back( QStringLiteral( "Profiler Data:" ) );
retLines.append( InputUtils().qgisProfilerLog() );
retLines.push_back( QStringLiteral( "------------------------------------------" ) );

return retLines;
}

Expand Down
56 changes: 54 additions & 2 deletions app/inpututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QScreen>
#include <QApplication>

#include "qgsruntimeprofiler.h"
#include "qcoreapplication.h"
#include "qgsgeometrycollection.h"
#include "qgslinestring.h"
Expand Down Expand Up @@ -1838,7 +1839,6 @@ bool InputUtils::rescaleImage( const QString &path, QgsProject *activeProject )
return ImageUtils::rescale( path, quality );
}


QgsGeometry InputUtils::createGeometryForLayer( QgsVectorLayer *layer )
{
QgsGeometry geometry;
Expand Down Expand Up @@ -1918,7 +1918,6 @@ QgsGeometry InputUtils::createGeometryForLayer( QgsVectorLayer *layer )
return geometry;
}


QString InputUtils::invalidGeometryWarning( QgsVectorLayer *layer )
{
QString msg;
Expand Down Expand Up @@ -1999,6 +1998,59 @@ QString InputUtils::layerAttribution( QgsMapLayer *layer )
return QString();
}

const double PROFILER_THRESHOLD = 0.001;
static double qgsRuntimeProfilerExtractModelAsText( QStringList &lines, const QString &group, const QModelIndex &parent, int level )
{
double total_elapsed = 0.0;

const int rc = QgsApplication::profiler()->rowCount( parent );
for ( int r = 0; r < rc; r++ )
{
QModelIndex rowIndex = QgsApplication::profiler()->index( r, 0, parent );
if ( QgsApplication::profiler()->data( rowIndex, QgsRuntimeProfilerNode::Group ).toString() != group )
continue;
bool ok;
double elapsed = QgsApplication::profiler()->data( rowIndex, QgsRuntimeProfilerNode::Elapsed ).toDouble( &ok );
if ( !ok )
elapsed = 0.0;
total_elapsed += elapsed;

if ( elapsed > PROFILER_THRESHOLD )
{
QString name = QgsApplication::profiler()->data( rowIndex, QgsRuntimeProfilerNode::Name ).toString();
lines << QStringLiteral( " %1 %2: %3 sec" ).arg( QStringLiteral( ">" ).repeated( level + 1 ), name, QString::number( elapsed, 'f', 3 ) );
}
total_elapsed += qgsRuntimeProfilerExtractModelAsText( lines, group, rowIndex, level + 1 );
}
return total_elapsed;
}

QVector<QString> InputUtils::qgisProfilerLog()
{
QVector<QString> lines;
const QString project = QgsProject::instance()->fileName();

if ( !project.isEmpty() )
{
lines << QStringLiteral( "QgsProject filename: %1" ).arg( project );
}

lines << QStringLiteral( "List of QgsRuntimeProfiler events above %1 sec" ).arg( QString::number( PROFILER_THRESHOLD, 'f', 3 ) );

const auto groups = QgsApplication::profiler()->groups();
for ( const QString &g : groups )
{
QVector<QString> groupLines;
double elapsed = qgsRuntimeProfilerExtractModelAsText( groupLines, g, QModelIndex(), 0 );
if ( elapsed > PROFILER_THRESHOLD )
{
lines << QStringLiteral( " %1: total %2 sec" ).arg( g, QString::number( elapsed, 'f', 3 ) );
lines << groupLines;
}
}
return lines;
}

QList<QgsPoint> InputUtils::parsePositionUpdates( const QString &data )
{
QList<QgsPoint> parsedUpdates;
Expand Down
7 changes: 5 additions & 2 deletions app/inpututils.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ class InputUtils: public QObject
*/
Q_INVOKABLE static QString resolvePrefixForRelativePath( int relativeStorageMode, const QString &homePath, const QString &targetDir );


/**
* Returns absolute path of the file for given path and its prefix. If prefixPath is empty,
* returns given path.
Expand Down Expand Up @@ -412,7 +411,6 @@ class InputUtils: public QObject
*/
Q_INVOKABLE static QString evaluateExpression( const FeatureLayerPair &pair, QgsProject *activeProject, const QString &expression );


/**
* Returns the QVariant typeName of a \a field.
* This is a stable identifier (compared to the provider field name).
Expand Down Expand Up @@ -532,6 +530,11 @@ class InputUtils: public QObject
*/
Q_INVOKABLE static QString layerAttribution( QgsMapLayer *layer );

/**
* Returns QGIS profiler data
*/
static QVector<QString> qgisProfilerLog();

signals:
Q_INVOKABLE void showNotificationRequested( const QString &message );

Expand Down