9 #include <boost/lexical_cast.hpp> 11 #include <fwData/Array.hpp> 13 #include <fwServices/macros.hpp> 15 #include <fwGui/dialog/MessageDialog.hpp> 17 #include "monitor/action/MemoryConsumption.hpp" 25 static std::vector< ::fwData::Array::sptr > memoryConsumer;
33 void MemoryConsumption::pushNewArray(
size_t memorySizeInBytes)
37 ::fwData::Array::sptr buffer = ::fwData::Array::New();
39 buffer->resize(::fwTools::Type::s_UINT8_TYPENAME, size, 1,
true);
41 OSLM_INFO(
"Creating a fwData::array consuming "<< memorySizeInBytes/(1024*1024) <<
" Mo ");
43 memoryConsumer.push_back( buffer );
45 catch( std::exception &e )
47 std::stringstream msg;
48 msg <<
"Cannot allocate buffer (256 Mo) :\n" << e.what() << std::endl;
50 "Action increase memory",
52 ::fwGui::dialog::IMessageDialog::CRITICAL);
59 m_isIncreaseMode(true), m_memorySizeInBytes(1024*1024*256)
75 this->pushNewArray(m_memorySizeInBytes);
79 if( !memoryConsumer.empty() )
81 SLM_INFO(
"Removing one fwData::Array");
82 memoryConsumer.pop_back();
93 ::fwRuntime::ConfigurationElement::sptr consumptionCfg;
95 SLM_ASSERT(
"Missing mode tag", consumptionCfg);
97 SLM_ASSERT(
"Missing attribute 'value'", consumptionCfg->hasAttribute(
"mode"));
98 std::string mode = consumptionCfg->getAttributeValue(
"mode");
99 OSLM_ASSERT(
"Wrong value ("<< mode <<
") for mode tag", mode ==
"increase" || mode ==
"decrease");
100 m_isIncreaseMode = (mode ==
"increase");
102 if(m_isIncreaseMode && consumptionCfg->hasAttribute(
"value"))
104 std::string value = consumptionCfg->getAttributeValue(
"value");
105 size_t sizeInMo = ::boost::lexical_cast<
size_t>(value);
106 m_memorySizeInBytes = sizeInMo * 1024 * 1024;
void starting() override
Calls classic IAction methods to start.
std::vector< size_t > SizeType
Array size type.
void stopping() override
Calls classic IAction methods to stop.
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
#define OSLM_INFO(message)
Defines the service interface managing the menu items.
Increase or decrease the memory consumption by storing a new image, use to experiment dump process...
virtual MONITOR_API ~MemoryConsumption() noexcept
Does nothing.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGUI_API void initialize()
Initialize the action.
Base class for each data object.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
void updating() override
Increase or decrease memory with size defined during configuration.
void configuring() override
Implements configuring method derived from IService. .
The namespace monitor contains tools for monitoring an application built with FW4SPL.
#define SLM_INFO(message)
MONITOR_API MemoryConsumption() noexcept
Does nothing.