|
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. | |
| std::string | availMemStr () const |
| Returns the available memory of the system as a string. | |
| std::string | checkAvailableMemory (std::size_t const requestedMemoryBytes) const |
| Check if there is enough space in memory to hold the requested amount of memory. | |
| std::size_t | getCurrentRSS () const |
| double | getFreeRatio () const |
| The ratio of available to total system memory as a number between 0-100. | |
| std::size_t | getPeakRSS () const |
| void | ignoreFields (const MemoryStatsIgnore) |
| Set the fields to ignore. | |
| MemoryStats (const MemoryStatsIgnore ignore=MEMORY_STATS_IGNORE_NONE) | |
| Constructor. | |
| std::size_t | reservedMem () const |
| Returns the reserved memory that has not been factored into the available memory calculation. | |
| std::size_t | residentMem () const |
| Returns the memory usage of the current process in kiB. | |
| std::string | resUsageStr () const |
| Returns the resident memory used by the current process. | |
| std::size_t | totalMem () const |
| Returns the total memory of the system. | |
| std::string | totalMemStr () const |
| Returns the total memory of the system as a string. | |
| void | update () |
| Update the structure with current information, taking into account what is to be ignored. | |
| std::size_t | virtualMem () const |
| Returns the virtual memory usage of the current process in kiB. | |
| std::string | vmUsageStr () const |
| Returns the virtual memory usage as a string. | |
Static Public Member Functions | |
| static bool | memoryCheckEnabled () |
| Whether checkAvailableMemory compares a request against the available memory at all. | |
Private Member Functions | |
| void | process_mem_system (size_t &sys_avail, size_t &sys_total) |
| Attempts to read the system memory statistics. | |
Private Attributes | |
| std::size_t | avail_memory |
| Available memory of system in kiB. | |
| MemoryStatsIgnore | ignore |
| What fields to ignore. | |
| std::size_t | res_usage |
| Resident memory usage by process in kiB. | |
| std::size_t | total_memory |
| Total physical memory of system in kiB. | |
| std::size_t | vm_usage |
| Virtual memory usage by process in kiB. | |
Static Private Attributes | |
| static std::mutex | mutexMemory |
| Mutex to avoid simultaneous access to memory resources. | |
Friends | |
| MANTID_KERNEL_DLL std::ostream & | operator<< (std::ostream &out, const MemoryStats &stats) |
| Convenience function for writting out to stream. | |
| Mantid::Kernel::MemoryStats::MemoryStats | ( | const MemoryStatsIgnore | ignore = MEMORY_STATS_IGNORE_NONE | ) |
Constructor.
| ignore | :: Which memory stats should be ignored. |
Definition at line 334 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 404 of file Memory.cpp.
References avail_memory.
Referenced by checkAvailableMemory(), Mantid::MDAlgorithms::LoadSQW::exec(), export_MemoryStats(), Mantid::DataObjects::MDEventWorkspace< MDE, nd >::setMinRecursionDepth(), and Mantid::MDAlgorithms::LoadSQW2::warnIfMemoryInsufficient().
| string Mantid::Kernel::MemoryStats::availMemStr | ( | ) | const |
Returns the available memory of the system as a string.
Definition at line 390 of file Memory.cpp.
References avail_memory, and Mantid::Kernel::memToString().
| std::string Mantid::Kernel::MemoryStats::checkAvailableMemory | ( | std::size_t const | requestedMemoryBytes | ) | const |
Check if there is enough space in memory to hold the requested amount of memory.
| requestedMemoryBytes | :: The amount of memory that is being requested, in bytes. |
Definition at line 573 of file Memory.cpp.
References availMem(), memoryCheckEnabled(), and std::to_string().
Referenced by Mantid::Kernel::RebinParamsValidator::checkValidity(), Mantid::MDAlgorithms::SlicingAlgorithm::createAlignedTransform(), Mantid::MDAlgorithms::SlicingAlgorithm::processGeneralTransformProperties(), and Mantid::Algorithms::Rebin::validateInputs().
| 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 534 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 465 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 490 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 366 of file Memory.cpp.
References ignore.
Referenced by MemoryStats().
|
static |
Whether checkAvailableMemory compares a request against the available memory at all.
This is controlled by the "algorithms.memorycheck" property, which is on unless it is set otherwise. Turning it off lets a calculation run on a machine whose reported available memory does not reflect what it can really provide, which is the case on machines that are given memory on demand and on our own build servers.
Definition at line 595 of file Memory.cpp.
Referenced by checkAvailableMemory().
|
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 187 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 431 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 410 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 378 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 397 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 384 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 349 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(), and MemoryStats().
| size_t Mantid::Kernel::MemoryStats::virtualMem | ( | ) | const |
Returns the virtual memory usage of the current process in kiB.
Definition at line 418 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 372 of file Memory.cpp.
References Mantid::Kernel::memToString(), and vm_usage.
|
friend |
Convenience function for writting out to stream.
Definition at line 470 of file Memory.cpp.
|
private |
Available memory of system in kiB.
Definition at line 54 of file Memory.h.
Referenced by availMem(), availMemStr(), getFreeRatio(), and update().
|
private |
What fields to ignore.
Definition at line 50 of file Memory.h.
Referenced by ignoreFields(), and update().
|
staticprivate |
|
private |
Resident memory usage by process in kiB.
Definition at line 52 of file Memory.h.
Referenced by residentMem(), resUsageStr(), and update().
|
private |
Total physical memory of system in kiB.
Definition at line 53 of file Memory.h.
Referenced by getFreeRatio(), totalMem(), totalMemStr(), and update().
|
private |
Virtual memory usage by process in kiB.
Definition at line 51 of file Memory.h.
Referenced by update(), virtualMem(), and vmUsageStr().