Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
mads::process_metrics Class Reference

Read-only process resource metrics for a given PID. More...

#include <pm.hpp>

Public Types

using pid_type = pid_t
 PID type used by the platform.
 
using clock = std::chrono::steady_clock
 Steady clock type used internally.
 

Public Member Functions

 process_metrics (std::optional< pid_type > pid=std::nullopt)
 Construct metrics for a target process.
 
pid_type pid () const noexcept
 Get the PID associated with this instance.
 
void sample ()
 Take a new CPU usage sample for the target PID.
 
double cpu_percent_total_capacity () const
 CPU usage as percentage of total machine capacity.
 
double cpu_percent_per_core () const
 CPU usage scaled per logical core.
 
std::uint32_t thread_count () const
 Get instantaneous number of threads in the target process.
 
std::uint64_t ram_bytes () const
 Get resident memory usage (RSS / working set) in bytes.
 
std::uint32_t cpu_count () const
 Get number of logical CPUs detected on the system.
 

Detailed Description

Read-only process resource metrics for a given PID.

Provides the following metrics for a target process:

  • number of threads
  • resident memory (RSS / working set)
  • CPU load (relative to total machine capacity and per-core scale)
Note
For macOS, querying other PIDs may require elevated privileges (task_for_pid entitlement/root); otherwise metrics may be unavailable.

Definition at line 54 of file pm.hpp.

Member Typedef Documentation

◆ clock

using mads::process_metrics::clock = std::chrono::steady_clock

Steady clock type used internally.

Definition at line 65 of file pm.hpp.

◆ pid_type

PID type used by the platform.

Definition at line 57 of file pm.hpp.

Constructor & Destructor Documentation

◆ process_metrics()

mads::process_metrics::process_metrics ( std::optional< pid_type >  pid = std::nullopt)
inlineexplicit

Construct metrics for a target process.

Parameters
pidOptional PID; if not provided, the current process PID is used.

Definition at line 72 of file pm.hpp.

Member Function Documentation

◆ cpu_count()

std::uint32_t mads::process_metrics::cpu_count ( ) const
inline

Get number of logical CPUs detected on the system.

Returns
Logical CPU count (>= 1).

Definition at line 255 of file pm.hpp.

◆ cpu_percent_per_core()

double mads::process_metrics::cpu_percent_per_core ( ) const
inline

CPU usage scaled per logical core.

0..(100 * cpu_count), where 100 corresponds to one fully saturated logical core.

Returns
CPU percentage in range [0, 100*cpu_count()] (best-effort).
Note
Meaningful only after at least two calls to sample().

Definition at line 135 of file pm.hpp.

◆ cpu_percent_total_capacity()

double mads::process_metrics::cpu_percent_total_capacity ( ) const
inline

CPU usage as percentage of total machine capacity.

0..100, where 100 means the process is using ~all CPU capacity across all logical CPUs (i.e., saturating the machine).

Returns
CPU percentage in range [0, 100] (best-effort).
Note
Meaningful only after at least two calls to sample().

Definition at line 122 of file pm.hpp.

◆ pid()

pid_type mads::process_metrics::pid ( ) const
inlinenoexcept

Get the PID associated with this instance.

Returns
Target PID.

Definition at line 81 of file pm.hpp.

◆ ram_bytes()

std::uint64_t mads::process_metrics::ram_bytes ( ) const
inline

Get resident memory usage (RSS / working set) in bytes.

  • Windows: Working Set Size.
  • Linux: RSS derived from /proc/<pid>/statm.
  • macOS: resident_size from Mach task info.
Returns
Resident bytes; 0 if unavailable.

Definition at line 208 of file pm.hpp.

◆ sample()

void mads::process_metrics::sample ( )
inline

Take a new CPU usage sample for the target PID.

Reads process CPU time and system CPU time, and updates internal deltas.

Note
CPU percentages returned by cpu_percent_*() are meaningful only after at least two calls to sample().

Definition at line 91 of file pm.hpp.

◆ thread_count()

std::uint32_t mads::process_metrics::thread_count ( ) const
inline

Get instantaneous number of threads in the target process.

Returns
Thread count; 0 if unavailable (e.g., insufficient permissions).

Definition at line 145 of file pm.hpp.

References thread_count().

Referenced by thread_count().


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