ndmspc  v1.2.0-0.1.rc3
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. More...
 
THnSparse * Initialize (THnSparse *hns)
 Initializes the THnSparse histogram for resource data. More...
 
void Fill (Int_t *coords, int threadId)
 Fills resource usage data into the histogram. More...
 
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. More...
 
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. More...
 

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.

Member Function Documentation

◆ 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().

Referenced by Ndmspc::NGnThreadData::Process().

◆ 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().

◆ 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().

Referenced by Ndmspc::NGnThreadData::Process().

◆ 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().

◆ 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().


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