Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
Mantid::Kernel::MemoryStats Class Reference

This class is responsible for memory statistics. More...

#include <Memory.h>

Public Member Functions

std::size_t availMem () const
 Returns the available memory of the system in kiB. More...
 
std::string availMemStr () const
 Returns the available memory of the system as a string. More...
 
std::size_t getCurrentRSS () const
 
double getFreeRatio () const
 The ratio of available to total system memory as a number between 0-100. More...
 
std::size_t getPeakRSS () const
 
void ignoreFields (const MemoryStatsIgnore)
 Set the fields to ignore. More...
 
 MemoryStats (const MemoryStatsIgnore ignore=MEMORY_STATS_IGNORE_NONE)
 Constructor. More...
 
std::size_t reservedMem () const
 Returns the reserved memory that has not been factored into the available memory calculation. More...
 
std::size_t residentMem () const
 Returns the memory usage of the current process in kiB. More...
 
std::string resUsageStr () const
 Returns the resident memory used by the current process. More...
 
std::size_t totalMem () const
 Returns the total memory of the system. More...
 
std::string totalMemStr () const
 Returns the total memory of the system as a string. More...
 
void update ()
 Update the structure with current information, taking into account what is to be ignored. More...
 
std::size_t virtualMem () const
 Returns the virtual memory usage of the current process in kiB. More...
 
std::string vmUsageStr () const
 Returns the virtual memory usage as a string. More...
 

Private Member Functions

void process_mem_system (size_t &sys_avail, size_t &sys_total)
 Attempts to read the system memory statistics. More...
 

Private Attributes

std::size_t avail_memory
 Available memory of system in kiB. More...
 
MemoryStatsIgnore ignore
 What fields to ignore. More...
 
std::size_t res_usage
 Resident memory usage by process in kiB. More...
 
std::size_t total_memory
 Total physical memory of system in kiB. More...
 
std::size_t vm_usage
 Virtual memory usage by process in kiB. More...
 

Static Private Attributes

static std::mutex mutexMemory
 Mutex to avoid simultaneous access to memory resources. More...
 

Friends

MANTID_KERNEL_DLL std::ostream & operator<< (std::ostream &out, const MemoryStats &stats)
 Convenience function for writting out to stream. More...
 

Detailed Description

This class is responsible for memory statistics.

Definition at line 28 of file Memory.h.

Constructor & Destructor Documentation

◆ MemoryStats()

Mantid::Kernel::MemoryStats::MemoryStats ( const MemoryStatsIgnore  ignore = MEMORY_STATS_IGNORE_NONE)

Constructor.

Parameters
ignore:: Which memory stats should be ignored.

Definition at line 328 of file Memory.cpp.

References ignoreFields(), and update().

Member Function Documentation

◆ availMem()

size_t Mantid::Kernel::MemoryStats::availMem ( ) const

Returns the available memory of the system in kiB.

Returns
An unsigned containing the available amount of memory on the system in kiB

Definition at line 398 of file Memory.cpp.

References avail_memory.

Referenced by Mantid::MDAlgorithms::LoadSQW::exec(), export_MemoryStats(), Mantid::MDAlgorithms::LoadSQW2::warnIfMemoryInsufficient(), and Mantid::DataHandling::SaveToSNSHistogramNexus::WriteDataGroup().

◆ availMemStr()

string Mantid::Kernel::MemoryStats::availMemStr ( ) const

Returns the available memory of the system as a string.

Returns
A string containing the amount of available memory on the system

Definition at line 384 of file Memory.cpp.

References avail_memory, and Mantid::Kernel::memToString().

◆ getCurrentRSS()

size_t Mantid::Kernel::MemoryStats::getCurrentRSS ( ) const
Returns
the current resident set size (physical memory use) measured in bytes, or zero if the value cannot be determined on this OS.

This was adopted from http://nadeausoftware.com/articles/2012/07/c_c_tip_how_get_process_resident_set_size_physical_memory_use

Definition at line 528 of file Memory.cpp.

Referenced by export_MemoryStats().

◆ getFreeRatio()

double Mantid::Kernel::MemoryStats::getFreeRatio ( ) const

The ratio of available to total system memory as a number between 0-100.

Returns
A percentage

Definition at line 459 of file Memory.cpp.

References avail_memory, and total_memory.

Referenced by export_MemoryStats().

◆ getPeakRSS()

size_t Mantid::Kernel::MemoryStats::getPeakRSS ( ) const
Returns
the peak (maximum so far) resident set size (physical memory use) measured in bytes, or zero if the value cannot be determined on this OS.

This was adopted from http://nadeausoftware.com/articles/2012/07/c_c_tip_how_get_process_resident_set_size_physical_memory_use

Definition at line 484 of file Memory.cpp.

Referenced by export_MemoryStats().

◆ ignoreFields()

void Mantid::Kernel::MemoryStats::ignoreFields ( const MemoryStatsIgnore  ignore)

Set the fields to ignore.

Parameters
ignore:: An enumeration giving the fields to ignore

Definition at line 360 of file Memory.cpp.

References ignore.

Referenced by MemoryStats().

◆ process_mem_system()

void Mantid::Kernel::MemoryStats::process_mem_system ( size_t &  sys_avail,
size_t &  sys_total 
)
private

Attempts to read the system memory statistics.

Parameters
sys_avail:: An output variable containing the reported available system memory in this variable in KiB
sys_total:: An output variable containing the reported total system memory in the system in KiB

Definition at line 186 of file Memory.cpp.

References count, Mantid::Kernel::Logger::debug(), Mantid::Kernel::DateAndTimeHelpers::g_log, and Mantid::Kernel::Logger::warning().

Referenced by update().

◆ reservedMem()

size_t Mantid::Kernel::MemoryStats::reservedMem ( ) const

Returns the reserved memory that has not been factored into the available memory calculation.

NOTE: On Windows this can be a lengthy calculation as it involves adding up the reserved space DWORD length at a time. Call only when necessary On other systems this will return 0 as it has already been factored in to the available memory calculation

Returns
An extra area of memory that can still be allocated.

Definition at line 425 of file Memory.cpp.

Referenced by export_MemoryStats().

◆ residentMem()

size_t Mantid::Kernel::MemoryStats::residentMem ( ) const

Returns the memory usage of the current process in kiB.

Returns
An unsigned containing the memory used by the current process in kiB

Definition at line 404 of file Memory.cpp.

References res_usage.

Referenced by export_MemoryStats().

◆ resUsageStr()

string Mantid::Kernel::MemoryStats::resUsageStr ( ) const

Returns the resident memory used by the current process.

Returns
A string containing the amount of memory the process is using

Definition at line 372 of file Memory.cpp.

References Mantid::Kernel::memToString(), and res_usage.

◆ totalMem()

size_t Mantid::Kernel::MemoryStats::totalMem ( ) const

Returns the total memory of the system.

Returns
An unsigned containing the total amount of memory on the system in kiB

Definition at line 391 of file Memory.cpp.

References total_memory.

Referenced by export_MemoryStats().

◆ totalMemStr()

string Mantid::Kernel::MemoryStats::totalMemStr ( ) const

Returns the total memory of the system as a string.

Returns
A string containing the total amount of memory on the system

Definition at line 378 of file Memory.cpp.

References Mantid::Kernel::memToString(), and total_memory.

◆ update()

void Mantid::Kernel::MemoryStats::update ( )

Update the structure with current information, taking into account what is to be ignored.

This call is thread-safe (protected by a mutex). Note: This takes about 0.1 ms on a Ubuntu 10.10 system.

Definition at line 343 of file Memory.cpp.

References avail_memory, ignore, Mantid::Kernel::MEMORY_STATS_IGNORE_PROCESS, Mantid::Kernel::MEMORY_STATS_IGNORE_SYSTEM, mutexMemory, process_mem_system(), Mantid::Kernel::process_mem_usage(), res_usage, total_memory, and vm_usage.

Referenced by export_MemoryStats(), MemoryStats(), and Mantid::DataHandling::SaveToSNSHistogramNexus::WriteDataGroup().

◆ virtualMem()

size_t Mantid::Kernel::MemoryStats::virtualMem ( ) const

Returns the virtual memory usage of the current process in kiB.

Returns
An unsigned containing the virtual memory used by the current process in kiB

Definition at line 412 of file Memory.cpp.

References vm_usage.

Referenced by export_MemoryStats().

◆ vmUsageStr()

string Mantid::Kernel::MemoryStats::vmUsageStr ( ) const

Returns the virtual memory usage as a string.

Returns
A string containing the amount of virtual memory usage

Definition at line 366 of file Memory.cpp.

References Mantid::Kernel::memToString(), and vm_usage.

Friends And Related Function Documentation

◆ operator<<

MANTID_KERNEL_DLL std::ostream & operator<< ( std::ostream &  out,
const MemoryStats stats 
)
friend

Convenience function for writting out to stream.

Definition at line 464 of file Memory.cpp.

Member Data Documentation

◆ avail_memory

std::size_t Mantid::Kernel::MemoryStats::avail_memory
private

Available memory of system in kiB.

Definition at line 52 of file Memory.h.

Referenced by availMem(), availMemStr(), getFreeRatio(), and update().

◆ ignore

MemoryStatsIgnore Mantid::Kernel::MemoryStats::ignore
private

What fields to ignore.

Definition at line 48 of file Memory.h.

Referenced by ignoreFields(), and update().

◆ mutexMemory

std::mutex Mantid::Kernel::MemoryStats::mutexMemory
staticprivate

Mutex to avoid simultaneous access to memory resources.

Definition at line 55 of file Memory.h.

Referenced by update().

◆ res_usage

std::size_t Mantid::Kernel::MemoryStats::res_usage
private

Resident memory usage by process in kiB.

Definition at line 50 of file Memory.h.

Referenced by residentMem(), resUsageStr(), and update().

◆ total_memory

std::size_t Mantid::Kernel::MemoryStats::total_memory
private

Total physical memory of system in kiB.

Definition at line 51 of file Memory.h.

Referenced by getFreeRatio(), totalMem(), totalMemStr(), and update().

◆ vm_usage

std::size_t Mantid::Kernel::MemoryStats::vm_usage
private

Virtual memory usage by process in kiB.

Definition at line 49 of file Memory.h.

Referenced by update(), virtualMem(), and vmUsageStr().


The documentation for this class was generated from the following files: