fixed struct log stuff
It was writing out the types every time and relying on that behavior.
diff --git a/aos/linux_code/logging/binary_log_file.cc b/aos/linux_code/logging/binary_log_file.cc
index e1e99b4..05b2d93 100644
--- a/aos/linux_code/logging/binary_log_file.cc
+++ b/aos/linux_code/logging/binary_log_file.cc
@@ -71,6 +71,9 @@
}
position_ += sizeof(LogFileMessageHeader) + r->name_size + r->message_size;
AlignPosition();
+ if (position_ >= kPageSize) {
+ LOG(FATAL, "corrupt log file running over page size\n");
+ }
return r;
}
@@ -78,15 +81,19 @@
msync(current_, kPageSize, MS_ASYNC | MS_INVALIDATE);
}
-void LogFileAccessor::MoveToEnd() {
- Unmap(current_);
+bool LogFileAccessor::IsLastPage() {
+ if (is_last_page_ != 0) {
+ return is_last_page_ == 2;
+ }
+
struct stat info;
if (fstat(fd_, &info) == -1) {
LOG(FATAL, "fstat(%d, %p) failed with %d: %s\n", fd_, &info, errno,
strerror(errno));
}
- offset_ = info.st_size - kPageSize;
- MapNextPage();
+ bool r = offset_ == info.st_size - kPageSize;
+ is_last_page_ = r ? 2 : 1;
+ return r;
}
void LogFileAccessor::MapNextPage() {
@@ -116,6 +123,7 @@
LOG(FATAL, "munmap(%p, %zd) failed with %d: %s. aborting\n", location,
kPageSize, errno, strerror(errno));
}
+ is_last_page_ = 0;
}
} // namespace linux_code
diff --git a/aos/linux_code/logging/binary_log_file.h b/aos/linux_code/logging/binary_log_file.h
index 58aa792..0f8c3fb 100644
--- a/aos/linux_code/logging/binary_log_file.h
+++ b/aos/linux_code/logging/binary_log_file.h
@@ -93,8 +93,7 @@
// Asynchronously syncs all open mappings.
void Sync() const;
- // TODO(brians): This won't work any more.
- void MoveToEnd();
+ bool IsLastPage();
private:
// The size of the chunks that get mmaped/munmapped together. Large enough so
@@ -114,6 +113,9 @@
char *current_;
size_t position_;
+ // 0 = unknown, 1 = no, 2 = yes
+ int is_last_page_ = 0;
+
void MapNextPage();
void Unmap(void *location);
diff --git a/aos/linux_code/logging/binary_log_writer.cc b/aos/linux_code/logging/binary_log_writer.cc
index aa81521..67cb166 100644
--- a/aos/linux_code/logging/binary_log_writer.cc
+++ b/aos/linux_code/logging/binary_log_writer.cc
@@ -54,6 +54,8 @@
output->type = LogFileMessageHeader::MessageType::kStructType;
futex_set(&output->marker);
+
+ written_type_ids.insert(type_id);
}
int BinaryLogReaderMain() {
diff --git a/aos/linux_code/logging/log_displayer.cc b/aos/linux_code/logging/log_displayer.cc
index 7b56f35..98021b5 100644
--- a/aos/linux_code/logging/log_displayer.cc
+++ b/aos/linux_code/logging/log_displayer.cc
@@ -50,11 +50,16 @@
int main(int argc, char **argv) {
const char *filter_name = NULL;
- size_t filter_length;
+ size_t filter_length = 0;
log_level filter_level = INFO;
- bool follow = false, start_at_beginning = true;
+ bool follow = false;
+ // Whether we need to skip everything until we get to the end of the file.
+ bool skip_to_end = false;
const char *filename = "aos_log-current";
+ ::aos::logging::AddImplementation(
+ new ::aos::logging::StreamLogImplementation(stdout));
+
while (true) {
static struct option long_options[] = {
{"name", required_argument, NULL, 'n'},
@@ -100,16 +105,16 @@
break;
case 'f':
follow = true;
- start_at_beginning = false;
+ skip_to_end = true;
break;
case 't':
follow = false;
break;
case 'b':
- start_at_beginning = true;
+ skip_to_end = false;
break;
case 'e':
- start_at_beginning = false;
+ skip_to_end = true;
break;
case 'm':
abort();
@@ -145,8 +150,9 @@
exit(EXIT_FAILURE);
}
::aos::logging::linux_code::LogFileAccessor accessor(fd, false);
- if (!start_at_beginning) {
- accessor.MoveToEnd();
+
+ if (skip_to_end) {
+ fputs("skipping old logs...\n", stderr);
}
const LogFileMessageHeader *msg;
@@ -166,6 +172,15 @@
continue;
}
+ if (skip_to_end) {
+ if (accessor.IsLastPage()) {
+ fputs("done skipping old logs\n", stderr);
+ skip_to_end = false;
+ } else {
+ continue;
+ }
+ }
+
if (::aos::logging::log_gt_important(filter_level, msg->level)) continue;
if (filter_name != NULL) {
if (filter_length != msg->name_size) continue;