ndmspc v1.2.0-0.1.rc5
Loading...
Searching...
No Matches
Ndmspc::NResourceMonitor Class Reference

Monitors and records resource usage (CPU, memory, wall time) for processes or threads. More...

#include <NResourceMonitor.h>

Inheritance diagram for Ndmspc::NResourceMonitor:

Public Member Functions

 NResourceMonitor ()
 Default constructor.
 
virtual ~NResourceMonitor ()
 Destructor.
 
virtual void Print (Option_t *option="") const
 Prints the resource monitor information.
 
THnSparse * Initialize (THnSparse *hns)
 Initializes the THnSparse histogram for resource data.
 
void Fill (Int_t *coords, int threadId)
 Fills resource usage data into the histogram.
 
THnSparse * GetHnSparse () const
 Returns the pointer to the THnSparse histogram.
 
rusage & GetUsageStart ()
 Returns the starting resource usage structure.
 
rusage & GetUsageEnd ()
 Returns the ending resource usage structure.
 
double GetTimeDiffInSeconds () const
 Returns the time difference in seconds since the last measurement or reset.
 
double GetCpuUsage () const
 Calculates and returns the CPU usage between Start and End.
 
long GetMemoryUsageDiff () const
 Returns the difference in memory usage (in kilobytes) between Start and End.
 
void Start ()
 Records the starting resource usage and wall time.
 
void End ()
 Records the ending resource usage and wall time.
 

Private Member Functions

double timevalToDouble (const timeval &tv) const
 Helper function to convert timeval to double seconds.
 

Private Attributes

THnSparse * fHnSparse {nullptr}
 THnSparse histogram for resource data.
 
rusage fUsageStart
 Resource usage at start.
 
rusage fUsageEnd
 Resource usage at end.
 
std::chrono::high_resolution_clock::time_point fWallStart
 Wall clock start time.
 
std::chrono::high_resolution_clock::time_point fWallEnd
 Wall clock end time.
 
std::vector< std::string > fNames = {"time", "cpu", "mem"}
 Axis names.
 

Detailed Description

Monitors and records resource usage (CPU, memory, wall time) for processes or threads.

Provides methods to start and stop resource monitoring, fill resource usage data into a THnSparse histogram, and retrieve CPU and memory usage statistics. Uses system resource tracking and wall clock timing to measure performance.

Author
Martin Vala mvala.nosp@m.@cer.nosp@m.n.ch

Definition at line 20 of file NResourceMonitor.h.

Constructor & Destructor Documentation

◆ NResourceMonitor()

Ndmspc::NResourceMonitor::NResourceMonitor ( )

Default constructor.

Definition at line 12 of file NResourceMonitor.cxx.

◆ ~NResourceMonitor()

Ndmspc::NResourceMonitor::~NResourceMonitor ( )
virtual

Destructor.

Definition at line 13 of file NResourceMonitor.cxx.

Member Function Documentation

◆ End()

void Ndmspc::NResourceMonitor::End ( )

Records the ending resource usage and wall time.

Definition at line 115 of file NResourceMonitor.cxx.

References fUsageEnd, and fWallEnd.

◆ Fill()

void Ndmspc::NResourceMonitor::Fill ( Int_t * coords,
int threadId )

Fills resource usage data into the histogram.

Parameters
coordsArray of coordinates for histogram axes.
threadIdIdentifier for the thread.

Fill resource monitor with THnSparse object and coordinates

Definition at line 74 of file NResourceMonitor.cxx.

References fHnSparse, GetCpuUsage(), GetMemoryUsageDiff(), and GetTimeDiffInSeconds().

◆ GetCpuUsage()

double Ndmspc::NResourceMonitor::GetCpuUsage ( ) const

Calculates and returns the CPU usage between Start and End.

Definition at line 129 of file NResourceMonitor.cxx.

References fUsageEnd, fUsageStart, fWallEnd, fWallStart, and timevalToDouble().

Referenced by Fill(), and Print().

◆ GetHnSparse()

THnSparse * Ndmspc::NResourceMonitor::GetHnSparse ( ) const
inline

Returns the pointer to the THnSparse histogram.

Definition at line 55 of file NResourceMonitor.h.

References fHnSparse.

◆ GetMemoryUsageDiff()

