Skip to content

Commit 151bad5

Browse files
committed
Update to qgis_bench: use renderer job, allow parallel mode, print other time
1 parent e814e8d commit 151bad5

File tree

3 files changed

+78
-29
lines changed

3 files changed

+78
-29
lines changed

tests/bench/main.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ void usage( std::string const & appName )
8181
<< "\t[--configpath path]\tuse the given path for all user configuration\n"
8282
<< "\t[--prefix path]\tpath to a different build of qgis, may be used to test old versions\n"
8383
<< "\t[--quality]\trenderer hint(s), comma separated, possible values: Antialiasing,TextAntialiasing,SmoothPixmapTransform,NonCosmeticDefaultPen\n"
84+
<< "\t[--parallel]\trender layers in parallel instead of sequentially\n"
85+
<< "\t[--print type]\twhat kind of time to print, possible values: wall,total,user,sys. Default is total.\n"
8486
<< "\t[--help]\t\tthis text\n\n"
8587
<< " FILES:\n"
8688
<< " Files specified on the command line can include rasters,\n"
@@ -135,6 +137,8 @@ int main( int argc, char *argv[] )
135137
int mySnapshotWidth = 800;
136138
int mySnapshotHeight = 600;
137139
QString myQuality = "";
140+
bool myParallel = false;
141+
QString myPrintTime = "total";
138142

139143
// This behaviour will set initial extent of map canvas, but only if
140144
// there are no command line arguments. This gives a usable map
@@ -173,6 +177,8 @@ int main( int argc, char *argv[] )
173177
{"configpath", required_argument, 0, 'c'},
174178
{"prefix", required_argument, 0, 'r'},
175179
{"quality", required_argument, 0, 'q'},
180+
{"parallel", no_argument, 0, 'P'},
181+
{"print", required_argument, 0, 'R'},
176182
{0, 0, 0, 0}
177183
};
178184

@@ -242,6 +248,14 @@ int main( int argc, char *argv[] )
242248
myQuality = optarg;
243249
break;
244250

251+
case 'P':
252+
myParallel = true;
253+
break;
254+
255+
case 'R':
256+
myPrintTime = optarg;
257+
break;
258+
245259
case '?':
246260
usage( argv[0] );
247261
return 2; // XXX need standard exit codes
@@ -322,6 +336,14 @@ int main( int argc, char *argv[] )
322336
{
323337
myQuality = argv[++i];
324338
}
339+
else if ( arg == "--parallel" || arg == "-P" )
340+
{
341+
myParallel = true;
342+
}
343+
else if ( i + 1 < argc && ( arg == "--print" || arg == "-R" ) )
344+
{
345+
myPrintTime = argv[++i];
346+
}
325347
else
326348
{
327349
myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) );
@@ -476,6 +498,8 @@ int main( int argc, char *argv[] )
476498
qbench->setRenderHints( hints );
477499
}
478500

501+
qbench->setParallel( myParallel );
502+
479503
/////////////////////////////////////////////////////////////////////
480504
// autoload any file names that were passed in on the command line
481505
/////////////////////////////////////////////////////////////////////
@@ -551,7 +575,7 @@ int main( int argc, char *argv[] )
551575
qbench->saveLog( myLogFileName );
552576
}
553577

554-
qbench->printLog();
578+
qbench->printLog( myPrintTime );
555579

556580
delete qbench;
557581
delete myApp;

tests/bench/qgsbench.cpp

+45-24
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
#include "qgsbench.h"
4141
#include "qgslogger.h"
4242
#include "qgsmaplayerregistry.h"
43+
#include "qgsmaprendererjob.h"
4344
#include "qgsproject.h"
44-
#include "qgspallabeling.h"
45+
46+
const char *pre[] = { "user", "sys", "total", "wall" };
4547

4648
#ifdef Q_OS_WIN
4749
// 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 )
117119
#endif
118120

