EventAnalysis  1.3.0
Classes | Public Types | Static Public Member Functions | Static Public Attributes | Static Private Attributes | List of all members
EA::Memory Class Reference

A static class containing helper functions for interrogating the memory status. More...

#include <Memory.h>

Classes

struct  BadLevelsException
 Exception class for badly-defined memory levels. More...
 

Public Types

enum  Status : int { Status::NORMAL = 0, Status::WARNING = 1, Status::CRITICAL = 2, Status::EXHAUSTED = 3 }
 Aliases for memory occupation levels. More...
 
using UnitType = unsigned long int
 Conversion factors for common memory usage units. More...
 

Static Public Member Functions

static unsigned long long GetOccupation ()
 Returns the current memory occupation in bytes. More...
 
static Status GetStatus ()
 Returns a status code for the current memory occupancy. More...
 
static void SetMaxMemory (unsigned long long maxMemory)
 Set the maximum allocable memory. More...
 
static unsigned long long GetMaxMemory ()
 Get the maximum allocable memory. More...
 
static void SetLevels (const std::array< float, 3 > &levels)
 Set the memory levels. More...
 
static const std::array< float, 3 > & GetLevels ()
 Set the memory levels. More...
 

Static Public Attributes

static constexpr UnitType KB = 1024UL
 
static constexpr UnitType MB = 1024UL * 1024UL
 
static constexpr UnitType GB = 1024UL * 1024UL * 1024UL
 

Static Private Attributes

static std::array< float, 3 > _levels = {80, 90, 95}
 
static const int _pageSize = getpagesize()
 
static unsigned long long _maxMemory = 3221225472
 

Detailed Description

A static class containing helper functions for interrogating the memory status.

Member Typedef Documentation

◆ UnitType

using EA::Memory::UnitType = unsigned long int

Conversion factors for common memory usage units.

Member Enumeration Documentation

◆ Status

enum EA::Memory::Status : int
strong

Aliases for memory occupation levels.

Enumerator
NORMAL 
WARNING 
CRITICAL 
EXHAUSTED 

Member Function Documentation

◆ GetLevels()

static const std::array<float, 3>& EA::Memory::GetLevels ( )
inlinestatic

Set the memory levels.

Returns
the array of memory levels.
See also
SetLevels

◆ GetMaxMemory()

static unsigned long long EA::Memory::GetMaxMemory ( )
inlinestatic

Get the maximum allocable memory.

Returns
the maximum memory in bytes.

◆ GetOccupation()

unsigned long long EA::Memory::GetOccupation ( )
static

Returns the current memory occupation in bytes.

The returned occupation is the resident memory used by the program instance.

Returns
the current memory occupation in bytes.

◆ GetStatus()

Memory::Status EA::Memory::GetStatus ( )
static

Returns a status code for the current memory occupancy.

Returns a status code corresponding to the current memory occupancy. See SetLevels for how to set the memory occupancy levels.

Returns
The status code of the current memory occupancy.

◆ SetLevels()

void EA::Memory::SetLevels ( const std::array< float, 3 > &  levels)
static

Set the memory levels.

Sets the memory occupation levels as percentages of the maximum allocable memory. Each value will mark the limit of memory statuses, for example:

SetLevels({70, 80, 95})

will set the NORMAL level at 70% or less of allocated memory, the WARNING level between 70% and 80%, the CRITICAL level between 80% and 95% and the EXHAUSTED level above 95%.

Values must be in the (0,100) range and be in strictly increasing order, otherwise a #BadLevelsException is thrown.

Default levels are {80, 90, 95}.

Parameters
levelsThe levels corresponding to the transitions between memory statuses.
Exceptions
BadLevelsExceptionif levels are not between 0 and 100 or not in strictly increasing order.

◆ SetMaxMemory()

static void EA::Memory::SetMaxMemory ( unsigned long long  maxMemory)
inlinestatic

Set the maximum allocable memory.

Default value is 3221225472 bytes (3 GB).

Parameters
maxMemoryThe maximum memory in bytes.

Member Data Documentation

◆ _levels

std::array< float, 3 > EA::Memory::_levels = {80, 90, 95}
staticprivate

◆ _maxMemory

unsigned long long EA::Memory::_maxMemory = 3221225472
staticprivate

◆ _pageSize

const int EA::Memory::_pageSize = getpagesize()
staticprivate

◆ GB

constexpr UnitType EA::Memory::GB = 1024UL * 1024UL * 1024UL
static

◆ KB

constexpr UnitType EA::Memory::KB = 1024UL
static

◆ MB

constexpr UnitType EA::Memory::MB = 1024UL * 1024UL
static

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