Class ResourceMonitor
Defined in File resource_monitor.h
Class Documentation
-
class ResourceMonitor
Monitors system resource usage, including CPU time, wall time, and RAM usage.
The
ResourceMonitor
class tracks CPU and wall clock time over timed episodes, much like wavemap’s Stopwatch class. It also provides functionality to retrieve the total RAM usage of the current process.Public Functions
-
void start()
Starts a new CPU and wall time monitoring episode.
Records the CPU and wall clock start times for the current episode. If monitoring is already running, calling
start()
has no effect.
-
void stop()
Stops timing the current episode.
Records the end CPU and wall clock times for the current episode, updating the last episode duration and total accumulated duration. If no episode is in progress, calling
stop()
has no effect.
-
inline bool isRunning() const
Checks if the stopwatch is currently running.
- Returns:
true
if the stopwatch is running,false
otherwise.
-
inline double getLastEpisodeCpuTime() const
Gets the CPU time duration of the last episode.
The value represents the CPU time elapsed during the most recently completed pair of
start()
andstop()
calls. If no episode has been completed, this returns 0.- Returns:
The CPU time duration of the last episode in seconds.
-
inline double getLastEpisodeWallTime() const
Gets the wall clock time duration of the last episode.
The value represents the real-world time elapsed during the most recently completed pair of
start()
andstop()
calls. If no episode has been completed, this returns 0.- Returns:
The wall clock time duration of the last episode in seconds.
-
std::string getLastEpisodeResourceUsageStats() const
Get the last episode’s resource usage stats formatted as a string.
The returned string provides a human-readable summary of the resource usage for the most recently completed episode. CPU and wall times are displayed in seconds with two decimal places, while RAM usage is reported in kilobytes. If RAM usage information is unavailable, it will be labeled as “Unknown”. Each statistic is printed on a new line, with a leading
*
.- Returns:
A string with the CPU time, wall time, and RAM usage statistics.
-
inline double getTotalCpuTime() const
Gets the total accumulated CPU time of all episodes.
The value represents the sum of the CPU times of all episodes that have been timed since the creation of the resource monitor or since it was last reset.
- Returns:
The total CPU time in seconds.
-
inline double getTotalWallTime() const
Gets the total accumulated wall clock time of all episodes.
The value represents the sum of the wall times of all episodes that have been timed since the creation of the resource monitor or since it was last reset.
- Returns:
The total wall time in seconds.
-
std::string getTotalResourceUsageStats() const
Get the total accumulated resource usage stats formatted as a string.
The returned string provides a human-readable summary of the total resource usage for all episodes. CPU and wall times are displayed in seconds with two decimal places, while RAM usage is reported in kilobytes. If RAM usage information is unavailable, it will be labeled as “Unknown”. Each statistic is printed on a new line, with a leading
*
.- Returns:
A string with the CPU time, wall time, and RAM usage statistics.
-
void start()