119121
QgsBench::QgsBench( int theWidth, int theHeight, int theIterations )
120-
: QObject(), mWidth( theWidth ), mHeight( theHeight ), mIterations( theIterations ), mSetExtent( false )
122+
: QObject()
123+
, mWidth( theWidth )
124+
, mHeight( theHeight )
125+
, mIterations( theIterations )
126+
, mSetExtent( false )
127+
, mParallel( false )
121128
{
122129
QgsDebugMsg( "entered" );
123130

124131
QgsDebugMsg( QString( "mIterations = %1" ).arg( mIterations ) );
125132

126-
mMapRenderer = new QgsMapRenderer;
127-
128133
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
129134
this, SLOT( readProject( const QDomDocument & ) ) );
130135
}
@@ -153,7 +158,7 @@ void QgsBench::readProject( const QDomDocument &doc )
153158
if ( nodes.count() )
154159
{
155160
QDomNode node = nodes.item( 0 );
156-
mMapRenderer->readXML( node );
161+
mMapSettings.readXML( node );
157162
}
158163
else
159164
{
@@ -171,17 +176,17 @@ void QgsBench::render()
171176
{
172177
QgsDebugMsg( "entered" );
173178

174-
QgsDebugMsg( "extent: " + mMapRenderer->extent().toString() );
179+
QgsDebugMsg( "extent: " + mMapSettings.extent().toString() );
175180

176181
QMap<QString, QgsMapLayer*> layersMap = QgsMapLayerRegistry::instance()->mapLayers();
177182

178183
QStringList layers( layersMap.keys() );
179184

180-
mMapRenderer->setLayerSet( layers );
185+
mMapSettings.setLayers( layers );
181186

182187
if ( mSetExtent )
183188
{
184-
mMapRenderer->setExtent( mExtent );
189+
mMapSettings.setExtent( mExtent );
185190
}
186191

187192
// Maybe in future
@@ -190,27 +195,34 @@ void QgsBench::render()
190195
//mMapRenderer->setDestinationCrs( outputCRS );
191196

192197
// TODO: this should be probably set according to project
193-
mMapRenderer->setProjectionsEnabled( true );
198+
mMapSettings.setCrsTransformEnabled( true );
194199

195200
// Enable labeling
196-
mMapRenderer->setLabelingEngine( new QgsPalLabeling() );
197-
198-
mImage = new QImage( mWidth, mHeight, QImage::Format_ARGB32_Premultiplied );
199-
mImage->fill( 0 );
201+
mMapSettings.setFlag( QgsMapSettings::DrawLabeling );
200202

201-
mMapRenderer->setOutputSize( QSize( mWidth, mHeight ), mImage->logicalDpiX() );
203+
mMapSettings.setOutputSize( QSize( mWidth, mHeight ) );
202204

203-
QPainter painter( mImage );
204-
205-
painter.setRenderHints( mRendererHints );
205+
// TODO: do we need the other QPainter flags?
206+
mMapSettings.setFlag( QgsMapSettings::Antialiasing, mRendererHints.testFlag( QPainter::Antialiasing ) );
206207

207208
for ( int i = 0; i < mIterations; i++ )
208209
{
210+
QgsMapRendererQImageJob* job;
211+
if ( mParallel )
212+
job = new QgsMapRendererParallelJob( mMapSettings );
213+
else
214+
job = new QgsMapRendererSequentialJob( mMapSettings );
215+
209216
start();
210-
mMapRenderer->render( &painter );
217+
job->start();
218+
job->waitForFinished();
211219
elapsed();
220+
221+
mImage = job->renderedImage();
222+
delete job;
212223
}
213224

225+
214226
mLogMap.insert( "iterations", mTimes.size() );
215227
mLogMap.insert( "revision", QGSVERSION );
216228

@@ -247,8 +259,6 @@ void QgsBench::render()
247259
stdev[t] = sqrt( stdev[t] / mTimes.size() );
248260
}
249261

250-
const char *pre[] = { "user", "sys", "total", "wall" };
251-
252262
QMap<QString, QVariant> map;
253263

254264
map.insert( "min", min[t] );
@@ -265,19 +275,30 @@ void QgsBench::render()
265275
void QgsBench::saveSnapsot( const QString & fileName )
266276
{
267277
// If format is 0, QImage will attempt to guess the format by looking at fileName's suffix.
268-
mImage->save( fileName );
278+
mImage.save( fileName );
269279
}
270280

271-
void QgsBench::printLog()
281+
void QgsBench::printLog( const QString& printTime )
272282
{
273283
std::cout << "iterations: " << mLogMap["iterations"].toString().toAscii().constData() << std::endl;
274284

285+
bool validPrintTime = false;
286+
for ( int x = 0; x < 4; ++x )
287+
if ( printTime == pre[x] )
288+
validPrintTime = true;
289+
290+
if ( !validPrintTime )
291+
{
292+
std::cout << "invalid --print option: " << printTime.toAscii().data() << std::endl;
293+
return;
294+
}
295+
275296
QMap<QString, QVariant> timesMap = mLogMap["times"].toMap();
276-
QMap<QString, QVariant> totalMap = timesMap["total"].toMap();
297+
QMap<QString, QVariant> totalMap = timesMap[printTime].toMap();
277298
QMap<QString, QVariant>::iterator i = totalMap.begin();
278299
while ( i != totalMap.end() )
279300
{
280-
QString s = "total_" + i.key() + ": " + i.value().toString();
301+
QString s = printTime + "_" + i.key() + ": " + i.value().toString();
281302
std::cout << s.toAscii().constData() << std::endl;
282303
++i;
283304
}

tests/bench/qgsbench.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <QVariant>
2828
#include <QVector>
2929

30-
#include "qgsmaprenderer.h"
30+
#include "qgsmapsettings.h"
3131

3232
class QgsBench : public QObject
3333
{
@@ -44,7 +44,7 @@ class QgsBench : public QObject
4444

4545
void render();
4646

47-
void printLog();
47+
void printLog( const QString& printTime );
4848

4949
bool openProject( const QString & fileName );
5050

@@ -58,6 +58,8 @@ class QgsBench : public QObject
5858

5959
void setRenderHints( QPainter::RenderHints hints ) { mRendererHints = hints; }
6060

61+
void setParallel( bool enabled ) { mParallel = enabled; }
62+
6163
public slots:
6264
void readProject( const QDomDocument &doc );
6365

@@ -87,9 +89,11 @@ class QgsBench : public QObject
8789
// user, sys, total times
8890
QVector<double*> mTimes;
8991

90-
QImage* mImage;
92+
QImage mImage;
93+
94+
QgsMapSettings mMapSettings;
9195

92-
QgsMapRenderer *mMapRenderer;
96+
bool mParallel;
9397
};
9498

9599
#endif // QGSBENCH_H

0 commit comments

Comments
 (0)