Skip to content

Commit

Permalink
raster interfaces stats fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 1, 2012
1 parent 581df0d commit 2fdd82f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
29 changes: 23 additions & 6 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -15,6 +15,8 @@
* *
***************************************************************************/

#include <typeinfo>

#include <QByteArray>
#include <QTime>

Expand All @@ -23,7 +25,7 @@

QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input )
: mInput( input )
, mTimeMinSize( 300 ) // dont forget resampling!
, mStatsOn( false )
{
}

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

if ( width > mTimeMinSize && height > mTimeMinSize )
if ( mStatsOn )
{
if ( mTime.size() <= bandNo )
{
mTime.resize( bandNo + 1 );
}
// QTime counts only in miliseconds
mTime[bandNo] = time.elapsed();
// We are adding time until next clear, this way the time may be collected
// for the whole QgsRasterLayer::draw() for example, not just for a single part
mTime[bandNo] += time.elapsed();
QgsDebugMsg( QString( "bandNo = %2 time = %3" ).arg( bandNo ).arg( mTime[bandNo] ) );
}
return b;
}

double QgsRasterInterface::time( )
void QgsRasterInterface::setStatsOn( bool on )
{
// We can only count give total time, because we have to subtract time of previous
if ( on )
{
mTime.clear();
}
if ( mInput ) mInput->setStatsOn( on );
mStatsOn = on;
}

double QgsRasterInterface::time( bool cumulative )
{
// We can calculate total time only, because we have to subtract time of previous
// interface(s) and we dont know how to assign bands to each other
double t = 0;
for ( int i = 1; i < mTime.size(); i++ )
{
t += mTime[i];
}
if ( cumulative ) return t;

if ( mInput )
{
t -= mInput->time();
QgsDebugMsgLevel( QString( "%1 cumulative time = %2 time = %3" ).arg( typeid( *( this ) ).name() ).arg( t ).arg( t - mInput->time( true ) ), 3 );
t -= mInput->time( true );
}
return t;
}
15 changes: 9 additions & 6 deletions src/core/raster/qgsrasterinterface.h
Expand Up @@ -147,11 +147,14 @@ class CORE_EXPORT QgsRasterInterface
*/
QImage * createImage( int width, int height, QImage::Format format );

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

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

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

// Minimum block size to record time (to ignore thumbnails etc)
int mTimeMinSize;
// Collect statistics
int mStatsOn;
};

#endif
Expand Down
15 changes: 13 additions & 2 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -832,13 +832,24 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
projector->setCRS( theRasterViewPort->mSrcCRS, theRasterViewPort->mDestCRS );
}

#ifdef QGISDEBUG
// Collect stats only for larger sizes to avoid confusion (small time values)
// after thumbnail render e.g. 120 is current thumbnail size
// TODO: consider another way to switch stats on/off or storing of last significant
// stats somehow
if ( theRasterViewPort->drawableAreaXDim > 120 && theRasterViewPort->drawableAreaYDim > 120 )
{
mPipe.setStatsOn( true );
}
#endif

// Drawer to pipe?
mPipe.clearTime();
QgsRasterDrawer drawer( mPipe.last() );
drawer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );

// Print time stats
#ifdef QGISDEBUG
mPipe.setStatsOn( false );
// Print time stats
QgsDebugMsg( QString( "interface bands time" ) );
for ( int i = 0; i < mPipe.size(); i++ )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterpipe.h
Expand Up @@ -87,8 +87,8 @@ class CORE_EXPORT QgsRasterPipe
QgsRasterResampleFilter * resampleFilter() const;
QgsRasterProjector * projector() const;

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

private:
/** Get known parent type_info of interface parent */
Expand Down

0 comments on commit 2fdd82f

Please sign in to comment.