Add --rate_limit to aos_dump

Over slow networks, there are cases where we don't want every message
sent.  We are just trying to get a sense of what is going on.  Add a
flag to skip printing messages.

Change-Id: Ia70951b1720a647821195fb32e9f7663e6b7963b
diff --git a/aos/aos_dump.cc b/aos/aos_dump.cc
index ef61f6b..055700f 100644
--- a/aos/aos_dump.cc
+++ b/aos/aos_dump.cc
@@ -17,6 +17,9 @@
 DEFINE_bool(print_timestamps, true, "If true, timestamps are printed.");
 DEFINE_uint64(count, 0,
               "If >0, aos_dump will exit after printing this many messages.");
+DEFINE_int32(rate_limit, 0,
+             "The minimum amount of time to wait in milliseconds before "
+             "sending another message");
 
 namespace {
 
@@ -109,6 +112,8 @@
 
   aos::FastStringBuilder str_builder;
 
+  aos::monotonic_clock::time_point next_send_time =
+      aos::monotonic_clock::min_time;
   for (const aos::Channel *channel : found_channels) {
     if (FLAGS_fetch) {
       const std::unique_ptr<aos::RawFetcher> fetcher =
@@ -124,12 +129,16 @@
     }
 
     event_loop.MakeRawWatcher(
-        channel, [channel, &str_builder, &event_loop, &message_count](
-                     const aos::Context &context, const void * /*message*/) {
-          PrintMessage(channel, context, &str_builder);
-          ++message_count;
-          if (FLAGS_count > 0 && message_count >= FLAGS_count) {
-            event_loop.Exit();
+        channel,
+        [channel, &str_builder, &event_loop, &message_count, &next_send_time](
+            const aos::Context &context, const void * /*message*/) {
+          if (context.monotonic_event_time > next_send_time) {
+            PrintMessage(channel, context, &str_builder);
+            next_send_time = context.monotonic_event_time +
+                             std::chrono::milliseconds(FLAGS_rate_limit);
+            if (FLAGS_count > 0 && message_count >= FLAGS_count) {
+              event_loop.Exit();
+            }
           }
         });
   }