-
Notifications
You must be signed in to change notification settings - Fork 0
Presenter Class Documentation
The Presenter class is designed to provide a visual and textual presentation of CPU and memory usage within an OpenCV application. It allows the monitoring and graphical display of different types of system metrics, including average CPU load, CPU load distribution across cores, and memory usage. This class is particularly useful for applications that require real-time monitoring of system resources, such as performance analysis tools or benchmarking applications.
- Multiple Monitor Support: Enables monitoring of CPU average load, CPU distribution load, and memory usage.
- Graphical Representation: Displays real-time graphs of the monitored metrics directly on a video frame.
- Customizable Parameters: Allows customization of the graph size, position, and history size for data collection.
- Dynamic Control: Supports dynamic addition and removal of monitors through keyboard interaction.
-
explicit Presenter(std::set<MonitorType> enabledMonitors = {}, int yPos = 20, cv::Size graphSize = {150, 60}, std::size_t historySize = 20)-
Parameters:
-
enabledMonitors: A set ofMonitorTypeenums specifying which monitors should be enabled initially. -
yPos: The Y-position of the graphs on the video frame. -
graphSize: The size of the graphs (width and height). -
historySize: The number of historical data points to keep for each monitor.
-
-
Description: Initializes the
Presenterobject with the specified monitors enabled and sets the graphical and data collection parameters.
-
-
explicit Presenter(const std::string& keys, int yPos = 20, cv::Size graphSize = {150, 60}, std::size_t historySize = 20)-
Parameters:
-
keys: A string of characters representing monitor types to be enabled. Each character corresponds to aMonitorType. -
yPos: The Y-position of the graphs on the video frame. -
graphSize: The size of the graphs (width and height). -
historySize: The number of historical data points to keep for each monitor.
-
-
Description: Initializes the
Presenterobject with monitors based on the provided string of keys, converting each key to the correspondingMonitorType.
-
-
void addRemoveMonitor(MonitorType monitor)-
Parameters:
-
monitor: TheMonitorTypeenum specifying the monitor to add or remove.
-
-
Description: Toggles the activation of the specified monitor. If the monitor is already active, it is disabled, and vice versa. Adjusts the history size of the CPU and memory monitors based on the current set of enabled monitors.
-
-
void handleKey(int key)-
Parameters:
-
key: The integer key code representing the pressed key.
-
-
Description: Handles key presses for toggling monitors. Supports the following keys:
-
'C': Toggle CPU average load monitor. -
'D': Toggle CPU load distribution monitor. -
'M': Toggle memory usage monitor. -
'H': Toggle all monitors on or off.
-
-
-
void drawGraphs(cv::Mat& frame)-
Parameters:
-
frame: The OpenCV matrix (image) on which the graphs will be drawn.
-
-
Description: Draws the graphs for the enabled monitors on the provided video frame. The graphs are drawn in the specified area, and each monitor's data is visually represented.
-
-
std::vector<std::string> reportMeans() const-
Returns: A vector of strings where each string contains a summary of the average usage for the monitored resources.
-
Description: Collects and returns the mean values of the monitored metrics (CPU load, CPU distribution, and memory usage) as human-readable strings. This method is useful for logging or displaying summary information.
-
-
std::chrono::steady_clock::time_point prevTimeStamp: Stores the timestamp of the last data collection. -
std::size_t historySize: The number of data points to keep for historical data. -
CpuMonitor cpuMonitor: The monitor object responsible for collecting and managing CPU usage data. -
bool distributionCpuEnabled: A flag indicating whether the CPU distribution monitor is enabled. -
MemoryMonitor memoryMonitor: The monitor object responsible for collecting and managing memory usage data. -
std::ostringstream strStream: A stream object used for formatting output strings.
#include "presenter.h"
// Create a Presenter object with CPU and Memory monitoring enabled
Presenter presenter({MonitorType::CpuAverage, MonitorType::Memory});
// Add or remove the CPU distribution monitor based on user interaction
presenter.addRemoveMonitor(MonitorType::DistributionCpu);
// Handle keypress to toggle monitors
presenter.handleKey('C'); // Toggles CPU average monitor
// Draw the graphs on a video frame
cv::Mat frame = ...; // Your video frame
presenter.drawGraphs(frame);
// Get a report of the mean values
std::vector<std::string> means = presenter.reportMeans();
for (const auto& line : means) {
std::cout << line << std::endl;
}