Use config found in SortLogs instead of random log files
This both gives us a single Configuration object to use for all
matching configuration, and also gives us an abstraction to use when we
move the config out of the top of each log file and into a separate
file.
While we are here, expose name from the log file header as well. This
removes the last user of the raw LogFileHeader from logger.
Change-Id: I0c99d64f9a7222e17100650cdf4b018ae224887a
diff --git a/aos/events/logging/logger.cc b/aos/events/logging/logger.cc
index 24c0427..d750caf 100644
--- a/aos/events/logging/logger.cc
+++ b/aos/events/logging/logger.cc
@@ -40,18 +40,6 @@
namespace aos {
namespace logger {
namespace {
-// Helper to safely read a header, or CHECK.
-SizePrefixedFlatbufferVector<LogFileHeader> MaybeReadHeaderOrDie(
- const std::vector<LogFile> &log_files) {
- CHECK_GE(log_files.size(), 1u) << ": Empty filenames list";
- CHECK_GE(log_files[0].parts.size(), 1u) << ": Empty filenames list";
- CHECK_GE(log_files[0].parts[0].parts.size(), 1u) << ": Empty filenames list";
- std::optional<SizePrefixedFlatbufferVector<LogFileHeader>> result =
- ReadHeader(log_files[0].parts[0].parts[0]);
- CHECK(result);
- return result.value();
-}
-
std::string LogFileVectorToString(std::vector<LogFile> log_files) {
std::stringstream ss;
for (const auto f : log_files) {
@@ -929,8 +917,20 @@
LogReader::LogReader(std::vector<LogFile> log_files,
const Configuration *replay_configuration)
: log_files_(std::move(log_files)),
- log_file_header_(MaybeReadHeaderOrDie(log_files_)),
replay_configuration_(replay_configuration) {
+ CHECK_GT(log_files_.size(), 0u);
+ {
+ // Validate that we have the same config everwhere. This will be true if
+ // all the parts were sorted together and the configs match.
+ const Configuration *config = nullptr;
+ for (const LogFile &log_file : log_files) {
+ if (config == nullptr) {
+ config = log_file.config.get();
+ } else {
+ CHECK_EQ(config, log_file.config.get());
+ }
+ }
+ }
MakeRemappedConfig();
// Remap all existing remote timestamp channels. They will be recreated, and
@@ -1000,11 +1000,10 @@
if (remapped_configuration_buffer_) {
remapped_configuration_buffer_->Wipe();
}
- log_file_header_.Wipe();
}
const Configuration *LogReader::logged_configuration() const {
- return log_file_header_.message().configuration();
+ return log_files_[0].config.get();
}
const Configuration *LogReader::configuration() const {