blob: 083fdb0b219b622a30af1a575be12078a8c46570 [file] [log] [blame]
Austin Schuh47aabde2020-10-10 17:46:37 -07001#include <sys/resource.h>
2#include <sys/time.h>
3
James Kuszmaul38735e82019-12-07 16:42:06 -08004#include "aos/configuration.h"
Austin Schuhb06f03b2021-02-17 22:00:37 -08005#include "aos/events/logging/log_writer.h"
James Kuszmaul38735e82019-12-07 16:42:06 -08006#include "aos/events/shm_event_loop.h"
7#include "aos/init.h"
Brian Silvermand90905f2020-09-23 14:42:56 -07008#include "aos/logging/log_namer.h"
James Kuszmaul38735e82019-12-07 16:42:06 -08009#include "gflags/gflags.h"
10#include "glog/logging.h"
11
James Kuszmaul38735e82019-12-07 16:42:06 -080012DEFINE_string(config, "config.json", "Config file to use.");
13
Austin Schuh27553152020-11-18 21:26:37 -080014DEFINE_bool(skip_renicing, false,
15 "If true, skip renicing the logger. This leaves it lower priority "
16 "and increases the likelihood of dropping messages and crashing.");
17
James Kuszmaul38735e82019-12-07 16:42:06 -080018int main(int argc, char *argv[]) {
19 gflags::SetUsageMessage(
20 "This program provides a simple logger binary that logs all SHMEM data "
21 "directly to a file specified at the command line. It does not manage "
22 "filenames, so it will just crash if you attempt to overwrite an "
23 "existing file, and the user must specify the logfile manually at the "
24 "command line.");
25 aos::InitGoogle(&argc, &argv);
26
27 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
28 aos::configuration::ReadConfig(FLAGS_config);
29
30 aos::ShmEventLoop event_loop(&config.message());
31
Sabina Davisa3d08412020-02-23 17:47:28 -080032 std::unique_ptr<aos::logger::LogNamer> log_namer;
Milind Upadhyayd3a7bdc2020-12-26 16:07:03 -080033 log_namer = std::make_unique<aos::logger::MultiNodeLogNamer>(
Austin Schuha499cea2021-07-31 19:49:53 -070034 absl::StrCat(aos::logging::GetLogName("fbs_log"), "/"), &event_loop);
Austin Schuhcde938c2020-02-02 17:30:07 -080035
Brian Silverman1f345222020-09-24 21:14:48 -070036 aos::logger::Logger logger(&event_loop);
Austin Schuh47aabde2020-10-10 17:46:37 -070037 event_loop.OnRun([&log_namer, &logger]() {
Austin Schuh27553152020-11-18 21:26:37 -080038 if (FLAGS_skip_renicing) {
39 LOG(WARNING) << "Ignoring request to renice to -20 due to "
40 "--skip_renicing.";
41 } else {
42 errno = 0;
43 setpriority(PRIO_PROCESS, 0, -20);
44 PCHECK(errno == 0)
45 << ": Renicing to -20 failed, use --skip_renicing to skip renicing.";
46 }
Austin Schuh47aabde2020-10-10 17:46:37 -070047 logger.StartLogging(std::move(log_namer));
48 });
James Kuszmaul38735e82019-12-07 16:42:06 -080049
50 event_loop.Run();
51
Austin Schuh2f8fd752020-09-01 22:38:28 -070052 LOG(INFO) << "Shutting down";
53
James Kuszmaul38735e82019-12-07 16:42:06 -080054 return 0;
55}