Skip to content

Commit 2fdd82f

Browse files
committedJul 1, 2012
raster interfaces stats fixes
1 parent 581df0d commit 2fdd82f

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed
 

‎src/core/raster/qgsrasterinterface.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* *
1616
***************************************************************************/
1717

18+
#include <typeinfo>
19+
1820
#include <QByteArray>
1921
#include <QTime>
2022

@@ -23,7 +25,7 @@
2325

2426
QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input )
2527
: mInput( input )
26-
, mTimeMinSize( 300 ) // dont forget resampling!
28+
, mStatsOn( false )
2729
{
2830
}
2931

@@ -51,31 +53,46 @@ void * QgsRasterInterface::block( int bandNo, QgsRectangle const & extent, int
5153
time.start();
5254
void * b = readBlock( bandNo, extent, width, height );
5355

54-
if ( width > mTimeMinSize && height > mTimeMinSize )
56+
if ( mStatsOn )
5557
{
5658
if ( mTime.size() <= bandNo )
5759
{
5860
mTime.resize( bandNo + 1 );
5961
}
6062
// QTime counts only in miliseconds
61-
mTime[bandNo] = time.elapsed();
63+
// We are adding time until next clear, this way the time may be collected
64+
// for the whole QgsRasterLayer::draw() for example, not just for a single part
65+
mTime[bandNo] += time.elapsed();
6266
QgsDebugMsg( QString( "bandNo = %2 time = %3" ).arg( bandNo ).arg( mTime[bandNo] ) );
6367
}
6468
return b;
6569
}
6670

67-
double QgsRasterInterface::time( )
71+
void QgsRasterInterface::setStatsOn( bool on )
6872
{
69-
// We can only count give total time, because we have to subtract time of previous
73+
if ( on )
74+
{
75+
mTime.clear();
76+
}
77+
if ( mInput ) mInput->setStatsOn( on );
78+
mStatsOn = on;
79+
}
80+
81+
double QgsRasterInterface::time( bool cumulative )
82+
{
83+
// We can calculate total time only, because we have to subtract time of previous
7084
// interface(s) and we dont know how to assign bands to each other
7185
double t = 0;
7286
for ( int i = 1; i < mTime.size(); i++ )
7387
{
7488
t += mTime[i];
7589
}
90+
if ( cumulative ) return t;
91+
7692
if ( mInput )
7793
{
78-
t -= mInput->time();
94+
QgsDebugMsgLevel( QString( "%1 cumulative time = %2 time = %3" ).arg( typeid( *( this ) ).name() ).arg( t ).arg( t - mInput->time( true ) ), 3 );
95+
t -= mInput->time( true );
7996
}
8097
return t;
8198
}

‎src/core/raster/qgsrasterinterface.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,14 @@ class CORE_EXPORT QgsRasterInterface
147147
*/
148148
QImage * createImage( int width, int height, QImage::Format format );
149149

150-
/** Clear last rendering time */
151-
void clearTime() { mTime.clear(); if ( mInput ) mInput->clearTime(); }
150+
/** Switch on (and clear old statistics) or off collection of statistics */
151+
void setStatsOn( bool on );
152152

153-
/** Last total time (for allbands) consumed by this interface for call to block() */
154-
double time();
153+
/** Last total time (for allbands) consumed by this interface for call to block()
154+
* If cumulative is true, the result includes also time spent in all preceding
155+
* interfaces. If cumulative is false, only time consumed by this interface is
156+
* returned. */
157+
double time( bool cumulative = false );
155158

156159
protected:
157160
// QgsRasterInterface used as input
@@ -161,8 +164,8 @@ class CORE_EXPORT QgsRasterInterface
161164
// Last rendering cumulative (this and all preceding interfaces) times, from index 1
162165
QVector<double> mTime;
163166

164-
// Minimum block size to record time (to ignore thumbnails etc)
165-
int mTimeMinSize;
167+
// Collect statistics
168+
int mStatsOn;
166169
};
167170

168171
#endif

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,13 +832,24 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
832832
projector->setCRS( theRasterViewPort->mSrcCRS, theRasterViewPort->mDestCRS );
833833
}
834834

835+
#ifdef QGISDEBUG
836+
// Collect stats only for larger sizes to avoid confusion (small time values)
837+
// after thumbnail render e.g. 120 is current thumbnail size
838+
// TODO: consider another way to switch stats on/off or storing of last significant
839+
// stats somehow
840+
if ( theRasterViewPort->drawableAreaXDim > 120 && theRasterViewPort->drawableAreaYDim > 120 )
841+
{
842+
mPipe.setStatsOn( true );
843+
}
844+
#endif
845+
835846
// Drawer to pipe?
836-
mPipe.clearTime();
837847
QgsRasterDrawer drawer( mPipe.last() );
838848
drawer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
839849

840-
// Print time stats
841850
#ifdef QGISDEBUG
851+
mPipe.setStatsOn( false );
852+
// Print time stats
842853
QgsDebugMsg( QString( "interface bands time" ) );
843854
for ( int i = 0; i < mPipe.size(); i++ )
844855
{

‎src/core/raster/qgsrasterpipe.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class CORE_EXPORT QgsRasterPipe
8787
QgsRasterResampleFilter * resampleFilter() const;
8888
QgsRasterProjector * projector() const;
8989

90-
/** Clear last rendering time */
91-
void clearTime() { if ( last() ) last()->clearTime(); }
90+
/** Set on/off collection of statistics */
91+
void setStatsOn( bool on ) { if ( last() ) last()->setStatsOn( on ); }
9292

9393
private:
9494
/** Get known parent type_info of interface parent */

0 commit comments

Comments
 (0)
Please sign in to comment.