Add a localizer logger that doesn't log images
Add this so that we can have a logger running on the localizer pi which
does not log images and so can be logging 100% of the time.
We may want to actually log this into an entirely different directory
than the image logs so that if the image logs fill up the disk we still
get regular logs.
Change-Id: Ida4906ecfcc65604c01e5f7fd2f1e8773d3ed25a
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/y2024/BUILD b/y2024/BUILD
index f710e7b..bba7b51 100644
--- a/y2024/BUILD
+++ b/y2024/BUILD
@@ -59,6 +59,7 @@
"//y2024/vision:viewer",
"//y2024/constants:constants_sender",
"//y2024/localizer:localizer_main",
+ "//y2024/localizer:localizer_logger",
"//y2024/vision:foxglove_image_converter",
],
data = [
diff --git a/y2024/localizer/BUILD b/y2024/localizer/BUILD
index 38c8c9d..caec284 100644
--- a/y2024/localizer/BUILD
+++ b/y2024/localizer/BUILD
@@ -147,3 +147,22 @@
"//y2024/control_loops/drivetrain:drivetrain_base",
],
)
+
+cc_binary(
+ name = "localizer_logger",
+ srcs = [
+ "localizer_logger.cc",
+ ],
+ target_compatible_with = ["@platforms//os:linux"],
+ visibility = ["//visibility:public"],
+ deps = [
+ "//aos:configuration",
+ "//aos:init",
+ "//aos/events:shm_event_loop",
+ "//aos/events/logging:log_writer",
+ "//aos/events/logging:snappy_encoder",
+ "//aos/logging:log_namer",
+ "@com_github_gflags_gflags//:gflags",
+ "@com_github_google_glog//:glog",
+ ],
+)
diff --git a/y2024/localizer/localizer_logger.cc b/y2024/localizer/localizer_logger.cc
new file mode 100644
index 0000000..ec8d3ac
--- /dev/null
+++ b/y2024/localizer/localizer_logger.cc
@@ -0,0 +1,80 @@
+#include <sys/resource.h>
+#include <sys/time.h>
+
+#include "gflags/gflags.h"
+#include "glog/logging.h"
+
+#include "aos/configuration.h"
+#include "aos/events/logging/log_writer.h"
+#include "aos/events/logging/snappy_encoder.h"
+#include "aos/events/shm_event_loop.h"
+#include "aos/init.h"
+#include "aos/logging/log_namer.h"
+
+DEFINE_string(config, "aos_config.json", "Config file to use.");
+
+DEFINE_double(rotate_every, 30.0,
+ "If set, rotate the logger after this many seconds");
+
+DECLARE_int32(flush_size);
+
+int main(int argc, char *argv[]) {
+ gflags::SetUsageMessage(
+ "This program provides a simple logger binary that logs all SHMEM data "
+ "directly to a file specified at the command line. It does not manage "
+ "filenames, so it will just crash if you attempt to overwrite an "
+ "existing file, and the user must specify the logfile manually at the "
+ "command line.");
+ aos::InitGoogle(&argc, &argv);
+
+ aos::FlatbufferDetachedBuffer<aos::Configuration> config =
+ aos::configuration::ReadConfig(FLAGS_config);
+
+ aos::ShmEventLoop event_loop(&config.message());
+
+ auto log_namer = std::make_unique<aos::logger::MultiNodeFilesLogNamer>(
+ &event_loop,
+ std::make_unique<aos::logger::RenamableFileBackend>(
+ absl::StrCat(aos::logging::GetLogName("localizer_log"), "/"),
+ /*O_DIRECT*/ true));
+
+ log_namer->set_extension(aos::logger::SnappyDecoder::kExtension);
+ log_namer->set_encoder_factory([](size_t max_message_size) {
+ return std::make_unique<aos::logger::SnappyEncoder>(max_message_size,
+ FLAGS_flush_size);
+ });
+
+ aos::monotonic_clock::time_point last_rotation_time =
+ event_loop.monotonic_now();
+ aos::logger::Logger logger(
+ &event_loop, event_loop.configuration(),
+ // Only log channels smaller than ~10 MB / sec.
+ [](const aos::Channel *channel) {
+ return (channel->max_size() * channel->frequency()) < 10e6;
+ });
+
+ if (FLAGS_rotate_every != 0.0) {
+ logger.set_on_logged_period(
+ [&logger, &last_rotation_time](aos::monotonic_clock::time_point t) {
+ if (t > last_rotation_time +
+ std::chrono::duration<double>(FLAGS_rotate_every)) {
+ logger.Rotate();
+ last_rotation_time = t;
+ }
+ });
+ }
+
+ event_loop.OnRun([&log_namer, &logger]() {
+ errno = 0;
+ setpriority(PRIO_PROCESS, 0, -20);
+ PCHECK(errno == 0)
+ << ": Renicing to -20 failed, use --skip_renicing to skip renicing.";
+ logger.StartLogging(std::move(log_namer));
+ });
+
+ event_loop.Run();
+
+ LOG(INFO) << "Shutting down";
+
+ return 0;
+}
diff --git a/y2024/vision/image_logger.cc b/y2024/vision/image_logger.cc
index 45e25f6..55a4e12 100644
--- a/y2024/vision/image_logger.cc
+++ b/y2024/vision/image_logger.cc
@@ -25,7 +25,7 @@
std::unique_ptr<aos::logger::MultiNodeFilesLogNamer> MakeLogNamer(
aos::EventLoop *event_loop) {
std::optional<std::string> log_name =
- aos::logging::MaybeGetLogName("fbs_log");
+ aos::logging::MaybeGetLogName("image_log");
if (!log_name.has_value()) {
return nullptr;
diff --git a/y2024/y2024_imu.json b/y2024/y2024_imu.json
index ff8f625..647009b 100644
--- a/y2024/y2024_imu.json
+++ b/y2024/y2024_imu.json
@@ -302,11 +302,7 @@
},
{
"name": "localizer_logger",
- "executable_name": "logger_main",
- "args": [
- "--snappy_compress",
- "--rotate_every", "30.0"
- ],
+ "executable_name": "localizer_logger",
"user": "pi",
"nodes": [
"imu"