control: Dump flight recorder to a JSON file
A future commit will dump more debug data as opposed to just the flight
recorder. To better support the data all being in the same file, it
will be a JSON file. The first step of that is to write the flight
recorder output to a JSON file.
This also reorganizes the Manager code that does it to prepare for
different data also being in the same file.
An example is:
{
"flight_recorder": [
"Oct 06 05:59:01.183998: main: Startup"
]
}
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Iaeb55ffde3a30c2345968e1b3fad313b50aff331
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 92ef0d0..10bb84d 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -58,6 +58,8 @@
Manager::_objects;
std::unordered_map<std::string, PropertyVariantType> Manager::_parameters;
+const std::string Manager::dumpFile = "/tmp/fan_control_dump.json";
+
Manager::Manager(const sdeventplus::Event& event) :
_bus(util::SDBusPlus::getBus()), _event(event),
_mgr(util::SDBusPlus::getBus(), CONTROL_OBJPATH), _loadAllowed(true),
@@ -95,15 +97,26 @@
void Manager::sigUsr1Handler(sdeventplus::source::Signal&,
const struct signalfd_siginfo*)
{
- _flightRecEventSource = std::make_unique<sdeventplus::source::Defer>(
- _event, std::bind(std::mem_fn(&Manager::dumpFlightRecorder), this,
+ debugDumpEventSource = std::make_unique<sdeventplus::source::Defer>(
+ _event, std::bind(std::mem_fn(&Manager::dumpDebugData), this,
std::placeholders::_1));
}
-void Manager::dumpFlightRecorder(sdeventplus::source::EventBase& /*source*/)
+void Manager::dumpDebugData(sdeventplus::source::EventBase& /*source*/)
{
- FlightRecorder::instance().dump();
- _flightRecEventSource.reset();
+ json data;
+ FlightRecorder::instance().dump(data);
+
+ std::ofstream file{Manager::dumpFile};
+ if (!file)
+ {
+ log<level::ERR>("Could not open file for fan dump");
+ return;
+ }
+
+ file << std::setw(4) << data;
+
+ debugDumpEventSource.reset();
}
void Manager::load()