Add plotting script for looking at time estimation

Change-Id: Ifedf7d21c892be93c39daab76dec523a6814dd45
diff --git a/aos/events/logging/logger.cc b/aos/events/logging/logger.cc
index 9da790a..d4f4abd 100644
--- a/aos/events/logging/logger.cc
+++ b/aos/events/logging/logger.cc
@@ -1243,6 +1243,15 @@
 
   if (FLAGS_timestamps_to_csv) {
     filters_->Start(event_loop_factory);
+    std::fstream s("/tmp/timestamp_noncausal_starttime.csv", s.trunc | s.out);
+    CHECK(s.is_open());
+    for (std::unique_ptr<State> &state : states_) {
+      s << state->event_loop()->node()->name()->string_view() << ", "
+        << std::setprecision(12) << std::fixed
+        << chrono::duration<double>(state->monotonic_now().time_since_epoch())
+               .count()
+        << "\n";
+    }
   }
 }
 
diff --git a/aos/events/logging/timestamp_plot.gnuplot b/aos/events/logging/timestamp_plot.gnuplot
new file mode 100755
index 0000000..566448a
--- /dev/null
+++ b/aos/events/logging/timestamp_plot.gnuplot
@@ -0,0 +1,33 @@
+#!/usr/bin/gnuplot -c
+
+set format y "%.6f";
+set mouse mouseformat "%.6f, %.9f"
+
+node1 = ARG1
+node2 = ARG2
+
+print "Node1: ", node1
+print "Node2: ", node2
+
+node1_start_time = system("grep " . node1 . " /tmp/timestamp_noncausal_starttime.csv | awk '{print $2}'") + 0
+node1_index = int(system("grep -n " . node1 . " /tmp/timestamp_noncausal_starttime.csv | sed 's/:.*//'")) + 1
+node2_start_time = system("grep " . node2 . " /tmp/timestamp_noncausal_starttime.csv | awk '{print $2}'") + 0
+node2_index = int(system("grep -n " . node2 . " /tmp/timestamp_noncausal_starttime.csv | sed 's/:.*//'")) + 1
+
+noncausalfile12 = sprintf("/tmp/timestamp_noncausal_%s_%s.csv", node1, node2)
+noncausalfile21 = sprintf("/tmp/timestamp_noncausal_%s_%s.csv", node2, node1)
+
+samplefile12 = sprintf("/tmp/timestamp_noncausal_%s_%s_samples.csv", node1, node2)
+samplefile21 = sprintf("/tmp/timestamp_noncausal_%s_%s_samples.csv", node2, node1)
+
+offsetfile = "/tmp/timestamp_noncausal_offsets.csv"
+
+#set term qt 0
+
+plot samplefile12 using 1:2 title 'sample 1-2', \
+     samplefile21 using 1:(-$2) title 'sample 2-1', \
+     noncausalfile12 using 1:3 title 'nc 1-2' with lines, \
+     noncausalfile21 using 1:(-$3) title 'nc 2-1' with lines, \
+     offsetfile using ((column(node1_index) - node1_start_time + (column(node2_index) - node2_start_time)) / 2):(column(node2_index) - column(node1_index)) title 'filter 2-1' with lines
+
+pause -1