long Ndmspc::NResourceMonitor::GetMemoryUsageDiff ( ) const
inline

Returns the difference in memory usage (in kilobytes) between Start and End.

Definition at line 82 of file NResourceMonitor.h.

References fUsageEnd, and fUsageStart.

Referenced by Fill().

◆ GetTimeDiffInSeconds()

double Ndmspc::NResourceMonitor::GetTimeDiffInSeconds ( ) const

Returns the time difference in seconds since the last measurement or reset.

Returns
The elapsed time in seconds as a double.

Definition at line 123 of file NResourceMonitor.cxx.

References fWallEnd, and fWallStart.

Referenced by Fill().

◆ GetUsageEnd()

rusage & Ndmspc::NResourceMonitor::GetUsageEnd ( )
inline

Returns the ending resource usage structure.

Definition at line 65 of file NResourceMonitor.h.

References fUsageEnd.

◆ GetUsageStart()

rusage & Ndmspc::NResourceMonitor::GetUsageStart ( )
inline

Returns the starting resource usage structure.

Definition at line 60 of file NResourceMonitor.h.

References fUsageStart.

◆ Initialize()

THnSparse * Ndmspc::NResourceMonitor::Initialize ( THnSparse * hns)

Initializes the THnSparse histogram for resource data.

Parameters
hnsPointer to THnSparse to initialize.
Returns
Pointer to initialized THnSparse.

Initialize resource monitor with THnSparse object

Definition at line 42 of file NResourceMonitor.cxx.

References Ndmspc::NUtils::CreateAxisFromLabels(), fHnSparse, fNames, and Ndmspc::NUtils::ReshapeSparseAxes().

◆ Print()

void Ndmspc::NResourceMonitor::Print ( Option_t * option = "") const
virtual

Prints the resource monitor information.

Parameters
optionOptional print options.

Print resource usage

Definition at line 14 of file NResourceMonitor.cxx.

References fUsageEnd, fUsageStart, fWallEnd, fWallStart, GetCpuUsage(), and timevalToDouble().

◆ Start()

void Ndmspc::NResourceMonitor::Start ( )

Records the starting resource usage and wall time.

Definition at line 106 of file NResourceMonitor.cxx.

References fUsageStart, and fWallStart.

◆ timevalToDouble()

double Ndmspc::NResourceMonitor::timevalToDouble ( const timeval & tv) const
inlineprivate

Helper function to convert timeval to double seconds.

Parameters
tvtimeval structure.
Returns
Time in seconds as double.

Definition at line 107 of file NResourceMonitor.h.

Referenced by GetCpuUsage(), and Print().

Member Data Documentation

◆ fHnSparse

THnSparse* Ndmspc::NResourceMonitor::fHnSparse {nullptr}
private

THnSparse histogram for resource data.

Definition at line 95 of file NResourceMonitor.h.

Referenced by Fill(), GetHnSparse(), and Initialize().

◆ fNames

std::vector<std::string> Ndmspc::NResourceMonitor::fNames = {"time", "cpu", "mem"}
private

Axis names.

Definition at line 100 of file NResourceMonitor.h.

Referenced by Initialize().

◆ fUsageEnd

rusage Ndmspc::NResourceMonitor::fUsageEnd
private

Resource usage at end.

Definition at line 97 of file NResourceMonitor.h.

Referenced by End(), GetCpuUsage(), GetMemoryUsageDiff(), GetUsageEnd(), and Print().

◆ fUsageStart

rusage Ndmspc::NResourceMonitor::fUsageStart
private

Resource usage at start.

Definition at line 96 of file NResourceMonitor.h.

Referenced by GetCpuUsage(), GetMemoryUsageDiff(), GetUsageStart(), Print(), and Start().

◆ fWallEnd

std::chrono::high_resolution_clock::time_point Ndmspc::NResourceMonitor::fWallEnd
private

Wall clock end time.

Definition at line 99 of file NResourceMonitor.h.

Referenced by End(), GetCpuUsage(), GetTimeDiffInSeconds(), and Print().

◆ fWallStart

std::chrono::high_resolution_clock::time_point Ndmspc::NResourceMonitor::fWallStart
private

Wall clock start time.

Definition at line 98 of file NResourceMonitor.h.

Referenced by GetCpuUsage(), GetTimeDiffInSeconds(), Print(), and Start().


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