Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / ace / Monitor_Control / Memory_Usage_Monitor.cpp
blobab288a05dfac7c8e9f8661d95206460bf6d48f8a
1 #include "ace/Monitor_Control/Memory_Usage_Monitor.h"
3 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
5 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
7 namespace ACE
9 namespace Monitor_Control
11 const char* Memory_Usage_Monitor::default_name_ =
12 "OS/Memory/TotalUsage";
14 Memory_Usage_Monitor::Memory_Usage_Monitor (const char* name)
15 : Monitor_Base (name, Monitor_Control_Types::MC_NUMBER)
16 #if defined (ACE_HAS_WIN32_PDH)
17 , Windows_Monitor (ACE_TEXT ("\\Memory\\% Committed Bytes In Use"))
18 #endif
22 void
23 Memory_Usage_Monitor::update ()
25 #if defined (ACE_HAS_WIN32_PDH)
26 this->update_i ();
27 this->receive (this->value_);
28 #elif defined (ACE_HAS_LINUX_SYSINFO)
29 if (::sysinfo (&this->sysinfo_) != 0)
31 ACELIB_ERROR ((LM_ERROR,
32 ACE_TEXT ("Memory usage - sysinfo() failed\n")));
33 return;
36 double used_ram = this->sysinfo_.totalram - this->sysinfo_.freeram;
37 double percent_mem_usage = used_ram / this->sysinfo_.totalram * 100.0;
39 this->receive (percent_mem_usage);
40 #endif
43 const char*
44 Memory_Usage_Monitor::default_name ()
46 return Memory_Usage_Monitor::default_name_;
49 void
50 Memory_Usage_Monitor::clear_i ()
52 #if defined (ACE_HAS_WIN32_PDH)
53 this->clear_impl ();
54 #endif
56 this->Monitor_Base::clear_i ();
61 ACE_END_VERSIONED_NAMESPACE_DECL
63 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */