Mantid
|
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... | |
Mantid::Kernel::MemoryStats::MemoryStats | ( | const MemoryStatsIgnore | ignore = MEMORY_STATS_IGNORE_NONE | ) |
Constructor.
ignore | :: Which memory stats should be ignored. |
Definition at line 328 of file Memory.cpp.
References ignoreFields(), and update().
size_t Mantid::Kernel::MemoryStats::availMem | ( | ) | const |
Returns the available memory of 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().
string Mantid::Kernel::MemoryStats::availMemStr | ( | ) | const |
Returns the available memory of the system as a string.
Definition at line 384 of file Memory.cpp.
References avail_memory, and Mantid::Kernel::memToString().
size_t Mantid::Kernel::MemoryStats::getCurrentRSS | ( | ) | const |
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().
double Mantid::Kernel::MemoryStats::getFreeRatio | ( | ) | const |
The ratio of available to total system memory as a number between 0-100.
Definition at line 459 of file Memory.cpp.
References avail_memory, and total_memory.
Referenced by export_MemoryStats().
size_t Mantid::Kernel::MemoryStats::getPeakRSS | ( | ) | const |
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().
void Mantid::Kernel::MemoryStats::ignoreFields | ( | const MemoryStatsIgnore | ignore | ) |
Set the fields to ignore.
ignore | :: An enumeration giving the fields to ignore |
Definition at line 360 of file Memory.cpp.
References ignore.
Referenced by MemoryStats().
|
private |
Attempts to read the system memory statistics.
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().
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
Definition at line 425 of file Memory.cpp.
Referenced by export_MemoryStats().
size_t Mantid::Kernel::MemoryStats::residentMem | ( | ) | const |
Returns the memory usage of the current process in kiB.
Definition at line 404 of file Memory.cpp.
References res_usage.
Referenced by export_MemoryStats().
string Mantid::Kernel::MemoryStats::resUsageStr | ( | ) | const |
Returns the resident memory used by the current process.
Definition at line 372 of file Memory.cpp.
References Mantid::Kernel::memToString(), and res_usage.
size_t Mantid::Kernel::MemoryStats::totalMem | ( | ) | const |
Returns the total memory of the system.
Definition at line 391 of file Memory.cpp.
References total_memory.
Referenced by export_MemoryStats().
string Mantid::Kernel::MemoryStats::totalMemStr | ( | ) | const |
Returns the total memory of the system as a string.
Definition at line 378 of file Memory.cpp.
References Mantid::Kernel::memToString(), and total_memory.
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().
size_t Mantid::Kernel::MemoryStats::virtualMem | ( | ) | const |
Returns the virtual memory usage of the current process in kiB.
Definition at line 412 of file Memory.cpp.
References vm_usage.
Referenced by export_MemoryStats().
string Mantid::Kernel::MemoryStats::vmUsageStr | ( | ) | const |
Returns the virtual memory usage as a string.
Definition at line 366 of file Memory.cpp.
References Mantid::Kernel::memToString(), and vm_usage.
|
friend |
Convenience function for writting out to stream.
Definition at line 464 of file Memory.cpp.
|
private |
Available memory of system in kiB.
Definition at line 52 of file Memory.h.
Referenced by availMem(), availMemStr(), getFreeRatio(), and update().
|
private |
What fields to ignore.
Definition at line 48 of file Memory.h.
Referenced by ignoreFields(), and update().
|
staticprivate |
|
private |
Resident memory usage by process in kiB.
Definition at line 50 of file Memory.h.
Referenced by residentMem(), resUsageStr(), and update().
|
private |
Total physical memory of system in kiB.
Definition at line 51 of file Memory.h.
Referenced by getFreeRatio(), totalMem(), totalMemStr(), and update().
|
private |
Virtual memory usage by process in kiB.
Definition at line 49 of file Memory.h.
Referenced by update(), virtualMem(), and vmUsageStr().