Commit a3a5c936 authored by Guillaume Pasero's avatar Guillaume Pasero

Merge branch 'move_log_setup_info' into 'develop'

LogSetupInformation in CreateInstance is too invasive

See merge request !42
parents 01a00be6 9e9b0e79
......@@ -59,8 +59,15 @@ public:
// Overwrite this to provide custom formatting of log entries
std::string BuildFormattedEntry(itk::Logger::PriorityLevelType, std::string const&) override;
/** Output logs about the RAM, caching and multi-threading settings */
void LogSetupInformation();
/** Return true if the LogSetupInformation has already been called*/
bool IsLogSetupInformationDone();
/** Set the flag m_LogSetupInfoDone to true */
void LogSetupInformationDone();
protected:
Logger();
virtual ~Logger() ITK_OVERRIDE;
......@@ -71,6 +78,8 @@ private:
static Pointer CreateInstance();
bool m_LogSetupInfoDone;
}; // class Logger
} // namespace otb
......
......@@ -38,9 +38,6 @@ Logger::Pointer Logger::CreateInstance()
defaultOutput->SetStream(std::cout);
instance->AddLogOutput(defaultOutput);
// Log setup information
instance->LogSetupInformation();
return instance;
}
......@@ -61,6 +58,8 @@ Logger::Logger()
this->SetTimeStampFormat(itk::LoggerBase::HUMANREADABLE);
this->SetHumanReadableFormat("%Y-%m-%d %H:%M:%S");
m_LogSetupInfoDone = false;
}
Logger::~Logger()
......@@ -69,22 +68,29 @@ Logger::~Logger()
void Logger::LogSetupInformation()
{
std::ostringstream oss;
oss<<"Default RAM limit for OTB is "<<otb::ConfigurationManager::GetMaxRAMHint()<<" MB"<<std::endl;
this->Info(oss.str());
oss.str("");
oss.clear();
oss<<"GDAL maximum cache size is "<<GDALGetCacheMax64()/(1024*1024)<<" MB"<<std::endl;
this->Info(oss.str());
oss.str("");
oss.clear();
oss<<"OTB will use at most "<<itk::MultiThreader::GetGlobalDefaultNumberOfThreads()<<" threads"<<std::endl;
this->Info(oss.str());
oss.str("");
oss.clear();
if (! IsLogSetupInformationDone())
{
std::ostringstream oss;
oss<<"Default RAM limit for OTB is "<<otb::ConfigurationManager::GetMaxRAMHint()<<" MB"<<std::endl;
this->Info(oss.str());
oss.str("");
oss.clear();
oss<<"GDAL maximum cache size is "<<GDALGetCacheMax64()/(1024*1024)<<" MB"<<std::endl;
this->Info(oss.str());
oss.str("");
oss.clear();
oss<<"OTB will use at most "<<itk::MultiThreader::GetGlobalDefaultNumberOfThreads()<<" threads"<<std::endl;
this->Info(oss.str());
oss.str("");
oss.clear();
// only switch the flag for the singleton, so that other instances can call
// LogSetupInformation() several times
Instance()->LogSetupInformationDone();
}
}
std::string Logger::BuildFormattedEntry(itk::Logger::PriorityLevelType level, std::string const & content)
......@@ -116,4 +122,14 @@ std::string Logger::BuildFormattedEntry(itk::Logger::PriorityLevelType level, st
return s.str();
}
bool Logger::IsLogSetupInformationDone()
{
return m_LogSetupInfoDone;
}
void Logger::LogSetupInformationDone()
{
m_LogSetupInfoDone = true;
}
} // namespace otb
......@@ -183,6 +183,8 @@ void
StreamingImageVirtualWriter<TInputImage>
::GenerateData(void)
{
otb::Logger::Instance()->LogSetupInformation();
/**
* Prepare all the outputs. This may deallocate previous bulk data.
*/
......
......@@ -156,7 +156,7 @@ StreamingManager<TImage>::EstimateOptimalNumberOfDivisions(itk::DataObject * inp
unsigned int optimalNumberOfDivisions =
otb::PipelineMemoryPrintCalculator::EstimateOptimalNumberOfStreamDivisions(pipelineMemoryPrint, availableRAMInBytes);
otbLogMacro(Info,<<"Estimated memory for full processing: "<<pipelineMemoryPrint * otb::PipelineMemoryPrintCalculator::ByteToMegabyte<<"MB (avail.: "<<availableRAMInBytes * otb::PipelineMemoryPrintCalculator::ByteToMegabyte<<" NB), optimal image partitioning: "<<optimalNumberOfDivisions<<" blocks");
otbLogMacro(Info,<<"Estimated memory for full processing: "<<pipelineMemoryPrint * otb::PipelineMemoryPrintCalculator::ByteToMegabyte<<"MB (avail.: "<<availableRAMInBytes * otb::PipelineMemoryPrintCalculator::ByteToMegabyte<<" MB), optimal image partitioning: "<<optimalNumberOfDivisions<<" blocks");
return optimalNumberOfDivisions;
}
......
......@@ -279,6 +279,8 @@ ImageFileWriter<TInputImage>
itkExceptionMacro(<< "No input to writer");
}
otb::Logger::Instance()->LogSetupInformation();
/** Parse streaming modes */
if(m_FilenameHelper->StreamingTypeIsSet())
{
......
......@@ -28,7 +28,7 @@
#include <iostream>
#include "itkMultiThreader.h"
#include "itkMacro.h"
#include "otbMacro.h"
#include "otbOGRDriversInit.h"
#include "otbTestHelper.h"
......@@ -298,6 +298,7 @@ int main(int ac, char* av[])
}
else
{
otb::Logger::Instance()->LogSetupInformation();
MainFuncPointer f = j->second;
int result;
try
......
......@@ -645,6 +645,8 @@ int Application::ExecuteAndWriteOutput()
{
m_Chrono.Restart();
m_Logger->LogSetupInformation();
int status = this->Execute();
if (status == 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment