Add nodes to all the rest of the prints in NoncausalTimestampFilter

This makes it a lot easier to understand which filter is the problem
when something explodes, or when otherwise debugging.

Change-Id: Iba292a6b77eb37ba7293ca309e904a2f8efe6678
diff --git a/aos/network/timestamp_filter.cc b/aos/network/timestamp_filter.cc
index 5e4d115..5605246 100644
--- a/aos/network/timestamp_filter.cc
+++ b/aos/network/timestamp_filter.cc
@@ -1058,7 +1058,9 @@
 
   // The first sample is easy.  Just do it!
   if (timestamps_.size() == 0) {
-    VLOG(1) << "Initial sample of " << TimeString(monotonic_now, sample_ns);
+    VLOG(1) << node_a_->name()->string_view() << " -> "
+            << node_b_->name()->string_view() << " Initial sample of "
+            << TimeString(monotonic_now, sample_ns);
     timestamps_.emplace_back(std::make_tuple(monotonic_now, sample_ns, false));
     CHECK(!fully_frozen_) << ": " << node_a_->name()->string_view() << " -> "
                           << node_b_->name()->string_view()
@@ -1082,8 +1084,9 @@
   aos::monotonic_clock::duration doffset = sample_ns - std::get<1>(back);
 
   if (dt == chrono::nanoseconds(0) && doffset == chrono::nanoseconds(0)) {
-    VLOG(1) << "Duplicate sample of O(" << monotonic_now
-            << ") = " << sample_ns.count() << ", remote time "
+    VLOG(1) << node_a_->name()->string_view() << " -> "
+            << node_b_->name()->string_view() << " Duplicate sample of O("
+            << monotonic_now << ") = " << sample_ns.count() << ", remote time "
             << monotonic_now + sample_ns;
 
     return;
@@ -1096,7 +1099,9 @@
     // negative slope, the point violates our constraint and will never be worth
     // considering.  Ignore it.
     if (doffset < -dt * kMaxVelocity()) {
-      VLOG(1) << std::setprecision(1) << std::fixed << "Rejected sample of "
+      VLOG(1) << std::setprecision(1) << std::fixed
+              << node_a_->name()->string_view() << " -> "
+              << node_b_->name()->string_view() << " Rejected sample of "
               << TimeString(monotonic_now, sample_ns) << " because "
               << doffset.count() << " < " << (-dt * kMaxVelocity()).count()
               << " len " << timestamps_.size();
@@ -1106,13 +1111,14 @@
     // Be overly conservative here.  It either won't make a difference, or
     // will give us an error with an actual useful time difference.
     CHECK(!fully_frozen_)
-        << ": Returned a horizontal line previously and then got a new "
+        << ": " << node_a_->name()->string_view() << " -> "
+        << node_b_->name()->string_view()
+        << " Returned a horizontal line previously and then got a new "
            "sample at "
         << monotonic_now << ", "
         << chrono::duration<double>(monotonic_now - std::get<0>(timestamps_[0]))
                .count()
-        << " seconds after the last sample at " << std::get<0>(timestamps_[0])
-        << " " << csv_file_name_ << ".";
+        << " seconds after the last sample at " << std::get<0>(timestamps_[0]);
 
     // Back propagate the max velocity and remove any elements violating the
     // velocity constraint.  This is to handle the case where the offsets were
@@ -1126,8 +1132,12 @@
     // In this case, point 3 is now violating our constraint and we need to
     // remove it.  This is the non-causal part of the filter.
     while (dt * kMaxVelocity() < doffset && timestamps_.size() > 1u) {
-      CHECK(!std::get<2>(back)) << ": Can't pop an already frozen sample.";
-      VLOG(1) << "Removing now invalid sample during back propegation of "
+      CHECK(!std::get<2>(back)) << ": " << node_a_->name()->string_view()
+                                << " -> " << node_b_->name()->string_view()
+                                << " Can't pop an already frozen sample.";
+      VLOG(1) << node_a_->name()->string_view() << " -> "
+              << node_b_->name()->string_view()
+              << " Removing now invalid sample during back propegation of "
               << TimeString(back);
       timestamps_.pop_back();
 
@@ -1153,8 +1163,9 @@
   CHECK(it != timestamps_.end());
 
   CHECK(!std::get<2>(*(it)))
-      << ": Tried to insert " << monotonic_now << " before " << std::get<0>(*it)
-      << ", which is a frozen time.";
+      << ": " << node_a_->name()->string_view() << " -> "
+      << node_b_->name()->string_view() << " Tried to insert " << monotonic_now
+      << " before " << std::get<0>(*it) << ", which is a frozen time.";
 
   if (it == timestamps_.begin()) {
     // We are being asked to add at the beginning.
@@ -1164,7 +1175,8 @@
       const chrono::nanoseconds doffset = original_offset - sample_ns;
 
       if (dt == chrono::nanoseconds(0) && doffset >= chrono::nanoseconds(0)) {
-        VLOG(1) << "Redundant timestamp "
+        VLOG(1) << node_a_->name()->string_view() << " -> "
+                << node_b_->name()->string_view() << " Redundant timestamp "
                 << TimeString(monotonic_now, sample_ns) << " because "
                 << TimeString(timestamps_.front())
                 << " is at the same time and a better solution.";
@@ -1172,7 +1184,8 @@
       }
     }
 
-    VLOG(1) << "Added sample at beginning "
+    VLOG(1) << node_a_->name()->string_view() << " -> "
+            << node_b_->name()->string_view() << " Added sample at beginning "
             << TimeString(monotonic_now, sample_ns);
     timestamps_.insert(it, std::make_tuple(monotonic_now, sample_ns, false));
 
@@ -1185,7 +1198,9 @@
         const chrono::nanoseconds doffset = std::get<1>(*second) - sample_ns;
 
         if (doffset < -dt * kMaxVelocity()) {
-          VLOG(1) << "Removing redundant sample of " << TimeString(*second)
+          VLOG(1) << node_a_->name()->string_view() << " -> "
+                  << node_b_->name()->string_view()
+                  << " Removing redundant sample of " << TimeString(*second)
                   << " because " << TimeString(timestamps_.front())
                   << " would make the slope too negative.";
           timestamps_.erase(second);
@@ -1211,7 +1226,9 @@
               std::get<1>(*third) - std::get<1>(*second);
 
           if (doffset > dt * kMaxVelocity()) {
-            VLOG(1) << "Removing invalid sample of " << TimeString(*second)
+            VLOG(1) << node_a_->name()->string_view() << " -> "
+                    << node_b_->name()->string_view()
+                    << " Removing invalid sample of " << TimeString(*second)
                     << " because " << TimeString(*third)
                     << " would make the slope too positive.";
             timestamps_.erase(second);
@@ -1224,8 +1241,10 @@
     }
     return;
   } else {
-    VLOG(1) << "Found the next time " << std::get<0>(*(it - 1)) << " < "
-            << monotonic_now << " < " << std::get<0>(*it);
+    VLOG(1) << node_a_->name()->string_view() << " -> "
+            << node_b_->name()->string_view() << " Found the next time "
+            << std::get<0>(*(it - 1)) << " < " << monotonic_now << " < "
+            << std::get<0>(*it);
 
     {
       chrono::nanoseconds prior_dt = monotonic_now - std::get<0>(*(it - 1));
@@ -1235,14 +1254,18 @@
 
       // If we are worse than either the previous or next point, discard.
       if (prior_doffset < -prior_dt * kMaxVelocity()) {
-        VLOG(1) << "Ignoring timestamp " << TimeString(monotonic_now, sample_ns)
-                << " because " << TimeString(*(it - 1))
+        VLOG(1) << node_a_->name()->string_view() << " -> "
+                << node_b_->name()->string_view() << " Ignoring timestamp "
+                << TimeString(monotonic_now, sample_ns) << " because "
+                << TimeString(*(it - 1))
                 << " is before and the slope would be too negative.";
         return;
       }
       if (next_doffset > next_dt * kMaxVelocity()) {
-        VLOG(1) << "Ignoring timestamp " << TimeString(monotonic_now, sample_ns)
-                << " because " << TimeString(*it)
+        VLOG(1) << node_a_->name()->string_view() << " -> "
+                << node_b_->name()->string_view() << " Ignoring timestamp "
+                << TimeString(monotonic_now, sample_ns) << " because "
+                << TimeString(*it)
                 << " is following and the slope would be too positive.";
         return;
       }
@@ -1253,7 +1276,9 @@
     // new.
     auto middle_it = timestamps_.insert(
         it, std::make_tuple(monotonic_now, sample_ns, false));
-    VLOG(1) << "Inserted " << TimeString(*middle_it);
+    VLOG(1) << node_a_->name()->string_view() << " -> "
+            << node_b_->name()->string_view() << " Inserted "
+            << TimeString(*middle_it);
 
     while (middle_it != timestamps_.end() && middle_it != timestamps_.begin()) {
       auto next_it =
@@ -1269,7 +1294,9 @@
             std::get<1>(*next_it) - std::get<1>(*middle_it);
 
         if (next_doffset < -next_dt * kMaxVelocity()) {
-          VLOG(1) << "Next slope is too negative, removing next point "
+          VLOG(1) << node_a_->name()->string_view() << " -> "
+                  << node_b_->name()->string_view()
+                  << " Next slope is too negative, removing next point "
                   << TimeString(*next_it);
           next_it = timestamps_.erase(next_it);
           // erase invalidates all iterators, and this code uses middle as the
@@ -1288,7 +1315,9 @@
 
         if (prior_doffset > prior_dt * kMaxVelocity()) {
           CHECK(!std::get<2>(*prior_it))
-              << ": Can't pop an already frozen sample.";
+              << ": " << node_a_->name()->string_view() << " -> "
+              << node_b_->name()->string_view()
+              << " Can't pop an already frozen sample.";
           VLOG(1) << "Prior slope is too positive, removing prior point "
                   << TimeString(*prior_it);
           prior_it = timestamps_.erase(prior_it);
@@ -1387,10 +1416,9 @@
 }
 
 void NoncausalTimestampFilter::SetCsvFileName(std::string_view name) {
-  csv_file_name_ = name;
-  fp_ = fopen(absl::StrCat(csv_file_name_, ".csv").c_str(), "w");
+  fp_ = fopen(absl::StrCat(name, ".csv").c_str(), "w");
   samples_fp_ =
-      fopen(absl::StrCat(csv_file_name_, "_samples.csv").c_str(), "w");
+      fopen(absl::StrCat(name, "_samples.csv").c_str(), "w");
   PrintNoncausalTimestampFilterHeader(fp_);
   PrintNoncausalTimestampFilterSamplesHeader(samples_fp_);
 }
diff --git a/aos/network/timestamp_filter.h b/aos/network/timestamp_filter.h
index 5d577a7..7a9b7fa 100644
--- a/aos/network/timestamp_filter.h
+++ b/aos/network/timestamp_filter.h
@@ -447,7 +447,6 @@
       std::tuple<aos::monotonic_clock::time_point, std::chrono::nanoseconds>>
       saved_samples_;
 
-  std::string csv_file_name_;
   FILE *fp_ = nullptr;
   FILE *samples_fp_ = nullptr;