Austin Schuh | 47aabde | 2020-10-10 17:46:37 -0700 | [diff] [blame] | 1 | #include <sys/resource.h> |
| 2 | #include <sys/time.h> |
| 3 | |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 4 | #include "aos/configuration.h" |
| 5 | #include "aos/events/logging/logger.h" |
| 6 | #include "aos/events/shm_event_loop.h" |
| 7 | #include "aos/init.h" |
Brian Silverman | d90905f | 2020-09-23 14:42:56 -0700 | [diff] [blame] | 8 | #include "aos/logging/log_namer.h" |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 9 | #include "gflags/gflags.h" |
| 10 | #include "glog/logging.h" |
| 11 | |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 12 | DEFINE_string(config, "config.json", "Config file to use."); |
| 13 | |
Austin Schuh | 2755315 | 2020-11-18 21:26:37 -0800 | [diff] [blame^] | 14 | DEFINE_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 Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 18 | int 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 Davis | a3d0841 | 2020-02-23 17:47:28 -0800 | [diff] [blame] | 32 | std::unique_ptr<aos::logger::LogNamer> log_namer; |
| 33 | if (event_loop.node() == nullptr) { |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 34 | log_namer = std::make_unique<aos::logger::LocalLogNamer>( |
| 35 | aos::logging::GetLogName("fbs_log"), event_loop.node()); |
Sabina Davis | a3d0841 | 2020-02-23 17:47:28 -0800 | [diff] [blame] | 36 | } else { |
| 37 | log_namer = std::make_unique<aos::logger::MultiNodeLogNamer>( |
Austin Schuh | e715eae | 2020-10-10 15:39:30 -0700 | [diff] [blame] | 38 | absl::StrCat(aos::logging::GetLogName("fbs_log"), "/"), |
| 39 | event_loop.configuration(), event_loop.node()); |
Sabina Davis | a3d0841 | 2020-02-23 17:47:28 -0800 | [diff] [blame] | 40 | } |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 41 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 42 | aos::logger::Logger logger(&event_loop); |
Austin Schuh | 47aabde | 2020-10-10 17:46:37 -0700 | [diff] [blame] | 43 | event_loop.OnRun([&log_namer, &logger]() { |
Austin Schuh | 2755315 | 2020-11-18 21:26:37 -0800 | [diff] [blame^] | 44 | if (FLAGS_skip_renicing) { |
| 45 | LOG(WARNING) << "Ignoring request to renice to -20 due to " |
| 46 | "--skip_renicing."; |
| 47 | } else { |
| 48 | errno = 0; |
| 49 | setpriority(PRIO_PROCESS, 0, -20); |
| 50 | PCHECK(errno == 0) |
| 51 | << ": Renicing to -20 failed, use --skip_renicing to skip renicing."; |
| 52 | } |
Austin Schuh | 47aabde | 2020-10-10 17:46:37 -0700 | [diff] [blame] | 53 | logger.StartLogging(std::move(log_namer)); |
| 54 | }); |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 55 | |
| 56 | event_loop.Run(); |
| 57 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 58 | LOG(INFO) << "Shutting down"; |
| 59 | |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 60 | return 0; |
| 61 | } |