split parameters for logging and tuning
add a flag to enable/disable tuning: default off
add an option for specifying a folder for outputting logs.
Closes: #10
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I43864768f1dee8672f13288d3cf5a0c87c373aed
diff --git a/README.md b/README.md
index 17465b2..2b5e0b9 100644
--- a/README.md
+++ b/README.md
@@ -252,10 +252,14 @@
The main thread will manage the other threads, and process the initial
configuration files. It will also register a dbus handler for the OEM message.
-### Enabling Logging
+### Enabling Logging & Tuning
-By default, swampd won't log tuning information. To enable this pass "-t" on
-the command line with a pareter of the path to write the log file.
+By default, swampd won't log information. To enable logging pass "-l" on the
+command line with a parameter that is the folder into which to write the logs.
+
+The log files will be named {folderpath}/zone_{zoneid}.log
+
+To enable tuning, pass "-t" on the command line.
## Project Information
diff --git a/main.cpp b/main.cpp
index 477be66..3726f50 100644
--- a/main.cpp
+++ b/main.cpp
@@ -62,21 +62,23 @@
{
int rc = 0;
std::string configPath = "";
- tuningLoggingPath = "";
+ loggingPath = "";
+ loggingEnabled = false;
+ tuningEnabled = false;
CLI::App app{"OpenBMC Fan Control Daemon"};
app.add_option("-c,--conf", configPath,
"Optional parameter to specify configuration at run-time")
->check(CLI::ExistingFile);
- app.add_option("-t,--tuning", tuningLoggingPath,
- "Optional parameter to specify tuning logging path, and "
- "enable tuning");
+ app.add_option("-l,--log", loggingPath,
+ "Optional parameter to specify logging path");
+ app.add_flag("-t,--tuning", tuningEnabled, "Enable or disable tuning");
+
+ loggingEnabled = (!loggingPath.empty());
CLI11_PARSE(app, argc, argv);
- tuningLoggingEnabled = (tuningLoggingPath.length() > 0);
-
auto modeControlBus = sdbusplus::bus::new_system();
static constexpr auto modeRoot = "/xyz/openbmc_project/settings/fanctrl";
// Create a manager for the ModeBus because we own it.
diff --git a/pid/fancontroller.cpp b/pid/fancontroller.cpp
index 4c1b56b..1f23e0b 100644
--- a/pid/fancontroller.cpp
+++ b/pid/fancontroller.cpp
@@ -115,8 +115,8 @@
{
double percent = value;
- /* If doing tuning logging, don't go into failsafe mode. */
- if (!tuningLoggingEnabled)
+ /* If doing tuning, don't go into failsafe mode. */
+ if (!tuningEnabled)
{
if (_owner->getFailSafeMode())
{
diff --git a/pid/pidloop.cpp b/pid/pidloop.cpp
index b684747..f613c7e 100644
--- a/pid/pidloop.cpp
+++ b/pid/pidloop.cpp
@@ -45,7 +45,7 @@
{
if (first)
{
- if (tuningLoggingEnabled)
+ if (loggingEnabled)
{
zone->initializeLog();
}
@@ -104,7 +104,7 @@
// Run the fan PIDs every iteration.
zone->processFans();
- if (tuningLoggingEnabled)
+ if (loggingEnabled)
{
zone->getLogHandle() << "," << zone->getFailSafeMode();
zone->getLogHandle() << std::endl;
diff --git a/pid/tuning.cpp b/pid/tuning.cpp
index c3f21ed..3422e34 100644
--- a/pid/tuning.cpp
+++ b/pid/tuning.cpp
@@ -16,5 +16,7 @@
#include <string>
-bool tuningLoggingEnabled = false;
-std::string tuningLoggingPath;
+bool tuningEnabled = false;
+
+std::string loggingPath;
+bool loggingEnabled = false;
diff --git a/pid/tuning.hpp b/pid/tuning.hpp
index 511c797..ba4ec32 100644
--- a/pid/tuning.hpp
+++ b/pid/tuning.hpp
@@ -2,8 +2,12 @@
#include <string>
-/** Boolean variable controlling whether tuning logging output is enabled
+/** Boolean variable controlling whether tuning is enabled
* during this run.
*/
-extern bool tuningLoggingEnabled;
-extern std::string tuningLoggingPath;
+extern bool tuningEnabled;
+/** String variable with the folder for writing logs if logging is enabled.
+ */
+extern std::string loggingPath;
+/** Boolean variable whether loggingPath is non-empty. */
+extern bool loggingEnabled;
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 928aef5..eef4fde 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -139,7 +139,7 @@
*/
max = std::max(getMinThermalRPMSetpoint(), max);
- if (tuningLoggingEnabled)
+ if (tuningEnabled)
{
/*
* We received no setpoints from thermal sensors.
@@ -217,7 +217,7 @@
* is disabled? I think it's a waste to try and log things even if the
* data is just being dropped though.
*/
- if (tuningLoggingEnabled)
+ if (loggingEnabled)
{
tstamp now = std::chrono::high_resolution_clock::now();
_log << std::chrono::duration_cast<std::chrono::milliseconds>(
@@ -237,13 +237,13 @@
* However, these are the fans, so if I'm not getting updated values
* for them... what should I do?
*/
- if (tuningLoggingEnabled)
+ if (loggingEnabled)
{
_log << "," << r.value;
}
}
- if (tuningLoggingEnabled)
+ if (loggingEnabled)
{
for (const auto& t : _thermalInputs)
{
diff --git a/pid/zone.hpp b/pid/zone.hpp
index 78ebf0f..fcadac0 100644
--- a/pid/zone.hpp
+++ b/pid/zone.hpp
@@ -52,9 +52,9 @@
_minThermalOutputSetPt(minThermalOutput),
_failSafePercent(failSafePercent), _mgr(mgr)
{
- if (tuningLoggingEnabled && !tuningLoggingPath.empty())
+ if (loggingEnabled)
{
- _log.open(tuningLoggingPath + std::to_string(zone));
+ _log.open(loggingPath + std::to_string(zone));
}
}