Convert aos over to flatbuffers
Everything builds, and all the tests pass. I suspect that some entries
are missing from the config files, but those will be found pretty
quickly on startup.
There is no logging or live introspection of queue messages.
Change-Id: I496ee01ed68f202c7851bed7e8786cee30df29f5
diff --git a/aos/logging/BUILD b/aos/logging/BUILD
index 60c561b..6157e52 100644
--- a/aos/logging/BUILD
+++ b/aos/logging/BUILD
@@ -20,25 +20,6 @@
],
)
-cc_library(
- name = "replay",
- srcs = [
- "replay.cc",
- ],
- hdrs = [
- "replay.h",
- ],
- visibility = ["//visibility:public"],
- deps = [
- ":binary_log_file",
- ":logging",
- ":queue_logging",
- "//aos:queues",
- "//aos/events:event-loop",
- "//aos/ipc_lib:queue",
- ],
-)
-
cc_binary(
name = "binary_log_writer",
srcs = [
@@ -52,7 +33,6 @@
"//aos:configuration",
"//aos:die",
"//aos:init",
- "//aos:queue_types",
"//aos/ipc_lib:queue",
"//aos/time",
],
@@ -85,7 +65,6 @@
":logging",
"//aos:configuration",
"//aos:init",
- "//aos:queue_types",
"//aos/util:string_to_num",
],
)
@@ -123,42 +102,6 @@
)
cc_library(
- name = "queue_logging",
- srcs = [
- "queue_logging.cc",
- ],
- hdrs = [
- "queue_logging.h",
- ],
- visibility = ["//visibility:public"],
- deps = [
- ":logging",
- ":sizes",
- "//aos:die",
- "//aos:queue_types",
- ],
-)
-
-cc_library(
- name = "matrix_logging",
- srcs = [
- "matrix_logging.cc",
- ],
- hdrs = [
- "matrix_logging.h",
- ],
- visibility = ["//visibility:public"],
- deps = [
- ":logging",
- ":sizes",
- "//aos:die",
- "//aos:generated_queue_headers",
- "//aos:queue_types",
- "//third_party/eigen",
- ],
-)
-
-cc_library(
name = "printf_formats",
hdrs = [
"printf_formats.h",
@@ -183,11 +126,11 @@
visibility = ["//visibility:public"],
deps = [
":logging",
+ ":printf_formats",
":sizes",
"//aos:die",
"//aos:macros",
"//aos:once",
- "//aos:queue_types",
"//aos/ipc_lib:queue",
"//aos/mutex",
"//aos/time",
diff --git a/aos/logging/binary_log_writer.cc b/aos/logging/binary_log_writer.cc
index be19d45..5b1dc38 100644
--- a/aos/logging/binary_log_writer.cc
+++ b/aos/logging/binary_log_writer.cc
@@ -18,7 +18,6 @@
#include "aos/die.h"
#include "aos/logging/binary_log_file.h"
#include "aos/logging/implementations.h"
-#include "aos/queue_types.h"
#include "aos/time/time.h"
#include "aos/configuration.h"
#include "aos/init.h"
@@ -29,41 +28,6 @@
namespace linux_code {
namespace {
-void CheckTypeWritten(uint32_t type_id, LogFileWriter *writer,
- ::std::unordered_set<uint32_t> *written_type_ids) {
- if (written_type_ids->count(type_id) > 0) return;
- if (MessageType::IsPrimitive(type_id)) return;
-
- const MessageType &type = type_cache::Get(type_id);
- for (int i = 0; i < type.number_fields; ++i) {
- CheckTypeWritten(type.fields[i]->type, writer, written_type_ids);
- }
-
- char buffer[1024];
- ssize_t size = type.Serialize(buffer, sizeof(buffer));
- if (size == -1) {
- AOS_LOG(WARNING, "%zu-byte buffer is too small to serialize type %s\n",
- sizeof(buffer), type.name.c_str());
- return;
- }
- LogFileMessageHeader *const output =
- writer->GetWritePosition(sizeof(LogFileMessageHeader) + size);
-
- output->time_sec = output->time_nsec = 0;
- output->source = getpid();
- output->name_size = 0;
- output->sequence = 0;
- output->level = FATAL;
-
- memcpy(output + 1, buffer, size);
- output->message_size = size;
-
- output->type = LogFileMessageHeader::MessageType::kStructType;
- futex_set(&output->marker);
-
- written_type_ids->insert(type_id);
-}
-
void AllocateLogName(char **filename, const char *directory) {
int fileindex = 0;
DIR *const d = opendir(directory);
@@ -205,7 +169,6 @@
RawQueue *queue = GetLoggingQueue();
::std::unordered_set<uint32_t> written_type_ids;
- off_t clear_type_ids_cookie = 0;
while (true) {
const LogMessage *const msg =
@@ -222,21 +185,6 @@
const size_t raw_output_length =
sizeof(LogFileMessageHeader) + msg->name_length + msg->message_length;
size_t output_length = raw_output_length;
- if (msg->type == LogMessage::Type::kStruct) {
- output_length += sizeof(msg->structure.type_id) + sizeof(uint32_t) +
- msg->structure.string_length;
- if (writer.ShouldClearSeekableData(&clear_type_ids_cookie,
- output_length)) {
- writer.ForceNewPage();
- written_type_ids.clear();
- }
- CheckTypeWritten(msg->structure.type_id, &writer, &written_type_ids);
- } else if (msg->type == LogMessage::Type::kMatrix) {
- output_length +=
- sizeof(msg->matrix.type) + sizeof(uint32_t) + sizeof(uint16_t) +
- sizeof(uint16_t) + msg->matrix.string_length;
- AOS_CHECK(MessageType::IsPrimitive(msg->matrix.type));
- }
LogFileMessageHeader *const output = writer.GetWritePosition(output_length);
char *output_strings = reinterpret_cast<char *>(output) + sizeof(*output);
output->name_size = msg->name_length;
@@ -254,50 +202,6 @@
msg->message_length);
output->type = LogFileMessageHeader::MessageType::kString;
break;
- case LogMessage::Type::kStruct: {
- char *position = output_strings + msg->name_length;
-
- memcpy(position, &msg->structure.type_id,
- sizeof(msg->structure.type_id));
- position += sizeof(msg->structure.type_id);
- output->message_size += sizeof(msg->structure.type_id);
-
- const uint32_t length = msg->structure.string_length;
- memcpy(position, &length, sizeof(length));
- position += sizeof(length);
- memcpy(position, msg->structure.serialized,
- length + msg->message_length);
- position += length + msg->message_length;
- output->message_size += sizeof(length) + length;
-
- output->type = LogFileMessageHeader::MessageType::kStruct;
- } break;
- case LogMessage::Type::kMatrix: {
- char *position = output_strings + msg->name_length;
-
- memcpy(position, &msg->matrix.type, sizeof(msg->matrix.type));
- position += sizeof(msg->matrix.type);
- output->message_size += sizeof(msg->matrix.type);
-
- uint32_t length = msg->matrix.string_length;
- memcpy(position, &length, sizeof(length));
- position += sizeof(length);
- output->message_size += sizeof(length);
-
- uint16_t rows = msg->matrix.rows, cols = msg->matrix.cols;
- memcpy(position, &rows, sizeof(rows));
- position += sizeof(rows);
- memcpy(position, &cols, sizeof(cols));
- position += sizeof(cols);
- output->message_size += sizeof(rows) + sizeof(cols);
- AOS_CHECK_EQ(msg->message_length,
- MessageType::Sizeof(msg->matrix.type) * rows * cols);
-
- memcpy(position, msg->matrix.data, msg->message_length + length);
- output->message_size += length;
-
- output->type = LogFileMessageHeader::MessageType::kMatrix;
- } break;
}
if (output->message_size - msg->message_length !=
diff --git a/aos/logging/context.cc b/aos/logging/context.cc
index 2fcb301..72c1970 100644
--- a/aos/logging/context.cc
+++ b/aos/logging/context.cc
@@ -1,5 +1,9 @@
#include "aos/logging/context.h"
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE /* See feature_test_macros(7) */
+#endif
+
#include <string.h>
#include <sys/prctl.h>
#include <sys/types.h>
@@ -7,6 +11,11 @@
#include <string>
+#include <errno.h>
+
+extern char *program_invocation_name;
+extern char *program_invocation_short_name;
+
#include "aos/die.h"
#include "aos/complex_thread_local.h"
diff --git a/aos/logging/implementations.cc b/aos/logging/implementations.cc
index 632d90b..2220e4e 100644
--- a/aos/logging/implementations.cc
+++ b/aos/logging/implementations.cc
@@ -8,7 +8,6 @@
#include "aos/die.h"
#include "aos/logging/printf_formats.h"
-#include "aos/queue_types.h"
#include "aos/time/time.h"
#include "aos/ipc_lib/queue.h"
#include "aos/once.h"
@@ -23,10 +22,15 @@
// Some of the things specified in the LogImplementation documentation doesn't
// apply here (mostly the parts about being able to use AOS_LOG) because this is
// the root one.
-class RootLogImplementation : public SimpleLogImplementation {
+class RootLogImplementation : public LogImplementation {
public:
void have_other_implementation() { only_implementation_ = false; }
+ protected:
+ virtual ::aos::monotonic_clock::time_point monotonic_now() const {
+ return ::aos::monotonic_clock::now();
+ }
+
private:
void set_next(LogImplementation *) override {
AOS_LOG(FATAL, "can't have a next logger from here\n");
@@ -101,66 +105,6 @@
} // namespace
-void FillInMessageStructure(bool add_to_type_cache, log_level level,
- monotonic_clock::time_point monotonic_now,
- const ::std::string &message_string, size_t size,
- const MessageType *type,
- const ::std::function<size_t(char *)> &serialize,
- LogMessage *message) {
- if (add_to_type_cache) {
- type_cache::AddShm(type->id);
- }
- message->structure.type_id = type->id;
-
- FillInMessageBase(level, monotonic_now, message);
-
- if (message_string.size() + size > sizeof(message->structure.serialized)) {
- AOS_LOG(
- FATAL,
- "serialized struct %s (size %zd + %zd > %zd) and message %s too big\n",
- type->name.c_str(), message_string.size(), size,
- sizeof(message->structure.serialized), message_string.c_str());
- }
- message->structure.string_length = message_string.size();
- memcpy(message->structure.serialized, message_string.data(),
- message->structure.string_length);
-
- message->message_length = serialize(
- &message->structure.serialized[message->structure.string_length]);
- message->type = LogMessage::Type::kStruct;
-}
-
-void FillInMessageMatrix(log_level level,
- monotonic_clock::time_point monotonic_now,
- const ::std::string &message_string, uint32_t type_id,
- int rows, int cols, const void *data,
- LogMessage *message) {
- AOS_CHECK(MessageType::IsPrimitive(type_id));
- message->matrix.type = type_id;
-
- const auto element_size = MessageType::Sizeof(type_id);
-
- FillInMessageBase(level, monotonic_now, message);
-
- message->message_length = rows * cols * element_size;
- if (message_string.size() + message->message_length >
- sizeof(message->matrix.data)) {
- AOS_LOG(FATAL,
- "%dx%d matrix of type %" PRIu32
- " (size %u) and message %s is too big\n",
- rows, cols, type_id, element_size, message_string.c_str());
- }
- message->matrix.string_length = message_string.size();
- memcpy(message->matrix.data, message_string.data(),
- message->matrix.string_length);
-
- message->matrix.rows = rows;
- message->matrix.cols = cols;
- SerializeMatrix(type_id, &message->matrix.data[message->matrix.string_length],
- data, rows, cols);
- message->type = LogMessage::Type::kMatrix;
-}
-
void FillInMessage(log_level level, monotonic_clock::time_point monotonic_now,
const char *format, va_list ap, LogMessage *message) {
FillInMessageBase(level, monotonic_now, message);
@@ -180,105 +124,12 @@
fprintf(output, AOS_LOGGING_BASE_FORMAT "%.*s", BASE_ARGS,
static_cast<int>(message.message_length), message.message);
break;
- case LogMessage::Type::kStruct: {
- char buffer[4096];
- size_t output_length = sizeof(buffer);
- size_t input_length = message.message_length;
- if (!PrintMessage(
- buffer, &output_length,
- message.structure.serialized + message.structure.string_length,
- &input_length, type_cache::Get(message.structure.type_id))) {
- AOS_LOG(
- FATAL,
- "printing message (%.*s) of type %s into %zu-byte buffer failed\n",
- static_cast<int>(message.message_length), message.message,
- type_cache::Get(message.structure.type_id).name.c_str(),
- sizeof(buffer));
- }
- if (input_length > 0) {
- AOS_LOG(WARNING, "%zu extra bytes on message of type %s\n",
- input_length,
- type_cache::Get(message.structure.type_id).name.c_str());
- }
- fprintf(output, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
- static_cast<int>(message.structure.string_length),
- message.structure.serialized,
- static_cast<int>(sizeof(buffer) - output_length), buffer);
- } break;
- case LogMessage::Type::kMatrix: {
- char buffer[1024];
- size_t output_length = sizeof(buffer);
- if (message.message_length !=
- static_cast<size_t>(message.matrix.rows * message.matrix.cols *
- MessageType::Sizeof(message.matrix.type))) {
- AOS_LOG(FATAL, "expected %d bytes of matrix data but have %zu\n",
- message.matrix.rows * message.matrix.cols *
- MessageType::Sizeof(message.matrix.type),
- message.message_length);
- }
- if (!PrintMatrix(buffer, &output_length,
- message.matrix.data + message.matrix.string_length,
- message.matrix.type, message.matrix.rows,
- message.matrix.cols)) {
- AOS_LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n",
- message.matrix.rows, message.matrix.cols, message.matrix.type);
- }
- fprintf(output, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
- static_cast<int>(message.matrix.string_length),
- message.matrix.data,
- static_cast<int>(sizeof(buffer) - output_length), buffer);
- } break;
}
#undef BASE_ARGS
}
} // namespace internal
-void SimpleLogImplementation::LogStruct(
- log_level level, const ::std::string &message, size_t size,
- const MessageType *type, const ::std::function<size_t(char *)> &serialize) {
- char serialized[1024];
- if (size > sizeof(serialized)) {
- AOS_LOG(FATAL, "structure of type %s too big to serialize\n",
- type->name.c_str());
- }
- size_t used = serialize(serialized);
- char printed[1024];
- size_t printed_bytes = sizeof(printed);
- if (!PrintMessage(printed, &printed_bytes, serialized, &used, *type)) {
- AOS_LOG(FATAL,
- "PrintMessage(%p, %p(=%zd), %p, %p(=%zd), %p(name=%s)) failed\n",
- printed, &printed_bytes, printed_bytes, serialized, &used, used,
- type, type->name.c_str());
- }
- DoLogVariadic(level, "%.*s: %.*s\n", static_cast<int>(message.size()),
- message.data(),
- static_cast<int>(sizeof(printed) - printed_bytes), printed);
-}
-
-void SimpleLogImplementation::LogMatrix(
- log_level level, const ::std::string &message, uint32_t type_id,
- int rows, int cols, const void *data) {
- char serialized[1024];
- if (static_cast<size_t>(rows * cols * MessageType::Sizeof(type_id)) >
- sizeof(serialized)) {
- AOS_LOG(FATAL, "matrix of size %u too big to serialize\n",
- rows * cols * MessageType::Sizeof(type_id));
- }
- SerializeMatrix(type_id, serialized, data, rows, cols);
- char printed[1024];
- size_t printed_bytes = sizeof(printed);
- if (!PrintMatrix(printed, &printed_bytes, serialized, type_id, rows, cols)) {
- AOS_LOG(FATAL,
- "PrintMatrix(%p, %p(=%zd), %p, %" PRIu32 ", %d, %d) failed\n",
- printed, &printed_bytes, printed_bytes, serialized, type_id, rows,
- cols);
- }
- DoLogVariadic(level, "%.*s: %.*s\n", static_cast<int>(message.size()),
- message.data(),
- static_cast<int>(sizeof(printed) - printed_bytes), printed);
-}
-
void HandleMessageLogImplementation::DoLog(log_level level, const char *format,
va_list ap) {
LogMessage message;
@@ -286,25 +137,6 @@
HandleMessage(message);
}
-void HandleMessageLogImplementation::LogStruct(
- log_level level, const ::std::string &message_string, size_t size,
- const MessageType *type, const ::std::function<size_t(char *)> &serialize) {
- LogMessage message;
- internal::FillInMessageStructure(fill_type_cache(), level, monotonic_now(),
- message_string, size, type, serialize,
- &message);
- HandleMessage(message);
-}
-
-void HandleMessageLogImplementation::LogMatrix(
- log_level level, const ::std::string &message_string, uint32_t type_id,
- int rows, int cols, const void *data) {
- LogMessage message;
- internal::FillInMessageMatrix(level, monotonic_now(), message_string, type_id,
- rows, cols, data, &message);
- HandleMessage(message);
-}
-
StreamLogImplementation::StreamLogImplementation(FILE *stream)
: stream_(stream) {}
@@ -415,25 +247,6 @@
internal::FillInMessage(level, monotonic_now(), format, ap, message);
Write(message);
}
-
- void LogStruct(log_level level, const ::std::string &message_string,
- size_t size, const MessageType *type,
- const ::std::function<size_t(char *)> &serialize) override {
- LogMessage *message = GetMessageOrDie();
- internal::FillInMessageStructure(fill_type_cache(), level, monotonic_now(),
- message_string, size, type, serialize,
- message);
- Write(message);
- }
-
- void LogMatrix(log_level level, const ::std::string &message_string,
- uint32_t type_id, int rows, int cols,
- const void *data) override {
- LogMessage *message = GetMessageOrDie();
- internal::FillInMessageMatrix(level, monotonic_now(), message_string,
- type_id, rows, cols, data, message);
- Write(message);
- }
};
} // namespace
diff --git a/aos/logging/implementations.h b/aos/logging/implementations.h
index 5f7e1c5..27c0472 100644
--- a/aos/logging/implementations.h
+++ b/aos/logging/implementations.h
@@ -43,7 +43,7 @@
// Contains all of the information about a given logging call.
struct LogMessage {
enum class Type : uint8_t {
- kString, kStruct, kMatrix
+ kString
};
int32_t seconds, nseconds;
@@ -100,23 +100,6 @@
return LOG_UNKNOWN;
}
-// A LogImplementation where LogStruct and LogMatrix just create a string with
-// PrintMessage and then forward on to DoLog.
-class SimpleLogImplementation : public LogImplementation {
- protected:
- virtual ::aos::monotonic_clock::time_point monotonic_now() const {
- return ::aos::monotonic_clock::now();
- }
-
- private:
- void LogStruct(log_level level, const ::std::string &message, size_t size,
- const MessageType *type,
- const ::std::function<size_t(char *)> &serialize) override;
- void LogMatrix(log_level level, const ::std::string &message,
- uint32_t type_id, int rows, int cols,
- const void *data) override;
-};
-
// Implements all of the DoLog* methods in terms of a (pure virtual in this
// class) HandleMessage method that takes a pointer to the message.
class HandleMessageLogImplementation : public LogImplementation {
@@ -128,12 +111,6 @@
private:
__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
void DoLog(log_level level, const char *format, va_list ap) override;
- void LogStruct(log_level level, const ::std::string &message_string,
- size_t size, const MessageType *type,
- const ::std::function<size_t(char *)> &serialize) override;
- void LogMatrix(log_level level, const ::std::string &message_string,
- uint32_t type_id, int rows, int cols,
- const void *data) override;
virtual void HandleMessage(const LogMessage &message) = 0;
};
@@ -186,23 +163,6 @@
// goes.
namespace internal {
-// Fills in all the parts of message according to the given inputs (with type
-// kStruct).
-void FillInMessageStructure(bool add_to_type_cache, log_level level,
- ::aos::monotonic_clock::time_point monotonic_now,
- const ::std::string &message_string, size_t size,
- const MessageType *type,
- const ::std::function<size_t(char *)> &serialize,
- LogMessage *message);
-
-// Fills in all the parts of the message according to the given inputs (with
-// type kMatrix).
-void FillInMessageMatrix(log_level level,
- ::aos::monotonic_clock::time_point monotonic_now,
- const ::std::string &message_string, uint32_t type_id,
- int rows, int cols, const void *data,
- LogMessage *message);
-
// Fills in *message according to the given inputs (with type kString).
// Used for implementing LogImplementation::DoLog.
void FillInMessage(log_level level,
diff --git a/aos/logging/implementations_test.cc b/aos/logging/implementations_test.cc
index 2accf35..d97e165 100644
--- a/aos/logging/implementations_test.cc
+++ b/aos/logging/implementations_test.cc
@@ -19,9 +19,13 @@
namespace chrono = ::std::chrono;
-class TestLogImplementation : public SimpleLogImplementation {
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
- void DoLog(log_level level, const char *format, va_list ap) override {
+class TestLogImplementation : public LogImplementation {
+ virtual ::aos::monotonic_clock::time_point monotonic_now() const {
+ return ::aos::monotonic_clock::now();
+ }
+
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0))) void DoLog(
+ log_level level, const char *format, va_list ap) override {
internal::FillInMessage(level, monotonic_now(), format, ap, &message_);
if (level == FATAL) {
@@ -175,7 +179,8 @@
monotonic_clock::time_point end = monotonic_clock::now();
auto diff = end - start;
printf("short message took %" PRId64 " nsec for %ld\n",
- chrono::duration_cast<chrono::nanoseconds>(diff).count(),
+ static_cast<int64_t>(
+ chrono::duration_cast<chrono::nanoseconds>(diff).count()),
kTimingCycles);
start = monotonic_clock::now();
@@ -185,7 +190,8 @@
end = monotonic_clock::now();
diff = end - start;
printf("long message took %" PRId64 " nsec for %ld\n",
- chrono::duration_cast<chrono::nanoseconds>(diff).count(),
+ static_cast<int64_t>(
+ chrono::duration_cast<chrono::nanoseconds>(diff).count()),
kTimingCycles);
}
diff --git a/aos/logging/interface.cc b/aos/logging/interface.cc
index bcd8470..b72f8e1 100644
--- a/aos/logging/interface.cc
+++ b/aos/logging/interface.cc
@@ -19,7 +19,7 @@
static const char *const continued = "...\n";
const size_t size = output_size - strlen(continued);
const int ret = vsnprintf(output, size, format, ap);
- typedef ::std::common_type<typeof(ret), typeof(size)>::type RetType;
+ typedef ::std::common_type<int, size_t>::type RetType;
if (ret < 0) {
AOS_PLOG(FATAL, "vsnprintf(%p, %zd, %s, args) failed",
output, size, format);
diff --git a/aos/logging/interface.h b/aos/logging/interface.h
index 50237fc..92f0b10 100644
--- a/aos/logging/interface.h
+++ b/aos/logging/interface.h
@@ -16,19 +16,6 @@
struct MessageType;
namespace logging {
-namespace internal {
-
-// Defined in queue_logging.cc.
-void DoLogStruct(log_level level, const ::std::string &message, size_t size,
- const MessageType *type,
- const ::std::function<size_t(char *)> &serialize, int levels);
-
-// Defined in matrix_logging.cc.
-void DoLogMatrix(log_level level, const ::std::string &message,
- uint32_t type_id, int rows, int cols, const void *data,
- int levels);
-
-} // namespace internal
// Takes a message and logs it. It will set everything up and then call DoLog
// for the current LogImplementation.
@@ -75,20 +62,6 @@
va_end(ap);
}
- // Logs the contents of an auto-generated structure.
- // size and type are the result of calling Size() and Type() on the type of
- // the message.
- // serialize will call Serialize on the message.
- virtual void LogStruct(log_level level, const ::std::string &message,
- size_t size, const MessageType *type,
- const ::std::function<size_t(char *)> &serialize) = 0;
- // Similiar to LogStruct, except for matrixes.
- // type_id is the type of the elements of the matrix.
- // data points to rows*cols*type_id.Size() bytes of data in row-major order.
- virtual void LogMatrix(log_level level, const ::std::string &message,
- uint32_t type_id, int rows, int cols,
- const void *data) = 0;
-
private:
// These functions call similar methods on the "current" LogImplementation or
// Die if they can't find one.
@@ -97,14 +70,6 @@
__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 0)));
friend void VLog(log_level, const char *, va_list);
- friend void internal::DoLogStruct(
- log_level level, const ::std::string &message, size_t size,
- const MessageType *type, const ::std::function<size_t(char *)> &serialize,
- int levels);
- friend void internal::DoLogMatrix(log_level level,
- const ::std::string &message,
- uint32_t type_id, int rows, int cols,
- const void *data, int levels);
LogImplementation *next_;
};
diff --git a/aos/logging/log_displayer.cc b/aos/logging/log_displayer.cc
index e63bdc3..fe902c0 100644
--- a/aos/logging/log_displayer.cc
+++ b/aos/logging/log_displayer.cc
@@ -13,7 +13,6 @@
#include "aos/configuration.h"
#include "aos/logging/binary_log_file.h"
-#include "aos/queue_types.h"
#include "aos/logging/logging.h"
#include "aos/logging/implementations.h"
#include "aos/logging/printf_formats.h"
@@ -267,28 +266,6 @@
return 0;
}
- if (msg->type == LogFileMessageHeader::MessageType::kStructType) {
- size_t bytes = msg->message_size;
- ::aos::MessageType *type = ::aos::MessageType::Deserialize(
- reinterpret_cast<const char *>(msg + 1), &bytes);
- if (type == nullptr) {
- AOS_LOG(INFO, "Trying old version of type decoding.\n");
- bytes = msg->message_size;
- type = ::aos::MessageType::Deserialize(
- reinterpret_cast<const char *>(msg + 1), &bytes, false);
- }
-
- if (type == nullptr) {
- AOS_LOG(WARNING,
- "Error deserializing MessageType of size %" PRIx32
- " starting at %zx.\n",
- msg->message_size, reader.file_offset(msg + 1));
- } else {
- ::aos::type_cache::Add(*type);
- }
- continue;
- }
-
if (source_pid >= 0 && msg->source != source_pid) {
// Message is from the wrong process.
continue;
@@ -342,69 +319,10 @@
fprintf(stdout, AOS_LOGGING_BASE_FORMAT "%.*s", BASE_ARGS,
static_cast<int>(msg->message_size), position);
break;
- case LogFileMessageHeader::MessageType::kStruct: {
- uint32_t type_id;
- memcpy(&type_id, position, sizeof(type_id));
- position += sizeof(type_id);
-
- uint32_t string_length;
- memcpy(&string_length, position, sizeof(string_length));
- position += sizeof(string_length);
-
- char buffer[4096];
- size_t output_length = sizeof(buffer);
- size_t input_length =
- msg->message_size -
- (sizeof(type_id) + sizeof(uint32_t) + string_length);
- if (!PrintMessage(buffer, &output_length, position + string_length,
- &input_length, ::aos::type_cache::Get(type_id))) {
- AOS_LOG(FATAL,
- "printing message (%.*s) of type %s into %zu-byte buffer "
- "failed\n",
- static_cast<int>(string_length), position,
- ::aos::type_cache::Get(type_id).name.c_str(), sizeof(buffer));
- }
- if (input_length > 0) {
- AOS_LOG(WARNING, "%zu extra bytes on message of type %s\n",
- input_length, ::aos::type_cache::Get(type_id).name.c_str());
- }
- fprintf(stdout, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
- static_cast<int>(string_length), position,
- static_cast<int>(sizeof(buffer) - output_length), buffer);
- } break;
- case LogFileMessageHeader::MessageType::kMatrix: {
- uint32_t type;
- memcpy(&type, position, sizeof(type));
- position += sizeof(type);
-
- uint32_t string_length;
- memcpy(&string_length, position, sizeof(string_length));
- position += sizeof(string_length);
-
- uint16_t rows;
- memcpy(&rows, position, sizeof(rows));
- position += sizeof(rows);
- uint16_t cols;
- memcpy(&cols, position, sizeof(cols));
- position += sizeof(cols);
-
- const size_t matrix_bytes =
- msg->message_size -
- (sizeof(type) + sizeof(uint32_t) + sizeof(uint16_t) +
- sizeof(uint16_t) + string_length);
- AOS_CHECK_EQ(matrix_bytes,
- ::aos::MessageType::Sizeof(type) * rows * cols);
- char buffer[4096];
- size_t output_length = sizeof(buffer);
- if (!::aos::PrintMatrix(buffer, &output_length,
- position + string_length, type, rows, cols)) {
- AOS_LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n",
- rows, cols, type);
- }
- fprintf(stdout, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
- static_cast<int>(string_length), position,
- static_cast<int>(sizeof(buffer) - output_length), buffer);
- } break;
+ case LogFileMessageHeader::MessageType::kStruct:
+ case LogFileMessageHeader::MessageType::kMatrix:
+ AOS_LOG(FATAL, "Unsupported matrix or struct\n");
+ break;
case LogFileMessageHeader::MessageType::kStructType:
AOS_LOG(FATAL, "shouldn't get here\n");
break;
diff --git a/aos/logging/matrix_logging.cc b/aos/logging/matrix_logging.cc
deleted file mode 100644
index e17c8a6..0000000
--- a/aos/logging/matrix_logging.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "aos/logging/matrix_logging.h"
-
-#include "aos/queue_types.h"
-#include "aos/logging/sizes.h"
-
-namespace aos {
-namespace logging {
-namespace internal {
-
-void DoLogMatrix(log_level level, const ::std::string &message,
- uint32_t type_id, int rows, int cols, const void *data,
- int levels) {
- {
- auto fn = [&](LogImplementation *implementation) {
- implementation->LogMatrix(level, message, type_id, rows, cols, data);
- };
- RunWithCurrentImplementation(levels, ::std::ref(fn));
- }
-
- if (level == FATAL) {
- char serialized[1024];
- if (static_cast<size_t>(rows * cols * MessageType::Sizeof(type_id)) >
- sizeof(serialized)) {
- Die("LOG(FATAL) matrix too big to serialize");
- }
- SerializeMatrix(type_id, serialized, data, rows, cols);
- char printed[LOG_MESSAGE_LEN];
- size_t printed_bytes = sizeof(printed);
- if (!PrintMatrix(printed, &printed_bytes, serialized, type_id, rows, cols)) {
- Die("LOG(FATAL) PrintMatrix call failed");
- }
- Die("%.*s: %.*s\n", static_cast<int>(message.size()), message.data(),
- static_cast<int>(printed_bytes), printed);
- }
-}
-
-} // namespace internal
-} // namespace logging
-} // namespace aos
diff --git a/aos/logging/matrix_logging.h b/aos/logging/matrix_logging.h
deleted file mode 100644
index ef51d56..0000000
--- a/aos/logging/matrix_logging.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef AOS_LOGGING_MATRIX_LOGGING_H_
-#define AOS_LOGGING_MATRIX_LOGGING_H_
-
-#include <string>
-#include <functional>
-
-#include "Eigen/Dense"
-
-#include "aos/logging/interface.h"
-#include "aos/die.h"
-#include "aos/queue_primitives.h"
-
-namespace aos {
-namespace logging {
-
-// Logs the contents of a matrix and a constant string.
-// matrix must be an instance of an Eigen matrix (or something similar).
-#define AOS_LOG_MATRIX(level, message, matrix) \
- do { \
- static const ::std::string kAosLoggingMessage( \
- LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message); \
- ::aos::logging::DoLogMatrixTemplated(level, kAosLoggingMessage, \
- (matrix).eval()); \
- /* so that GCC knows that it won't return */ \
- if (level == FATAL) { \
- ::aos::Die("DoLogStruct(FATAL) fell through!!!!!\n"); \
- } \
- } while (false)
-
-template <class T>
-void DoLogMatrixTemplated(log_level level, const ::std::string &message,
- const T &matrix) {
- if (T::IsRowMajor) {
- typename T::Scalar data[matrix.rows() * matrix.cols()];
- ::Eigen::Map<T>(data, matrix.rows(), matrix.cols()) = matrix;
- internal::DoLogMatrix(level, message, TypeID<typename T::Scalar>::id,
- matrix.rows(), matrix.cols(), data, 1);
- } else {
- internal::DoLogMatrix(level, message, TypeID<typename T::Scalar>::id,
- matrix.rows(), matrix.cols(), matrix.data(), 1);
- }
-}
-
-} // namespace logging
-} // namespace aos
-
-#endif // AOS_LOGGING_MATRIX_LOGGING_H_
diff --git a/aos/logging/queue_logging.cc b/aos/logging/queue_logging.cc
deleted file mode 100644
index 541ddb1..0000000
--- a/aos/logging/queue_logging.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "aos/logging/queue_logging.h"
-
-#include "aos/logging/interface.h"
-#include "aos/logging/sizes.h"
-#include "aos/queue_types.h"
-
-namespace aos {
-namespace logging {
-namespace internal {
-
-void DoLogStruct(log_level level, const ::std::string &message, size_t size,
- const MessageType *type,
- const ::std::function<size_t(char *)> &serialize, int levels) {
- {
- auto fn = [&](LogImplementation *implementation) {
- implementation->LogStruct(level, message, size, type, serialize);
- };
- RunWithCurrentImplementation(levels, ::std::ref(fn));
- }
-
- if (level == FATAL) {
- char serialized[1024];
- if (size > sizeof(serialized)) {
- Die("LOG(FATAL) structure too big to serialize");
- }
- size_t used = serialize(serialized);
- char printed[LOG_MESSAGE_LEN];
- size_t printed_bytes = sizeof(printed);
- if (!PrintMessage(printed, &printed_bytes, serialized, &used, *type)) {
- Die("LOG(FATAL) PrintMessage call failed");
- }
- Die("%.*s: %.*s\n", static_cast<int>(message.size()), message.data(),
- static_cast<int>(printed_bytes), printed);
- }
-}
-
-} // namespace internal
-} // namespace logging
-} // namespace aos
diff --git a/aos/logging/queue_logging.h b/aos/logging/queue_logging.h
deleted file mode 100644
index fdebcc3..0000000
--- a/aos/logging/queue_logging.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef AOS_LOGGING_QUEUE_LOGGING_H_
-#define AOS_LOGGING_QUEUE_LOGGING_H_
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <functional>
-#include <string>
-
-#include "aos/logging/interface.h"
-#include "aos/die.h"
-
-namespace aos {
-namespace logging {
-
-// Logs the contents of a structure (or Queue message) and a constant string.
-// structure must be an instance of one of the generated queue types.
-#define AOS_LOG_STRUCT(level, message, structure) \
- do { \
- static const ::std::string kAosLoggingMessage( \
- LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message); \
- ::aos::logging::DoLogStructTemplated(level, kAosLoggingMessage, \
- structure); \
- /* so that GCC knows that it won't return */ \
- if (level == FATAL) { \
- ::aos::Die("DoLogStruct(FATAL) fell through!!!!!\n"); \
- } \
- } while (false)
-
-template <class T>
-void DoLogStructTemplated(log_level level, const ::std::string &message,
- const T &structure) {
- auto fn = [&structure](char *buffer)
- -> size_t { return structure.Serialize(buffer); };
-
- internal::DoLogStruct(level, message, T::Size(), T::GetType(), ::std::ref(fn),
- 1);
-}
-
-} // namespace logging
-} // namespace aos
-
-#endif // AOS_LOGGING_QUEUE_LOGGING_H_
diff --git a/aos/logging/replay.cc b/aos/logging/replay.cc
deleted file mode 100644
index c58ee8c..0000000
--- a/aos/logging/replay.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-#include "aos/logging/replay.h"
-
-#include <chrono>
-
-namespace aos {
-namespace logging {
-namespace linux_code {
-
-namespace chrono = ::std::chrono;
-
-bool LogReplayer::ProcessMessage() {
- const LogFileMessageHeader *message = reader_->ReadNextMessage(false);
- if (message == nullptr) return true;
- if (message->type != LogFileMessageHeader::MessageType::kStruct) return false;
-
- const char *position = reinterpret_cast<const char *>(message + 1);
-
- ::std::string process(position, message->name_size);
- position += message->name_size;
-
- uint32_t type_id;
- memcpy(&type_id, position, sizeof(type_id));
- position += sizeof(type_id);
-
- uint32_t message_length;
- memcpy(&message_length, position, sizeof(message_length));
- position += sizeof(message_length);
- ::std::string message_text(position, message_length);
- position += message_length;
-
- size_t split_index = message_text.find_first_of(':') + 2;
- split_index = message_text.find_first_of(':', split_index) + 2;
- message_text = message_text.substr(split_index);
-
- auto handler = handlers_.find(Key(process, message_text));
- if (handler == handlers_.end()) return false;
-
- handler->second->HandleStruct(
- monotonic_clock::time_point(chrono::seconds(message->time_sec) +
- chrono::nanoseconds(message->time_nsec)),
- type_id, position,
- message->message_size -
- (sizeof(type_id) + sizeof(message_length) + message_length));
- return false;
-}
-
-} // namespace linux_code
-} // namespace logging
-} // namespace aos
diff --git a/aos/logging/replay.h b/aos/logging/replay.h
deleted file mode 100644
index 6604591..0000000
--- a/aos/logging/replay.h
+++ /dev/null
@@ -1,171 +0,0 @@
-#ifndef AOS_LOGGING_REPLAY_H_
-#define AOS_LOGGING_REPLAY_H_
-
-#include <unordered_map>
-#include <string>
-#include <functional>
-#include <memory>
-
-#include "aos/events/event-loop.h"
-#include "aos/ipc_lib/queue.h"
-#include "aos/logging/binary_log_file.h"
-#include "aos/logging/logging.h"
-#include "aos/logging/queue_logging.h"
-#include "aos/macros.h"
-#include "aos/queue.h"
-#include "aos/queue_types.h"
-
-namespace aos {
-namespace logging {
-namespace linux_code {
-
-// Manages pulling logged queue messages out of log files.
-//
-// Basic usage:
-// - Use the Add* methods to register handlers for various message sources.
-// - Call OpenFile to open a log file.
-// - Call ProcessMessage repeatedly until it returns true.
-//
-// This code could do something to adapt similar-but-not-identical
-// messages to the current versions, but currently it will LOG(FATAL) if any of
-// the messages don't match up exactly.
-class LogReplayer {
- public:
- LogReplayer() {}
-
- // Gets ready to read messages from fd.
- // Does not take ownership of fd.
- void OpenFile(int fd) {
- reader_.reset(new LogFileReader(fd));
- }
- // Closes the currently open file.
- void CloseCurrentFile() { reader_.reset(); }
- // Returns true if we have a file which is currently open.
- bool HasCurrentFile() const { return reader_.get() != nullptr; }
-
- // Processes a single message from the currently open file.
- // Returns true if there are no more messages in the file.
- // This will not call any of the handlers if the next message either has no
- // registered handlers or is not a queue message.
- bool ProcessMessage();
-
- // Adds a handler for messages with a certain string from a certain process.
- // T must be a Message with the same format as the messages generated by
- // the .q files.
- // LOG(FATAL)s for duplicate handlers.
- template <class T>
- void AddHandler(const ::std::string &process_name,
- const ::std::string &log_message,
- ::std::function<void(const T &message)> handler) {
- AOS_CHECK(handlers_
- .emplace(::std::piecewise_construct,
- ::std::forward_as_tuple(process_name, log_message),
- ::std::forward_as_tuple(
- ::std::unique_ptr<StructHandlerInterface>(
- new TypedStructHandler<T>(handler))))
- .second);
- }
-
- // Adds a handler which takes messages and places them directly on a queue.
- // T must be a Message with the same format as the messages generated by
- // the .q files.
- template <class T>
- void AddDirectQueueSender(const ::std::string &process_name,
- const ::std::string &log_message,
- const ::std::string &name) {
- AddHandler(process_name, log_message,
- ::std::function<void(const T &)>(
- QueueDumpStructHandler<T>(name.c_str())));
- }
-
- private:
- // A generic handler of struct log messages.
- class StructHandlerInterface {
- public:
- virtual ~StructHandlerInterface() {}
-
- virtual void HandleStruct(::aos::monotonic_clock::time_point log_time,
- uint32_t type_id, const void *data,
- size_t data_size) = 0;
- };
-
- // Converts struct log messages to a message type and passes it to an
- // ::std::function.
- template <class T>
- class TypedStructHandler : public StructHandlerInterface {
- public:
- TypedStructHandler(::std::function<void(const T &message)> handler)
- : handler_(handler) {}
-
- void HandleStruct(::aos::monotonic_clock::time_point log_time,
- uint32_t type_id, const void *data,
- size_t data_size) override {
- AOS_CHECK_EQ(type_id, T::GetType()->id);
- T message;
- AOS_CHECK_EQ(data_size, T::Size());
- AOS_CHECK_EQ(data_size,
- message.Deserialize(static_cast<const char *>(data)));
- message.sent_time = log_time;
- handler_(message);
- }
-
- private:
- const ::std::function<void(T message)> handler_;
- };
-
- // A callable class which dumps messages straight to a queue.
- template <class T>
- class QueueDumpStructHandler {
- public:
- QueueDumpStructHandler(const ::std::string &queue_name)
- : queue_(RawQueue::Fetch(queue_name.c_str(), sizeof(T), T::kHash,
- T::kQueueLength)) {}
-
- void operator()(const T &message) {
- AOS_LOG_STRUCT(DEBUG, "re-sending", message);
- void *raw_message = queue_->GetMessage();
- AOS_CHECK_NOTNULL(raw_message);
- memcpy(raw_message, &message, sizeof(message));
- AOS_CHECK(queue_->WriteMessage(raw_message, RawQueue::kOverride));
- }
-
- private:
- ::aos::RawQueue *const queue_;
- };
-
- // A key for specifying log messages to give to a certain handler.
- struct Key {
- Key(const ::std::string &process_name, const ::std::string &log_message)
- : process_name(process_name), log_message(log_message) {}
-
- ::std::string process_name;
- ::std::string log_message;
- };
-
- struct KeyHash {
- size_t operator()(const Key &key) const {
- return string_hash(key.process_name) ^
- (string_hash(key.log_message) << 1);
- }
-
- private:
- const ::std::hash<::std::string> string_hash = ::std::hash<::std::string>();
- };
- struct KeyEqual {
- bool operator()(const Key &a, const Key &b) const {
- return a.process_name == b.process_name && a.log_message == b.log_message;
- }
- };
-
- ::std::unordered_map<const Key, ::std::unique_ptr<StructHandlerInterface>,
- KeyHash, KeyEqual> handlers_;
- ::std::unique_ptr<LogFileReader> reader_;
-
- DISALLOW_COPY_AND_ASSIGN(LogReplayer);
-};
-
-} // namespace linux_code
-} // namespace logging
-} // namespace aos
-
-#endif // AOS_LOGGING_REPLAY_H_