lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
lucid::metrics Namespace Reference

Collection of metric measuring functions. More...

Enumerations

enum class  MemoryUnit { B , KB , MB , GB }
 Memory units for conversion. More...
 
enum class  TimeUnit {
  MS , S , M , H ,
  D
}
 Time units for conversion. More...
 

Functions

size_t get_current_rss ()
 Get the current Resident Set Size (RSS) in bytes.
 
size_t get_peak_rss ()
 Get the peak Resident Set Size (RSS) in bytes.
 
double bytes_to (std::size_t size_in_bytes, MemoryUnit unit)
 Convert a size in bytes to the specified memory unit.
 
MemoryUnit get_suggested_memory_unit (std::size_t size_in_bytes)
 Suggest the most appropriate memory unit for a given size in bytes.
 
double time_to (double duration_in_seconds, TimeUnit unit)
 Convert a duration in seconds to the specified time unit.
 
TimeUnit get_suggested_time_unit (double duration_in_seconds)
 Suggest the most appropriate time unit for a given duration in seconds.
 
template<MemoryUnit U>
double bytes_to (const std::size_t size_in_bytes)
 Convert a size in bytes to the specified memory unit.
 
template<TimeUnit U>
double time_to (const double duration_in_seconds)
 Convert a duration in seconds to the specified time unit.
 

Detailed Description

Collection of metric measuring functions.

Enumeration Type Documentation

◆ MemoryUnit

enum class lucid::metrics::MemoryUnit
strong

Memory units for conversion.

Enumerator

Bytes.

KB 

Kilobytes (1024 Bytes)

MB 

Megabytes (1024 Kilobytes)

GB 

Gigabytes (1024 Megabytes)

◆ TimeUnit

enum class lucid::metrics::TimeUnit
strong

Time units for conversion.

Enumerator
MS 

Milliseconds.

Seconds.

Minutes (60 Seconds)

Hours (60 Minutes)

Days (24 Hours)

Function Documentation

◆ bytes_to() [1/2]

template<MemoryUnit U>
double lucid::metrics::bytes_to ( const std::size_t size_in_bytes)

Convert a size in bytes to the specified memory unit.

Template Parameters
Umemory unit to convert to
Parameters
size_in_bytessize in bytes
Returns
size in the specified memory unit

◆ bytes_to() [2/2]

double lucid::metrics::bytes_to ( std::size_t size_in_bytes,
MemoryUnit unit )

Convert a size in bytes to the specified memory unit.

Parameters
unitmemory unit to convert to
size_in_bytessize in bytes
Returns
size in the specified memory unit

◆ get_current_rss()

std::size_t lucid::metrics::get_current_rss ( )

Get the current Resident Set Size (RSS) in bytes.

This is the portion of memory occupied by a process that is held in RAM.

Note
This is different from the virtual memory size, which includes all memory the process can access, including memory that is swapped out to disk or allocated but not used.
Returns
current RSS in bytes

◆ get_peak_rss()

std::size_t lucid::metrics::get_peak_rss ( )

Get the peak Resident Set Size (RSS) in bytes.

This is the maximum portion of memory occupied by a process that was held in RAM at any point in time.

Note
This is different from the virtual memory size, which includes all memory the process can access, including memory that is swapped out to disk or allocated but not used.
Returns
peak RSS in bytes

◆ get_suggested_memory_unit()

MemoryUnit lucid::metrics::get_suggested_memory_unit ( std::size_t size_in_bytes)

Suggest the most appropriate memory unit for a given size in bytes.

The function selects the largest memory unit such that the converted size is at least 1 and less than 1024, provided the size is in the range of known memory units.

get_suggested_memory_unit(500); // Returns MemoryUnit::B -> 500 B
get_suggested_memory_unit(2048); // Returns MemoryUnit::KB -> 2 KB
get_suggested_memory_unit(5'242'880); // Returns MemoryUnit::MB -> 5 MB
get_suggested_memory_unit(10'737'418'240); // Returns MemoryUnit::GB -> 10 GB
MemoryUnit get_suggested_memory_unit(const std::size_t size_in_bytes)
Suggest the most appropriate memory unit for a given size in bytes.
Definition metrics.cpp:119
Parameters
size_in_bytessize in bytes
Returns
suggested memory unit for the given size in bytes

◆ get_suggested_time_unit()

TimeUnit lucid::metrics::get_suggested_time_unit ( double duration_in_seconds)

Suggest the most appropriate time unit for a given duration in seconds.

The function selects the largest time unit such that the converted duration is around 1 and less than the next larger unit, provided the duration in the range of known time units.

get_suggested_time_unit(0.002); // Returns TimeUnit::MS -> 2 ms
get_suggested_time_unit(0.5); // Returns TimeUnit::S -> 0.5 s
get_suggested_time_unit(2); // Returns TimeUnit::S -> 2 s
get_suggested_time_unit(120); // Returns TimeUnit::M -> 2 min
get_suggested_time_unit(7200); // Returns TimeUnit::H -> 2 h
get_suggested_time_unit(172800); // Returns TimeUnit::D -> 2 d
TimeUnit get_suggested_time_unit(const double duration_in_seconds)
Suggest the most appropriate time unit for a given duration in seconds.
Definition metrics.cpp:143
Note
Seconds has a larger range to capture ranges over a 1/100th of a second up to a minute.
Parameters
duration_in_secondsduration in seconds
Returns
suggested time unit for the given duration in seconds

◆ time_to() [1/2]

template<TimeUnit U>
double lucid::metrics::time_to ( const double duration_in_seconds)

Convert a duration in seconds to the specified time unit.

Template Parameters
Utime unit to convert to
Parameters
duration_in_secondsduration in seconds
Returns
duration in the specified time unit

◆ time_to() [2/2]

double lucid::metrics::time_to ( double duration_in_seconds,
TimeUnit unit )

Convert a duration in seconds to the specified time unit.

Parameters
duration_in_secondsduration in seconds
unittime unit to convert to
Returns
duration in the specified time unit