add support for replaying log messages
For example, this allows reproducing logged but hard to physically
reproduce problems to control loops with more logging to help debug the
problem, and then verifying that it does something different under the
same conditions.
Change-Id: I1e55e7a7c0b3154bcaf86373a9e6c57c594310a0
diff --git a/aos/common/time.cc b/aos/common/time.cc
index 1c86811..7318afb 100644
--- a/aos/common/time.cc
+++ b/aos/common/time.cc
@@ -1,9 +1,13 @@
#include "aos/common/time.h"
#include <string.h>
+#include <inttypes.h>
+
+// We only use global_core from here, which is weak, so we don't really have a
+// dependency on it.
+#include "aos/linux_code/ipc_lib/shared_mem.h"
#include "aos/common/logging/logging.h"
-#include <inttypes.h>
#include "aos/common/mutex.h"
namespace aos {
@@ -33,7 +37,11 @@
PLOG(FATAL, "clock_gettime(%jd, %p) failed",
static_cast<uintmax_t>(clock), &temp);
}
- return Time(temp);
+
+ const timespec offset = (global_core == nullptr)
+ ? timespec{0, 0}
+ : global_core->mem_struct->time_offset;
+ return Time(temp) + Time(offset);
}
} // namespace
@@ -214,5 +222,12 @@
}
}
+void OffsetToNow(const Time &now) {
+ CHECK_NOTNULL(global_core);
+ global_core->mem_struct->time_offset.tv_nsec = 0;
+ global_core->mem_struct->time_offset.tv_sec = 0;
+ global_core->mem_struct->time_offset = (now - Time::Now()).ToTimespec();
+}
+
} // namespace time
} // namespace aos