|
ndmspc v1.2.0-0.1.rc7
|
Monitors and records resource usage (CPU, memory, wall time) for processes or threads. More...
#include <NResourceMonitor.h>
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. | |
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.
Definition at line 20 of file NResourceMonitor.h.
| Ndmspc::NResourceMonitor::NResourceMonitor | ( | ) |
Default constructor.
Definition at line 12 of file NResourceMonitor.cxx.
|
virtual |
Destructor.
Definition at line 13 of file NResourceMonitor.cxx.
| void Ndmspc::NResourceMonitor::End | ( | ) |
Records the ending resource usage and wall time.
Definition at line 115 of file NResourceMonitor.cxx.
| void Ndmspc::NResourceMonitor::Fill | ( | Int_t * | coords, |
| int | threadId ) |
Fills resource usage data into the histogram.
| coords | Array of coordinates for histogram axes. |
| threadId | Identifier 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().
| 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().
|
inline |
Returns the pointer to the THnSparse histogram.
Definition at line 55 of file NResourceMonitor.h.
References fHnSparse.
|
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().
| double Ndmspc::NResourceMonitor::GetTimeDiffInSeconds | ( | ) | const |
Returns the time difference in seconds since the last measurement or reset.
Definition at line 123 of file NResourceMonitor.cxx.
References fWallEnd, and fWallStart.
Referenced by Fill().
|
inline |
Returns the ending resource usage structure.
Definition at line 65 of file NResourceMonitor.h.
References fUsageEnd.
|
inline |
Returns the starting resource usage structure.
Definition at line 60 of file NResourceMonitor.h.
References fUsageStart.
| THnSparse * Ndmspc::NResourceMonitor::Initialize | ( | THnSparse * | hns | ) |
Initializes the THnSparse histogram for resource data.
| hns | Pointer to THnSparse to initialize. |
Initialize resource monitor with THnSparse object
Definition at line 42 of file NResourceMonitor.cxx.
References Ndmspc::NUtils::CreateAxisFromLabels(), fHnSparse, fNames, and Ndmspc::NUtils::ReshapeSparseAxes().
|
virtual |
Prints the resource monitor information.
| option | Optional print options. |
Print resource usage
Definition at line 14 of file NResourceMonitor.cxx.
References fUsageEnd, fUsageStart, fWallEnd, fWallStart, GetCpuUsage(), and timevalToDouble().
| void Ndmspc::NResourceMonitor::Start | ( | ) |
Records the starting resource usage and wall time.
Definition at line 106 of file NResourceMonitor.cxx.
References fUsageStart, and fWallStart.
|
inlineprivate |
Helper function to convert timeval to double seconds.
| tv | timeval structure. |
Definition at line 107 of file NResourceMonitor.h.
Referenced by GetCpuUsage(), and Print().
|
private |
THnSparse histogram for resource data.
Definition at line 95 of file NResourceMonitor.h.
Referenced by Fill(), GetHnSparse(), and Initialize().
|
private |
|
private |
Resource usage at end.
Definition at line 97 of file NResourceMonitor.h.
Referenced by End(), GetCpuUsage(), GetMemoryUsageDiff(), GetUsageEnd(), and Print().
|
private |
Resource usage at start.
Definition at line 96 of file NResourceMonitor.h.
Referenced by GetCpuUsage(), GetMemoryUsageDiff(), GetUsageStart(), Print(), and Start().
|
private |
Wall clock end time.
Definition at line 99 of file NResourceMonitor.h.
Referenced by End(), GetCpuUsage(), GetTimeDiffInSeconds(), and Print().
|
private |
Wall clock start time.
Definition at line 98 of file NResourceMonitor.h.
Referenced by GetCpuUsage(), GetTimeDiffInSeconds(), Print(), and Start().