Add TimestampsStoredSeparately to detect separately stored timestamps
This gives us a nice tool to detect when to buffer and when not to.
Change-Id: I839b50792f18d4f38df390ca57b5110b560de36d
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/logging/logfile_sorting.cc b/aos/events/logging/logfile_sorting.cc
index bab57ef..2157d98 100644
--- a/aos/events/logging/logfile_sorting.cc
+++ b/aos/events/logging/logfile_sorting.cc
@@ -2289,5 +2289,33 @@
return SelectedLogParts(node_name, boot_index, result);
}
+bool LogFilesContainer::TimestampsStoredSeparately() const {
+ for (const LogFile &log_file : log_files_) {
+ for (const LogParts &part : log_file.parts) {
+ bool has_data = false;
+ bool has_timestamps = false;
+ bool has_remote_timestamps = false;
+ for (StoredDataType type : part.data_stored) {
+ switch (type) {
+ case StoredDataType::DATA:
+ has_data = true;
+ break;
+ case StoredDataType::TIMESTAMPS:
+ has_timestamps = true;
+ break;
+ case StoredDataType::REMOTE_TIMESTAMPS:
+ has_remote_timestamps = true;
+ break;
+ }
+ }
+
+ if (has_data && (has_timestamps || has_remote_timestamps)) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
} // namespace logger
} // namespace aos
diff --git a/aos/events/logging/logfile_sorting.h b/aos/events/logging/logfile_sorting.h
index 2a2615e..840c3d6 100644
--- a/aos/events/logging/logfile_sorting.h
+++ b/aos/events/logging/logfile_sorting.h
@@ -279,6 +279,10 @@
// Review its usage.
std::string_view name() const { return log_files_[0].name; }
+ // Returns true if the timestamps (remote and local) are stored only in files
+ // distinct from the data.
+ bool TimestampsStoredSeparately() const;
+
private:
LogFilesContainer(std::optional<const LogSource *> log_source,
std::vector<LogFile> log_files);
diff --git a/aos/events/logging/multinode_logger_test_lib.cc b/aos/events/logging/multinode_logger_test_lib.cc
index a4485d4..f62ddf5 100644
--- a/aos/events/logging/multinode_logger_test_lib.cc
+++ b/aos/events/logging/multinode_logger_test_lib.cc
@@ -499,6 +499,20 @@
}
}
+std::vector<std::pair<std::vector<realtime_clock::time_point>,
+ std::vector<realtime_clock::time_point>>>
+MultinodeLoggerTest::ConfirmReadable(const std::vector<std::string> &files,
+ realtime_clock::time_point start_time,
+ realtime_clock::time_point end_time) {
+ LogFilesContainer c(SortParts(files));
+ if (file_strategy() == FileStrategy::kCombine) {
+ EXPECT_FALSE(c.TimestampsStoredSeparately());
+ } else {
+ EXPECT_TRUE(c.TimestampsStoredSeparately());
+ }
+ return testing::ConfirmReadable(files, start_time, end_time);
+}
+
// Counts the number of messages on a channel. Returns (channel name, channel
// type, count) for every message matching matcher()
std::vector<std::tuple<std::string, std::string, int>> CountChannelsMatching(
diff --git a/aos/events/logging/multinode_logger_test_lib.h b/aos/events/logging/multinode_logger_test_lib.h
index ffdceb9..63d947a 100644
--- a/aos/events/logging/multinode_logger_test_lib.h
+++ b/aos/events/logging/multinode_logger_test_lib.h
@@ -156,6 +156,13 @@
void VerifyParts(const std::vector<LogFile> &sorted_parts,
const std::vector<std::string> &corrupted_parts = {});
+ std::vector<std::pair<std::vector<realtime_clock::time_point>,
+ std::vector<realtime_clock::time_point>>>
+ ConfirmReadable(
+ const std::vector<std::string> &files,
+ realtime_clock::time_point start_time = realtime_clock::min_time,
+ realtime_clock::time_point end_time = realtime_clock::max_time);
+
void AddExtension(std::string_view extension);
// Config and factory.