1 #ifndef Ndmspc_NResourceMonitor_H
2 #define Ndmspc_NResourceMonitor_H
3 #include <sys/resource.h>
36 virtual void Print(Option_t * option =
"")
const;
50 void Fill(Int_t * coords,
int threadId);
98 std::chrono::high_resolution_clock::time_point
fWallStart;
99 std::chrono::high_resolution_clock::time_point
fWallEnd;
100 std::vector<std::string>
fNames = {
"time",
"cpu",
"mem"};
109 return static_cast<double>(tv.tv_sec) +
static_cast<double>(tv.tv_usec) / 1000000.0;
Monitors and records resource usage (CPU, memory, wall time) for processes or threads.
rusage & GetUsageStart()
Returns the starting resource usage structure.
void Start()
Records the starting resource usage and wall time.
THnSparse * fHnSparse
THnSparse histogram for resource data.
virtual void Print(Option_t *option="") const
Prints the resource monitor information.
double GetTimeDiffInSeconds() const
Returns the time difference in seconds since the last measurement or reset.
std::chrono::high_resolution_clock::time_point fWallStart
Wall clock start time.
void End()
Records the ending resource usage and wall time.
virtual ~NResourceMonitor()
Destructor.
double timevalToDouble(const timeval &tv) const
Helper function to convert timeval to double seconds.
std::vector< std::string > fNames
Axis names.
rusage & GetUsageEnd()
Returns the ending resource usage structure.
void Fill(Int_t *coords, int threadId)
Fills resource usage data into the histogram.
double GetCpuUsage() const
Calculates and returns the CPU usage between Start and End.
THnSparse * GetHnSparse() const
Returns the pointer to the THnSparse histogram.
THnSparse * Initialize(THnSparse *hns)
Initializes the THnSparse histogram for resource data.
NResourceMonitor()
Default constructor.
rusage fUsageStart
Resource usage at start.
rusage fUsageEnd
Resource usage at end.
std::chrono::high_resolution_clock::time_point fWallEnd
Wall clock end time.
long GetMemoryUsageDiff() const
Returns the difference in memory usage (in kilobytes) between Start and End.