add tuning enable variable

Add a variable that when set, enables tuning logging.  This variable is
set to false.

Tuning can be enabled via "-t" "--tuning" on the command line.
With a parameter is the path where to write the logging information.

Change-Id: I6eb8035d56cc3301face21e9375c02fc9fcc5b31
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 7433d30..928aef5 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -23,6 +23,7 @@
 #include "pid/fancontroller.hpp"
 #include "pid/stepwisecontroller.hpp"
 #include "pid/thermalcontroller.hpp"
+#include "pid/tuning.hpp"
 
 #include <algorithm>
 #include <chrono>
@@ -138,38 +139,38 @@
      */
     max = std::max(getMinThermalRPMSetpoint(), max);
 
-#ifdef __TUNING_LOGGING__
-    /*
-     * We received no setpoints from thermal sensors.
-     * This is a case experienced during tuning where they only specify
-     * fan sensors and one large fan PID for all the fans.
-     */
-    static constexpr auto setpointpath = "/etc/thermal.d/setpoint";
-    try
+    if (tuningLoggingEnabled)
     {
-        std::ifstream ifs;
-        ifs.open(setpointpath);
-        if (ifs.good())
+        /*
+         * We received no setpoints from thermal sensors.
+         * This is a case experienced during tuning where they only specify
+         * fan sensors and one large fan PID for all the fans.
+         */
+        static constexpr auto setpointpath = "/etc/thermal.d/setpoint";
+        try
         {
-            int value;
-            ifs >> value;
+            std::ifstream ifs;
+            ifs.open(setpointpath);
+            if (ifs.good())
+            {
+                int value;
+                ifs >> value;
 
-            /* expecting RPM setpoint, not pwm% */
-            max = static_cast<double>(value);
+                /* expecting RPM setpoint, not pwm% */
+                max = static_cast<double>(value);
+            }
+        }
+        catch (const std::exception& e)
+        {
+            /* This exception is uninteresting. */
+            std::cerr << "Unable to read from '" << setpointpath << "'\n";
         }
     }
-    catch (const std::exception& e)
-    {
-        /* This exception is uninteresting. */
-        std::cerr << "Unable to read from '" << setpointpath << "'\n";
-    }
-#endif
 
     _maximumRPMSetPt = max;
     return;
 }
 
-#ifdef __TUNING_LOGGING__
 void PIDZone::initializeLog(void)
 {
     /* Print header for log file:
@@ -196,7 +197,6 @@
 {
     return _log;
 }
-#endif
 
 /*
  * TODO(venture) This is effectively updating the cache and should check if the
@@ -217,13 +217,14 @@
      * is disabled?  I think it's a waste to try and log things even if the
      * data is just being dropped though.
      */
-#ifdef __TUNING_LOGGING__
-    tstamp now = std::chrono::high_resolution_clock::now();
-    _log << std::chrono::duration_cast<std::chrono::milliseconds>(
-                now.time_since_epoch())
-                .count();
-    _log << "," << _maximumRPMSetPt;
-#endif
+    if (tuningLoggingEnabled)
+    {
+        tstamp now = std::chrono::high_resolution_clock::now();
+        _log << std::chrono::duration_cast<std::chrono::milliseconds>(
+                    now.time_since_epoch())
+                    .count();
+        _log << "," << _maximumRPMSetPt;
+    }
 
     for (const auto& f : _fanInputs)
     {
@@ -236,17 +237,19 @@
          * However, these are the fans, so if I'm not getting updated values
          * for them... what should I do?
          */
-#ifdef __TUNING_LOGGING__
-        _log << "," << r.value;
-#endif
+        if (tuningLoggingEnabled)
+        {
+            _log << "," << r.value;
+        }
     }
 
-#ifdef __TUNING_LOGGING__
-    for (const auto& t : _thermalInputs)
+    if (tuningLoggingEnabled)
     {
-        _log << "," << _cachedValuesByName[t];
+        for (const auto& t : _thermalInputs)
+        {
+            _log << "," << _cachedValuesByName[t];
+        }
     }
-#endif
 
     return;
 }