fw4spl
MemoryInfo.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "monitor/action/MemoryInfo.hpp"
8 
9 #include <fwGui/dialog/MessageDialog.hpp>
10 
11 #include <fwMemory/BufferManager.hpp>
12 #include <fwMemory/tools/MemoryMonitorTools.hpp>
13 
14 #include <fwServices/macros.hpp>
15 
16 #include <iostream>
17 
18 namespace monitor
19 {
20 namespace action
21 {
22 
23 fwServicesRegisterMacro( ::fwGui::IActionSrv, ::monitor::action::MemoryInfo, ::fwData::Object );
24 
25 //------------------------------------------------------------------------------
26 
27 MemoryInfo::MemoryInfo( ) noexcept
28 {
29 }
30 
31 //------------------------------------------------------------------------------
32 
34 {
35 }
36 
37 //------------------------------------------------------------------------------
38 
40 {
41  // Memory information
42  std::uint64_t mo = 1024*1024;
43  std::uint64_t totalSystemMemory = ::fwMemory::tools::MemoryMonitorTools::getTotalSystemMemory();
44  std::uint64_t freeSystemMemory = ::fwMemory::tools::MemoryMonitorTools::getFreeSystemMemory();
45  std::uint64_t usedProcessMemory = ::fwMemory::tools::MemoryMonitorTools::getUsedProcessMemory();
46  std::uint64_t estimateFreeMem = ::fwMemory::tools::MemoryMonitorTools::estimateFreeMem();
47 
48  ::fwMemory::BufferManager::SizeType managedBufferSize = 0;
49  ::fwMemory::BufferManager::SizeType dumpedBufferSize = 0;
50  ::fwMemory::BufferManager::sptr manager = ::fwMemory::BufferManager::getDefault();
51  if( manager )
52  {
53  ::fwMemory::BufferManager::BufferStats stats = manager->getBufferStats().get();
54  managedBufferSize = stats.totalManaged;
55  dumpedBufferSize = stats.totalDumped;
56  }
57  std::stringstream stream;
58  stream << "Total system memory = " << totalSystemMemory/mo << " Mo" << std::endl;
59  stream << "Free system memory = " << freeSystemMemory/mo << " Mo" << std::endl;
60  stream << "Used process memory = " << usedProcessMemory/mo << " Mo" << std::endl;
61  stream << "Estimed Free memory = " << estimateFreeMem/mo << " Mo" << std::endl;
62  stream << "ManagedBuffer size = " << managedBufferSize/mo << " Mo" << std::endl;
63  stream << "DumpedBuffer size = " << dumpedBufferSize/mo << " Mo" << std::endl;
64 
65  // Information message box
67  "MemoryInfo",
68  stream.str(),
69  ::fwGui::dialog::IMessageDialog::INFO);
70 }
71 
72 //------------------------------------------------------------------------------
73 
75 {
77 }
78 
79 //------------------------------------------------------------------------------
80 
82 {
84 }
85 
86 //------------------------------------------------------------------------------
87 
89 {
91 }
92 
93 //------------------------------------------------------------------------------
94 
95 } // namespace action
96 } // namespace basicVisuCtrl
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
static FWMEMORY_API BufferManager::sptr getDefault()
Returns the current BufferManager instance.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
void updating() override
Shows in a message box few memory information.
Definition: MemoryInfo.cpp:39
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
Base class for each data object.
void stopping() override
Calls classic IAction methods to stop.
Definition: MemoryInfo.cpp:88
The namespace monitor contains tools for monitoring an application built with FW4SPL.
Definition: fwMetrics.hpp:14
Implements an action to show in a message box few memory information.
Definition: MemoryInfo.hpp:20
void configuring() override
Calls classic IAction methods to configure.
Definition: MemoryInfo.cpp:74
virtual MONITOR_API ~MemoryInfo() noexcept
Does nothing.
Definition: MemoryInfo.cpp:33
MONITOR_API MemoryInfo() noexcept
Does nothing.
void starting() override
Calls classic IAction methods to start.
Definition: MemoryInfo.cpp:81