Expose time to on_logged_period in the AOS logger

This lets us know what time the logger just finished writing so we can
use that info in any callbacks.

Change-Id: Ic94f6bc60a9270111d5d5e2327dbadd85e8e01f5
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/logging/log_writer.cc b/aos/events/logging/log_writer.cc
index 5ccf15b..56d0c4f 100644
--- a/aos/events/logging/log_writer.cc
+++ b/aos/events/logging/log_writer.cc
@@ -865,7 +865,7 @@
     LogUntil(std::min(last_synchronized_time_ + polling_period_, end_time));
 
     if (run_on_logged) {
-      on_logged_period_();
+      on_logged_period_(last_synchronized_time_);
     }
 
     // If we missed cycles, we could be pretty far behind.  Spin until we are
diff --git a/aos/events/logging/log_writer.h b/aos/events/logging/log_writer.h
index 3d3d7f2..6fb1bfa 100644
--- a/aos/events/logging/log_writer.h
+++ b/aos/events/logging/log_writer.h
@@ -54,11 +54,14 @@
     logger_version_ = version;
   }
 
-  // Sets the callback to run after each period of data is logged. Defaults to
-  // doing nothing.
+  // Sets the callback to run *after* each period of data is logged.  Defaults
+  // to doing nothing.  The argument to the callback is the time which we just
+  // wrote until.  This is not called when rotating or finishing logs.
   //
   // This callback may safely do things like call Rotate().
-  void set_on_logged_period(std::function<void()> on_logged_period) {
+  void set_on_logged_period(
+      std::function<void(aos::monotonic_clock::time_point t)>
+          on_logged_period) {
     on_logged_period_ = std::move(on_logged_period);
   }
 
@@ -307,7 +310,10 @@
   std::string logger_sha1_;
   std::string logger_version_;
 
-  std::function<void()> on_logged_period_ = []() {};
+  // The callback to get called on each logged period.  See
+  // set_on_logged_period() above for more details.
+  std::function<void(aos::monotonic_clock::time_point t)> on_logged_period_ =
+      [](aos::monotonic_clock::time_point) {};
 
   std::chrono::nanoseconds max_message_fetch_time_ =
       std::chrono::nanoseconds::zero();
diff --git a/aos/events/logging/logger_main.cc b/aos/events/logging/logger_main.cc
index afc166f..f99fe4c 100644
--- a/aos/events/logging/logger_main.cc
+++ b/aos/events/logging/logger_main.cc
@@ -79,12 +79,11 @@
   aos::logger::Logger logger(&event_loop);
 
   if (FLAGS_rotate_every != 0.0) {
-    logger.set_on_logged_period([&] {
-      const auto now = event_loop.monotonic_now();
-      if (now > last_rotation_time +
-                    std::chrono::duration<double>(FLAGS_rotate_every)) {
+    logger.set_on_logged_period([&](aos::monotonic_clock::time_point t) {
+      if (t > last_rotation_time +
+                  std::chrono::duration<double>(FLAGS_rotate_every)) {
         logger.Rotate();
-        last_rotation_time = now;
+        last_rotation_time = t;
       }
     });
   }
diff --git a/aos/events/logging/multinode_logger_test.cc b/aos/events/logging/multinode_logger_test.cc
index 677fc72..f010466 100644
--- a/aos/events/logging/multinode_logger_test.cc
+++ b/aos/events/logging/multinode_logger_test.cc
@@ -3016,13 +3016,14 @@
     StartLogger(&pi1_logger);
     aos::monotonic_clock::time_point last_rotation_time =
         pi1_logger.event_loop->monotonic_now();
-    pi1_logger.logger->set_on_logged_period([&] {
-      const auto now = pi1_logger.event_loop->monotonic_now();
-      if (now > last_rotation_time + std::chrono::seconds(5)) {
-        pi1_logger.logger->Rotate();
-        last_rotation_time = now;
-      }
-    });
+    pi1_logger.logger->set_on_logged_period(
+        [&](aos::monotonic_clock::time_point) {
+          const auto now = pi1_logger.event_loop->monotonic_now();
+          if (now > last_rotation_time + std::chrono::seconds(5)) {
+            pi1_logger.logger->Rotate();
+            last_rotation_time = now;
+          }
+        });
 
     event_loop_factory_.RunFor(chrono::milliseconds(10000));
   }
@@ -4216,18 +4217,19 @@
     StartLogger(&pi1_logger, logfile_base1_);
     aos::monotonic_clock::time_point last_rotation_time =
         pi1_logger.event_loop->monotonic_now();
-    pi1_logger.logger->set_on_logged_period([&] {
-      const auto now = pi1_logger.event_loop->monotonic_now();
-      if (now > last_rotation_time + std::chrono::seconds(5)) {
-        pi1_logger.AppendAllFilenames(&filenames);
-        std::unique_ptr<MultiNodeFilesLogNamer> namer =
-            pi1_logger.MakeLogNamer(logfile_base2_);
-        pi1_logger.log_namer = namer.get();
+    pi1_logger.logger->set_on_logged_period(
+        [&](aos::monotonic_clock::time_point) {
+          const auto now = pi1_logger.event_loop->monotonic_now();
+          if (now > last_rotation_time + std::chrono::seconds(5)) {
+            pi1_logger.AppendAllFilenames(&filenames);
+            std::unique_ptr<MultiNodeFilesLogNamer> namer =
+                pi1_logger.MakeLogNamer(logfile_base2_);
+            pi1_logger.log_namer = namer.get();
 
-        pi1_logger.logger->RestartLogging(std::move(namer));
-        last_rotation_time = now;
-      }
-    });
+            pi1_logger.logger->RestartLogging(std::move(namer));
+            last_rotation_time = now;
+          }
+        });
 
     event_loop_factory_.RunFor(chrono::milliseconds(7000));