control: Flight recorder wrapper for actions
Add a convenience function 'record()' to the action base class that
handles creating a unique ID for each action instance to pass in to the
flight recorder. This is done so different instances of actions show up
in their own buckets in the flight recorder.
It just increments a count when each action is created and appends that
count to the action name when creating the unique name, like
"set_net_increase_target-5".
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I8989a02b12b85f1587eea53ec50ba217e1576900
diff --git a/control/json/actions/action.hpp b/control/json/actions/action.hpp
index 58d79b2..f0b1850 100644
--- a/control/json/actions/action.hpp
+++ b/control/json/actions/action.hpp
@@ -15,6 +15,7 @@
*/
#pragma once
+#include "../utils/flight_recorder.hpp"
#include "../zone.hpp"
#include "config_base.hpp"
#include "group.hpp"
@@ -119,7 +120,8 @@
* always include the action where no profiles are given.
*/
ActionBase(const json& jsonObj, const std::vector<Group>& groups) :
- ConfigBase(jsonObj), _groups(groups)
+ ConfigBase(jsonObj), _groups(groups),
+ _uniqueName(getName() + "-" + std::to_string(_actionCount++))
{}
/**
@@ -185,13 +187,41 @@
[this](Zone& zone) { this->run(zone); });
}
+ /**
+ * @brief Returns a unique name for the action.
+ *
+ * @return std::string - The name
+ */
+ const std::string& getUniqueName() const
+ {
+ return _uniqueName;
+ }
+
protected:
+ /**
+ * @brief Logs a message to the flight recorder using
+ * the unique name of the action.
+ *
+ * @param[in] message - The message to log
+ */
+ void record(const std::string& message) const
+ {
+ FlightRecorder::instance().log(getUniqueName(), message);
+ }
+
/* Groups configured on the action */
const std::vector<Group> _groups;
private:
/* Zones configured on the action */
std::vector<std::reference_wrapper<Zone>> _zones;
+
+ /* Unique name of the action.
+ * It's just the name plus _actionCount at the time of action creation. */
+ const std::string _uniqueName;
+
+ /* Running count of all actions */
+ static inline size_t _actionCount = 0;
};
/**