mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Update to qgis_bench: use renderer job, allow parallel mode, print other time
This commit is contained in:
parent
e814e8df92
commit
151bad59cd
@ -81,6 +81,8 @@ void usage( std::string const & appName )
|
|||||||
<< "\t[--configpath path]\tuse the given path for all user configuration\n"
|
<< "\t[--configpath path]\tuse the given path for all user configuration\n"
|
||||||
<< "\t[--prefix path]\tpath to a different build of qgis, may be used to test old versions\n"
|
<< "\t[--prefix path]\tpath to a different build of qgis, may be used to test old versions\n"
|
||||||
<< "\t[--quality]\trenderer hint(s), comma separated, possible values: Antialiasing,TextAntialiasing,SmoothPixmapTransform,NonCosmeticDefaultPen\n"
|
<< "\t[--quality]\trenderer hint(s), comma separated, possible values: Antialiasing,TextAntialiasing,SmoothPixmapTransform,NonCosmeticDefaultPen\n"
|
||||||
|
<< "\t[--parallel]\trender layers in parallel instead of sequentially\n"
|
||||||
|
<< "\t[--print type]\twhat kind of time to print, possible values: wall,total,user,sys. Default is total.\n"
|
||||||
<< "\t[--help]\t\tthis text\n\n"
|
<< "\t[--help]\t\tthis text\n\n"
|
||||||
<< " FILES:\n"
|
<< " FILES:\n"
|
||||||
<< " Files specified on the command line can include rasters,\n"
|
<< " Files specified on the command line can include rasters,\n"
|
||||||
@ -135,6 +137,8 @@ int main( int argc, char *argv[] )
|
|||||||
int mySnapshotWidth = 800;
|
int mySnapshotWidth = 800;
|
||||||
int mySnapshotHeight = 600;
|
int mySnapshotHeight = 600;
|
||||||
QString myQuality = "";
|
QString myQuality = "";
|
||||||
|
bool myParallel = false;
|
||||||
|
QString myPrintTime = "total";
|
||||||
|
|
||||||
// This behaviour will set initial extent of map canvas, but only if
|
// This behaviour will set initial extent of map canvas, but only if
|
||||||
// there are no command line arguments. This gives a usable map
|
// there are no command line arguments. This gives a usable map
|
||||||
@ -173,6 +177,8 @@ int main( int argc, char *argv[] )
|
|||||||
{"configpath", required_argument, 0, 'c'},
|
{"configpath", required_argument, 0, 'c'},
|
||||||
{"prefix", required_argument, 0, 'r'},
|
{"prefix", required_argument, 0, 'r'},
|
||||||
{"quality", required_argument, 0, 'q'},
|
{"quality", required_argument, 0, 'q'},
|
||||||
|
{"parallel", no_argument, 0, 'P'},
|
||||||
|
{"print", required_argument, 0, 'R'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -242,6 +248,14 @@ int main( int argc, char *argv[] )
|
|||||||
myQuality = optarg;
|
myQuality = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'P':
|
||||||
|
myParallel = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'R':
|
||||||
|
myPrintTime = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
usage( argv[0] );
|
usage( argv[0] );
|
||||||
return 2; // XXX need standard exit codes
|
return 2; // XXX need standard exit codes
|
||||||
@ -322,6 +336,14 @@ int main( int argc, char *argv[] )
|
|||||||
{
|
{
|
||||||
myQuality = argv[++i];
|
myQuality = argv[++i];
|
||||||
}
|
}
|
||||||
|
else if ( arg == "--parallel" || arg == "-P" )
|
||||||
|
{
|
||||||
|
myParallel = true;
|
||||||
|
}
|
||||||
|
else if ( i + 1 < argc && ( arg == "--print" || arg == "-R" ) )
|
||||||
|
{
|
||||||
|
myPrintTime = argv[++i];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) );
|
myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) );
|
||||||
@ -476,6 +498,8 @@ int main( int argc, char *argv[] )
|
|||||||
qbench->setRenderHints( hints );
|
qbench->setRenderHints( hints );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qbench->setParallel( myParallel );
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
// autoload any file names that were passed in on the command line
|
// autoload any file names that were passed in on the command line
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
@ -551,7 +575,7 @@ int main( int argc, char *argv[] )
|
|||||||
qbench->saveLog( myLogFileName );
|
qbench->saveLog( myLogFileName );
|
||||||
}
|
}
|
||||||
|
|
||||||
qbench->printLog();
|
qbench->printLog( myPrintTime );
|
||||||
|
|
||||||
delete qbench;
|
delete qbench;
|
||||||
delete myApp;
|
delete myApp;
|
||||||
|
@ -40,8 +40,10 @@
|
|||||||
#include "qgsbench.h"
|
#include "qgsbench.h"
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgsmaplayerregistry.h"
|
#include "qgsmaplayerregistry.h"
|
||||||
|
#include "qgsmaprendererjob.h"
|
||||||
#include "qgsproject.h"
|
#include "qgsproject.h"
|
||||||
#include "qgspallabeling.h"
|
|
||||||
|
const char *pre[] = { "user", "sys", "total", "wall" };
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
// slightly adapted from http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/port/getrusage.c?rev=1.18;content-type=text%2Fplain
|
// slightly adapted from http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/port/getrusage.c?rev=1.18;content-type=text%2Fplain
|
||||||
@ -117,14 +119,17 @@ int getrusage( int who, struct rusage * rusage )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
QgsBench::QgsBench( int theWidth, int theHeight, int theIterations )
|
QgsBench::QgsBench( int theWidth, int theHeight, int theIterations )
|
||||||
: QObject(), mWidth( theWidth ), mHeight( theHeight ), mIterations( theIterations ), mSetExtent( false )
|
: QObject()
|
||||||
|
, mWidth( theWidth )
|
||||||
|
, mHeight( theHeight )
|
||||||
|
, mIterations( theIterations )
|
||||||
|
, mSetExtent( false )
|
||||||
|
, mParallel( false )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "entered" );
|
QgsDebugMsg( "entered" );
|
||||||
|
|
||||||
QgsDebugMsg( QString( "mIterations = %1" ).arg( mIterations ) );
|
QgsDebugMsg( QString( "mIterations = %1" ).arg( mIterations ) );
|
||||||
|
|
||||||
mMapRenderer = new QgsMapRenderer;
|
|
||||||
|
|
||||||
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
|
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
|
||||||
this, SLOT( readProject( const QDomDocument & ) ) );
|
this, SLOT( readProject( const QDomDocument & ) ) );
|
||||||
}
|
}
|
||||||
@ -153,7 +158,7 @@ void QgsBench::readProject( const QDomDocument &doc )
|
|||||||
if ( nodes.count() )
|
if ( nodes.count() )
|
||||||
{
|
{
|
||||||
QDomNode node = nodes.item( 0 );
|
QDomNode node = nodes.item( 0 );
|
||||||
mMapRenderer->readXML( node );
|
mMapSettings.readXML( node );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -171,17 +176,17 @@ void QgsBench::render()
|
|||||||
{
|
{
|
||||||
QgsDebugMsg( "entered" );
|
QgsDebugMsg( "entered" );
|
||||||
|
|
||||||
QgsDebugMsg( "extent: " + mMapRenderer->extent().toString() );
|
QgsDebugMsg( "extent: " + mMapSettings.extent().toString() );
|
||||||
|
|
||||||
QMap<QString, QgsMapLayer*> layersMap = QgsMapLayerRegistry::instance()->mapLayers();
|
QMap<QString, QgsMapLayer*> layersMap = QgsMapLayerRegistry::instance()->mapLayers();
|
||||||
|
|
||||||
QStringList layers( layersMap.keys() );
|
QStringList layers( layersMap.keys() );
|
||||||
|
|
||||||
mMapRenderer->setLayerSet( layers );
|
mMapSettings.setLayers( layers );
|
||||||
|
|
||||||
if ( mSetExtent )
|
if ( mSetExtent )
|
||||||
{
|
{
|
||||||
mMapRenderer->setExtent( mExtent );
|
mMapSettings.setExtent( mExtent );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maybe in future
|
// Maybe in future
|
||||||
@ -190,27 +195,34 @@ void QgsBench::render()
|
|||||||
//mMapRenderer->setDestinationCrs( outputCRS );
|
//mMapRenderer->setDestinationCrs( outputCRS );
|
||||||
|
|
||||||
// TODO: this should be probably set according to project
|
// TODO: this should be probably set according to project
|
||||||
mMapRenderer->setProjectionsEnabled( true );
|
mMapSettings.setCrsTransformEnabled( true );
|
||||||
|
|
||||||
// Enable labeling
|
// Enable labeling
|
||||||
mMapRenderer->setLabelingEngine( new QgsPalLabeling() );
|
mMapSettings.setFlag( QgsMapSettings::DrawLabeling );
|
||||||
|
|
||||||
mImage = new QImage( mWidth, mHeight, QImage::Format_ARGB32_Premultiplied );
|
mMapSettings.setOutputSize( QSize( mWidth, mHeight ) );
|
||||||
mImage->fill( 0 );
|
|
||||||
|
|
||||||
mMapRenderer->setOutputSize( QSize( mWidth, mHeight ), mImage->logicalDpiX() );
|
// TODO: do we need the other QPainter flags?
|
||||||
|
mMapSettings.setFlag( QgsMapSettings::Antialiasing, mRendererHints.testFlag( QPainter::Antialiasing ) );
|
||||||
QPainter painter( mImage );
|
|
||||||
|
|
||||||
painter.setRenderHints( mRendererHints );
|
|
||||||
|
|
||||||
for ( int i = 0; i < mIterations; i++ )
|
for ( int i = 0; i < mIterations; i++ )
|
||||||
{
|
{
|
||||||
|
QgsMapRendererQImageJob* job;
|
||||||
|
if ( mParallel )
|
||||||
|
job = new QgsMapRendererParallelJob( mMapSettings );
|
||||||
|
else
|
||||||
|
job = new QgsMapRendererSequentialJob( mMapSettings );
|
||||||
|
|
||||||
start();
|
start();
|
||||||
mMapRenderer->render( &painter );
|
job->start();
|
||||||
|
job->waitForFinished();
|
||||||
elapsed();
|
elapsed();
|
||||||
|
|
||||||
|
mImage = job->renderedImage();
|
||||||
|
delete job;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mLogMap.insert( "iterations", mTimes.size() );
|
mLogMap.insert( "iterations", mTimes.size() );
|
||||||
mLogMap.insert( "revision", QGSVERSION );
|
mLogMap.insert( "revision", QGSVERSION );
|
||||||
|
|
||||||
@ -247,8 +259,6 @@ void QgsBench::render()
|
|||||||
stdev[t] = sqrt( stdev[t] / mTimes.size() );
|
stdev[t] = sqrt( stdev[t] / mTimes.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *pre[] = { "user", "sys", "total", "wall" };
|
|
||||||
|
|
||||||
QMap<QString, QVariant> map;
|
QMap<QString, QVariant> map;
|
||||||
|
|
||||||
map.insert( "min", min[t] );
|
map.insert( "min", min[t] );
|
||||||
@ -265,19 +275,30 @@ void QgsBench::render()
|
|||||||
void QgsBench::saveSnapsot( const QString & fileName )
|
void QgsBench::saveSnapsot( const QString & fileName )
|
||||||
{
|
{
|
||||||
// If format is 0, QImage will attempt to guess the format by looking at fileName's suffix.
|
// If format is 0, QImage will attempt to guess the format by looking at fileName's suffix.
|
||||||
mImage->save( fileName );
|
mImage.save( fileName );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsBench::printLog()
|
void QgsBench::printLog( const QString& printTime )
|
||||||
{
|
{
|
||||||
std::cout << "iterations: " << mLogMap["iterations"].toString().toAscii().constData() << std::endl;
|
std::cout << "iterations: " << mLogMap["iterations"].toString().toAscii().constData() << std::endl;
|
||||||
|
|
||||||
|
bool validPrintTime = false;
|
||||||
|
for ( int x = 0; x < 4; ++x )
|
||||||
|
if ( printTime == pre[x] )
|
||||||
|
validPrintTime = true;
|
||||||
|
|
||||||
|
if ( !validPrintTime )
|
||||||
|
{
|
||||||
|
std::cout << "invalid --print option: " << printTime.toAscii().data() << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QMap<QString, QVariant> timesMap = mLogMap["times"].toMap();
|
QMap<QString, QVariant> timesMap = mLogMap["times"].toMap();
|
||||||
QMap<QString, QVariant> totalMap = timesMap["total"].toMap();
|
QMap<QString, QVariant> totalMap = timesMap[printTime].toMap();
|
||||||
QMap<QString, QVariant>::iterator i = totalMap.begin();
|
QMap<QString, QVariant>::iterator i = totalMap.begin();
|
||||||
while ( i != totalMap.end() )
|
while ( i != totalMap.end() )
|
||||||
{
|
{
|
||||||
QString s = "total_" + i.key() + ": " + i.value().toString();
|
QString s = printTime + "_" + i.key() + ": " + i.value().toString();
|
||||||
std::cout << s.toAscii().constData() << std::endl;
|
std::cout << s.toAscii().constData() << std::endl;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include "qgsmaprenderer.h"
|
#include "qgsmapsettings.h"
|
||||||
|
|
||||||
class QgsBench : public QObject
|
class QgsBench : public QObject
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ class QgsBench : public QObject
|
|||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
void printLog();
|
void printLog( const QString& printTime );
|
||||||
|
|
||||||
bool openProject( const QString & fileName );
|
bool openProject( const QString & fileName );
|
||||||
|
|
||||||
@ -58,6 +58,8 @@ class QgsBench : public QObject
|
|||||||
|
|
||||||
void setRenderHints( QPainter::RenderHints hints ) { mRendererHints = hints; }
|
void setRenderHints( QPainter::RenderHints hints ) { mRendererHints = hints; }
|
||||||
|
|
||||||
|
void setParallel( bool enabled ) { mParallel = enabled; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void readProject( const QDomDocument &doc );
|
void readProject( const QDomDocument &doc );
|
||||||
|
|
||||||
@ -87,9 +89,11 @@ class QgsBench : public QObject
|
|||||||
// user, sys, total times
|
// user, sys, total times
|
||||||
QVector<double*> mTimes;
|
QVector<double*> mTimes;
|
||||||
|
|
||||||
QImage* mImage;
|
QImage mImage;
|
||||||
|
|
||||||
QgsMapRenderer *mMapRenderer;
|
QgsMapSettings mMapSettings;
|
||||||
|
|
||||||
|
bool mParallel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QGSBENCH_H
|
#endif // QGSBENCH_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user