Commit 4609c856 authored by Laurentiu Nicola's avatar Laurentiu Nicola

PERF: Replace itk::TimeProbe with otb::Stopwatch

parent 7afea3ff
......@@ -46,8 +46,6 @@
#include <otbImageFileReader.h>
#include "otbImageFileWriter.h"
#include "itkTimeProbe.h"
int main(int itkNotUsed(argc), char * argv[])
{
......
......@@ -25,7 +25,7 @@
#include "otbGeometriesToGeometriesFilter.h"
#include <cassert>
#include "otbGeometriesSet.h"
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
#include "otbMacro.h"
/*===========================================================================*/
......@@ -200,8 +200,7 @@ void otb::GeometriesToGeometriesFilter::GenerateData(void )
assert(output && "Cann't filter a nil geometries set");
// Start recursive processing
itk::TimeProbe chrono;
chrono.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
if (input)
{
this->Process(*input, *output);
......@@ -212,7 +211,7 @@ void otb::GeometriesToGeometriesFilter::GenerateData(void )
}
chrono.Stop();
otbMsgDevMacro(<< "GeometriesToGeometriesFilter: geometries processed in " << chrono.GetMean() << " seconds.");
otbMsgDevMacro(<< "GeometriesToGeometriesFilter: geometries processed in " << chrono.GetElapsedMilliseconds() << " ms.");
}
/*virtual*/
......
......@@ -29,7 +29,6 @@
// Statistic XML Reader
#include "otbStatisticsXMLFileReader.h"
#include "itkTimeProbe.h"
#include "otbStandardFilterWatcher.h"
// Normalize the samples
......
......@@ -18,6 +18,8 @@
* limitations under the License.
*/
#include <numeric>
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
......
......@@ -26,8 +26,6 @@
#include "otbMultiToMonoChannelExtractROI.h"
#include "itkTimeProbe.h"
namespace otb
{
namespace Wrapper
......
......@@ -34,8 +34,6 @@
#include "otbImageList.h"
#include "otbImageListToVectorImageFilter.h"
#include "itkTimeProbe.h"
namespace otb
{
namespace Wrapper
......
......@@ -34,8 +34,6 @@
#include "otbImageList.h"
#include "otbImageListToVectorImageFilter.h"
#include "itkTimeProbe.h"
namespace otb
{
namespace Wrapper
......
......@@ -35,7 +35,6 @@
#include "otbImageList.h"
#include "otbImageListToVectorImageFilter.h"
#include "itkTimeProbe.h"
#include "otbConvexOrConcaveClassificationFilter.h"
#include "otbMorphologicalProfilesSegmentationFilter.h"
......
......@@ -35,7 +35,6 @@
#include "otbImageList.h"
#include "otbImageListToVectorImageFilter.h"
#include "itkTimeProbe.h"
#include "otbConvexOrConcaveClassificationFilter.h"
#include "otbMorphologicalProfilesSegmentationFilter.h"
#include "otbGeodesicMorphologyIterativeDecompositionImageFilter.h"
......
......@@ -36,7 +36,6 @@
#include "otbImageList.h"
#include "otbImageListToVectorImageFilter.h"
#include "itkTimeProbe.h"
#include "otbConvexOrConcaveClassificationFilter.h"
#include "otbMorphologicalProfilesSegmentationFilter.h"
#include "otbGeodesicMorphologyIterativeDecompositionImageFilter.h"
......
......@@ -28,8 +28,6 @@
#include "otbImageList.h"
#include "otbImageListToVectorImageFilter.h"
#include "itkTimeProbe.h"
namespace otb
{
namespace Wrapper
......
......@@ -22,9 +22,9 @@
#ifndef otbFilterWatcherBase_h
#define otbFilterWatcherBase_h
#include "otbStopwatch.h"
#include "itkCommand.h"
#include "itkProcessObject.h"
#include "itkTimeProbe.h"
#include "OTBCommonExport.h"
......@@ -82,10 +82,10 @@ public:
return m_Comment;
}
/** Get a reference to the TimeProbe */
itk::TimeProbe& GetTimeProbe()
/** Get a reference to the Stopwatch */
otb::Stopwatch& GetStopwatch()
{
return m_TimeProbe;
return m_Stopwatch;
}
protected:
......@@ -126,7 +126,7 @@ protected:
virtual void EndFilter() = 0;
/** Computing time */
itk::TimeProbe m_TimeProbe;
otb::Stopwatch m_Stopwatch;
/** Associated comment */
std::string m_Comment;
......
......@@ -22,9 +22,10 @@
#ifndef otbWriterWatcherBase_h
#define otbWriterWatcherBase_h
#include "otbStopwatch.h"
#include "itkCommand.h"
#include "itkProcessObject.h"
#include "itkTimeProbe.h"
#include "OTBCommonExport.h"
......@@ -89,10 +90,10 @@ public:
return m_Comment;
}
/** Get a reference to the TimeProbe */
itk::TimeProbe& GetTimeProbe()
/** Get a reference to the Stopwatch */
otb::Stopwatch& GetStopwatch()
{
return m_TimeProbe;
return m_Stopwatch;
}
protected:
......@@ -116,7 +117,7 @@ protected:
virtual void EndFilter() = 0;
/** Computing time */
itk::TimeProbe m_TimeProbe;
otb::Stopwatch m_Stopwatch;
/** Associated comment */
std::string m_Comment;
......
......@@ -81,7 +81,7 @@ FilterWatcherBase
}
// Initialize state
m_TimeProbe = watch.m_TimeProbe;
m_Stopwatch = watch.m_Stopwatch;
m_Process = watch.m_Process;
m_Comment = watch.m_Comment;
......@@ -125,7 +125,7 @@ FilterWatcherBase
}
// Initialize state
m_TimeProbe = watch.m_TimeProbe;
m_Stopwatch = watch.m_Stopwatch;
m_Process = watch.m_Process;
m_Comment = watch.m_Comment;
......
......@@ -100,7 +100,7 @@ void
StandardFilterWatcher
::StartFilter()
{
m_TimeProbe.Start();
m_Stopwatch.Start();
std::cout << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
<< " \"" << m_Comment << "\" " << std::endl;
}
......@@ -109,9 +109,9 @@ void
StandardFilterWatcher
::EndFilter()
{
m_TimeProbe.Stop();
m_Stopwatch.Stop();
std::cout << std::endl << "Filter took "
<< m_TimeProbe.GetMean()
<< m_Stopwatch.GetElapsedMilliseconds() / 1000
<< " seconds." << std::endl;
}
} // end namespace otb
......@@ -94,19 +94,19 @@ void
StandardOneLineFilterWatcher
::StartFilter()
{
m_TimeProbe.Start();
m_Stopwatch.Start();
}
void
StandardOneLineFilterWatcher
::EndFilter()
{
m_TimeProbe.Stop();
m_Stopwatch.Stop();
// Ensure we don't depend on std::cout configuration
std::ostringstream elapsedTime;
elapsedTime.precision(1);
elapsedTime << m_TimeProbe.GetMean();
elapsedTime << m_Stopwatch.GetElapsedMilliseconds() / 1000;
std::cout << " ("
<< elapsedTime.str()
......
......@@ -147,7 +147,7 @@ void
StandardWriterWatcher
::StartWriter()
{
m_TimeProbe.Start();
m_Stopwatch.Start();
std::cout << "Writing task: " << " \"" << m_Comment << "\" " << std::endl;
std::cout << "Writer type: " << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None") << std::endl;
std::cout << "Filter type: " << (m_SourceProcess.GetPointer() ? m_SourceProcess->GetNameOfClass() : "None") <<
......@@ -158,9 +158,9 @@ void
StandardWriterWatcher
::EndWriter()
{
m_TimeProbe.Stop();
m_Stopwatch.Stop();
std::cout << std::endl << "Writing task took "
<< m_TimeProbe.GetMean()
<< m_Stopwatch.GetElapsedMilliseconds() / 1000
<< " seconds." << std::endl;
}
......
......@@ -188,7 +188,7 @@ WriterWatcherBase
}
// Initialize state
m_TimeProbe = watch.m_TimeProbe;
m_Stopwatch = watch.m_Stopwatch;
m_Process = watch.m_Process;
m_SourceProcess = watch.m_SourceProcess;
m_Comment = watch.m_Comment;
......@@ -281,7 +281,7 @@ WriterWatcherBase
}
// Initialize state
m_TimeProbe = watch.m_TimeProbe;
m_Stopwatch = watch.m_Stopwatch;
m_Process = watch.m_Process;
m_SourceProcess = watch.m_SourceProcess;
m_Comment = watch.m_Comment;
......
......@@ -26,7 +26,7 @@
#include "otbImage.h"
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
template <typename InputPixelType /*= unsigned char */, typename OutputPixelType /*= unsigned char*/>
......@@ -130,20 +130,11 @@ int generic_otbMultiChannelExtractROI(int itkNotUsed(argc), char * argv[], const
writer->SetInput(extractROIFilter->GetOutput());
itk::TimeProbe chrono;
if (computeExtractTime)
{
chrono.Start();
}
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
writer->Update();
if (computeExtractTime)
{
chrono.Stop();
std::cout << " Time to compute the extracted image: " << chrono.GetTotal() << " seconds" << std::endl;
}
std::cout << " Time to compute the extracted image: " << chrono.GetElapsedMilliseconds() << " ms" << std::endl;
std::cout << " Number of channels in the input image: " << reader->GetOutput()->GetNumberOfComponentsPerPixel() <<
std::endl;
......
......@@ -26,7 +26,7 @@
#include "otbVectorData.h"
#include "otbVectorDataProjectionFilter.h"
#include "otbVectorDataFileWriter.h"
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
#include "itkMinimumMaximumImageCalculator.h"
#include "otbCorrectPolygonFunctor.h"
......@@ -87,15 +87,13 @@ int otbLabelObjectMapVectorizer(int argc, char * argv[])
data->GetDataTree()->Add(folder1, document);
data->SetProjectionRef(lreader->GetOutput()->GetProjectionRef());
itk::TimeProbe chrono;
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
// If a label is given, extract only this label
if (argc == 4)
{
std::cout << "Label is given; Vectorizing object " << atoi(argv[3]) << std::endl;
chrono.Start();
PolygonType::Pointer polygon = functor(labelMapFilter->GetOutput()->GetLabelObject(atoi(argv[3])));
chrono.Stop();
//correct polygon
PolygonType::Pointer correct_polygon = correctPolygon(polygon);
......@@ -117,9 +115,7 @@ int otbLabelObjectMapVectorizer(int argc, char * argv[])
if (labelMapFilter->GetOutput()->HasLabel(label) && label != labelMapFilter->GetOutput()->GetBackgroundValue())
{
std::cout << "Vectorizing object " << label << std::endl;
chrono.Start();
PolygonType::Pointer polygon = functor(labelMapFilter->GetOutput()->GetLabelObject(label));
chrono.Stop();
//correct polygon
PolygonType::Pointer correct_polygon = correctPolygon(polygon);
......@@ -131,7 +127,8 @@ int otbLabelObjectMapVectorizer(int argc, char * argv[])
}
}
}
std::cout << "Average vectorization time: " << chrono.GetMean() << " s." << std::endl;
std::cout << "Total vectorization time: " << chrono.GetElapsedMilliseconds() << " ms." << std::endl;
VectorDataFilterType::Pointer vectorDataProjection = VectorDataFilterType::New();
vectorDataProjection->SetInputOrigin(lreader->GetOutput()->GetOrigin());
......
......@@ -25,11 +25,11 @@
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbStopwatch.h"
#include "otbConvolutionImageFilter.h"
#include "otbOverlapSaveConvolutionImageFilter.h"
#include "otbGaborFilterGenerator.h"
#include "itkConstantBoundaryCondition.h"
#include "itkTimeProbe.h"
int otbCompareOverlapSaveAndClassicalConvolutionWithGaborFilter(int argc, char *argv[])
{
......@@ -82,8 +82,6 @@ int otbCompareOverlapSaveAndClassicalConvolutionWithGaborFilter(int argc, char *
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(infname);
itk::TimeProbe probe1, probe2;
ConvolutionFilterType::Pointer convolution = ConvolutionFilterType::New();
convolution->SetRadius(radius);
convolution->SetFilter(filter);
......@@ -93,11 +91,10 @@ int otbCompareOverlapSaveAndClassicalConvolutionWithGaborFilter(int argc, char *
writer1->SetInput(convolution->GetOutput());
writer1->SetFileName(outfname1);
probe1.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
writer1->Update();
probe1.Stop();
std::cout << "Classical convolution algorithm took " << probe1.GetMean() << " seconds." << std::endl;
std::cout << "Classical convolution algorithm took " << chrono.GetElapsedMilliseconds() << " ms." << std::endl;
OSConvolutionFilterType::Pointer osconvolution = OSConvolutionFilterType::New();
osconvolution->SetRadius(radius);
......@@ -108,11 +105,10 @@ int otbCompareOverlapSaveAndClassicalConvolutionWithGaborFilter(int argc, char *
writer2->SetInput(osconvolution->GetOutput());
writer2->SetFileName(outfname2);
probe2.Start();
chrono.Restart();
writer2->Update();
probe2.Stop();
std::cout << "Overlap-save convolution algorithm took " << probe2.GetMean() << " seconds." << std::endl;
std::cout << "Overlap-save convolution algorithm took " << chrono.GetElapsedMilliseconds() << " ms." << std::endl;
return EXIT_SUCCESS;
}
......@@ -25,7 +25,7 @@
#include "itkProgressReporter.h"
#include "itkMetaDataObject.h"
#include "otbMetaDataKey.h"
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
namespace otb
{
......@@ -358,11 +358,10 @@ VectorDataProjectionFilter<TInputVectorData, TOutputVectorData>
tree->SetRoot(outputRoot);
// Start recursive processing
itk::TimeProbe chrono;
chrono.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
this->ProcessNode(inputRoot, outputRoot);
chrono.Stop();
otbMsgDevMacro(<< "VectoDataProjectionFilter: features Processed in " << chrono.GetMean() << " seconds.");
otbMsgDevMacro(<< "VectoDataProjectionFilter: features processed in " << chrono.GetElapsedMilliseconds() << " ms.");
}
} // end namespace otb
......
......@@ -24,7 +24,7 @@
#include "otbVectorDataTransformFilter.h"
#include "itkProgressReporter.h"
#include <itkContinuousIndex.h>
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
namespace otb
{
......@@ -163,10 +163,10 @@ VectorDataTransformFilter<TInputVectorData, TOutputVectorData>
tree->SetRoot(outputRoot);
// Start recursive processing
itk::TimeProbe chrono;
chrono.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
this->ProcessNode(inputRoot, outputRoot);
chrono.Stop();
otbMsgDevMacro(<< "VectorDataTransformFilter: features processed in " << chrono.GetElapsedMilliseconds() << " ms.");
}
} // end namespace otb
......
......@@ -24,7 +24,6 @@
#include "otbConcatenateVectorDataFilter.h"
#include "otbMath.h"
#include "itkTimeProbe.h"
namespace otb
{
......
......@@ -31,7 +31,7 @@
#include "otbMacro.h"
#include "itkProgressReporter.h"
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
namespace otb
{
......@@ -110,12 +110,11 @@ VectorDataExtractROI<TVectorData>
m_Kept = 0;
// Start recursive processing
itk::TimeProbe chrono;
chrono.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
ProcessNode(inputRoot, outputRoot);
chrono.Stop();
otbMsgDevMacro(
<< "VectorDataExtractROI: " << m_Kept << " Features processed in " << chrono.GetMean() << " seconds.");
<< "VectorDataExtractROI: " << m_Kept << " features processed in " << chrono.GetElapsedMilliseconds() << " ms.");
} /*End GenerateData()*/
template <class TVectorData>
......
......@@ -24,7 +24,7 @@
#include "otbVectorDataToVectorDataFilter.h"
#include "itkProgressReporter.h"
#include "otbDataNode.h"
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
namespace otb
{
......@@ -104,11 +104,10 @@ VectorDataToVectorDataFilter<TInputVectorData, TOutputVectorData>
tree->SetRoot(outputRoot);
// Start recursive processing
itk::TimeProbe chrono;
chrono.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
this->ProcessNode(inputRoot, outputRoot);
chrono.Stop();
otbMsgDevMacro(<< "VectoDataProjectionFilter: features Processed in " << chrono.GetMean() << " seconds.");
otbMsgDevMacro(<< "VectoDataProjectionFilter: features processed in " << chrono.GetElapsedMilliseconds() << " ms.");
}
template <class TInputVectorData, class TOutputVectorData>
......
......@@ -28,8 +28,6 @@
#include "otbNeighborhoodMajorityVotingImageFilter.h"
#include "itkTimeProbe.h"
int otbNeighborhoodMajorityVotingImageFilterTest(int argc, char* argv[])
{
......
......@@ -25,6 +25,7 @@
#include "otbGDALImageIO.h"
#include "otbMacro.h"
#include "otbSystem.h"
#include "otbStopwatch.h"
#include "itksys/SystemTools.hxx"
#include "otbImage.h"
#include "otb_tinyxml.h"
......@@ -35,7 +36,6 @@
#include "itkRGBPixel.h"
#include "itkRGBAPixel.h"
#include "itkTimeProbe.h"
#include "cpl_conv.h"
#include "ogr_spatialref.h"
......@@ -408,8 +408,7 @@ void GDALImageIO::Read(void* buffer)
<< " lineOffset = " << lineOffset << "\n"
<< " bandOffset = " << bandOffset );
itk::TimeProbe chrono;
chrono.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
CPLErr lCrGdal = m_Dataset->GetDataSet()->RasterIO(GF_Read,
lFirstColumn,
lFirstLine,
......@@ -426,7 +425,7 @@ void GDALImageIO::Read(void* buffer)
lineOffset,
bandOffset);
chrono.Stop();
otbMsgDevMacro(<< "RasterIO Read took " << chrono.GetTotal() << " sec")
otbMsgDevMacro(<< "RasterIO Read took " << chrono.GetElapsedMilliseconds() << " ms")
// Check if gdal call succeed
if (lCrGdal == CE_Failure)
......@@ -1387,8 +1386,7 @@ void GDALImageIO::Write(const void* buffer)
"\n, Line offset =" << m_BytePerPixel * m_NbBands * lNbColumns << // is pixelOffset * nbColumns
"\n, Band offset =" << m_BytePerPixel) // is BytePerPixel
itk::TimeProbe chrono;
chrono.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
CPLErr lCrGdal = m_Dataset->GetDataSet()->RasterIO(GF_Write,
lFirstColumn,
lFirstLine,
......@@ -1410,7 +1408,7 @@ void GDALImageIO::Write(const void* buffer)
// Band offset is BytePerPixel
m_BytePerPixel);
chrono.Stop();
otbMsgDevMacro(<< "RasterIO Write took " << chrono.GetTotal() << " sec")
otbMsgDevMacro(<< "RasterIO Write took " << chrono.GetElapsedMilliseconds() << " ms")
// Check if writing succeed
if (lCrGdal == CE_Failure)
......
......@@ -23,7 +23,7 @@
#include "otbMacro.h"
#include "ogrsf_frmts.h"
#include "otbOGR.h"
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
namespace otb
{
......@@ -188,11 +188,10 @@ void OGRIOHelper
layer->ResetReading();
unsigned int counter = 0;
itk::TimeProbe chrono;
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
while ((feature = layer->GetNextFeature()) != ITK_NULLPTR)
{
chrono.Start();
// A pointer to the current multi-geometry
InternalTreeNodeType::Pointer multiPtr;
......@@ -203,7 +202,6 @@ void OGRIOHelper
if (geometry == ITK_NULLPTR)
{
OGRFeature::DestroyFeature(feature);
chrono.Stop();
++counter;
continue;
}
......@@ -642,11 +640,12 @@ void OGRIOHelper
OGRFeature::DestroyFeature(feature);
chrono.Stop();
++counter;
} //end While feature
chrono.Stop();
otbMsgDevMacro(
<< layer->GetFeatureCount() << " features read, average insertion time " << chrono.GetMean() << " s");
<< layer->GetFeatureCount() << " features read, total processing time " << chrono.GetElapsedMilliseconds() << " ms");
}
......
......@@ -27,7 +27,7 @@
#include "otbMacro.h"
#include "otbDataNode.h"
#include "otbMetaDataKey.h"
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
#include "otbOGRIOHelper.h"
namespace otb
......@@ -204,8 +204,7 @@ bool OGRVectorDataIO::CanWriteFile(const char* filename) const
void OGRVectorDataIO::Write(const itk::DataObject* datag, char ** /** unused */)
{
itk::TimeProbe chrono;
chrono.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
VectorDataConstPointerType data = dynamic_cast<const VectorDataType*>(datag);
......@@ -298,7 +297,7 @@ void OGRVectorDataIO::Write(const itk::DataObject* datag, char ** /** unused */)
}
chrono.Stop();
otbMsgDevMacro( << "OGRVectorDataIO: file saved in " << chrono.GetMean() << " seconds. (" << layerKept <<
otbMsgDevMacro( << "OGRVectorDataIO: file saved in " << chrono.GetElapsedMilliseconds() << " ms. (" << layerKept <<
" elements)" );
otbMsgDevMacro(<< " OGRVectorDataIO::Write() ");
......
......@@ -38,7 +38,7 @@
#include "otbDataNode.h"
#include "itkPreOrderTreeIterator.h"
#include "otbMetaDataKey.h"
#include "itkTimeProbe.h"
#include "otbStopwatch.h"
namespace otb
......@@ -525,8 +525,7 @@ bool KMLVectorDataIO::CanWriteFile(const char* filename) const
void KMLVectorDataIO::Write(const itk::DataObject* datag, char ** itkNotUsed(papszOptions))
{
itk::TimeProbe chrono;
chrono.Start();
otb::Stopwatch chrono = otb::Stopwatch::StartNew();
// Retrieve data required for georeferencing
VectorDataConstPointerType data_in = dynamic_cast<const VectorDataType*>(datag);
......@@ -600,7 +599,7 @@ void KMLVectorDataIO::Write(const itk::DataObject* datag, char ** itkNotUsed(pap
//std::cout << xml;
chrono.Stop();
otbMsgDevMacro(<< "KMLVectorDataIO: file saved in " << chrono.GetMean() << " seconds. (" << m_Kept << " elements)" );
otbMsgDevMacro(<< "KMLVectorDataIO: file saved in " << chrono.GetElapsedMilliseconds() << " ms. (" << m_Kept << " elements)" );
otbMsgDevMacro(<< " KMLVectorDataIO::Write() ");
}
......
......@@ -33,7 +33,6 @@
#include "otbGDALImageIO.h"
#include "itkTimeProbe.h"
#include "otbCurlHelper.h"
#include "otbImageKeywordlist.h"
......
......@@ -22,7 +22,6 @@
#define otbOGRDataToSamplePositionFilter_txx
#include "otbOGRDataToSamplePositionFilter.h"
#include "itkTimeProbe.h"
namespace otb
{
......