|
ndmspc
v1.2.0-0.1.rc3
|
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. 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. | |
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.
| 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().
Referenced by Ndmspc::NGnThreadData::Process().
| 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().
| 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().
Referenced by Ndmspc::NGnThreadData::Process().
|
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().
|
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().