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" |
Austin Schuh | b06f03b | 2021-02-17 22:00:37 -0800 | [diff] [blame] | 5 | #include "aos/events/logging/log_writer.h" |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame^] | 6 | #include "aos/events/logging/snappy_encoder.h" |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 7 | #include "aos/events/shm_event_loop.h" |
| 8 | #include "aos/init.h" |
Brian Silverman | d90905f | 2020-09-23 14:42:56 -0700 | [diff] [blame] | 9 | #include "aos/logging/log_namer.h" |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 10 | #include "gflags/gflags.h" |
| 11 | #include "glog/logging.h" |
| 12 | |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 13 | DEFINE_string(config, "config.json", "Config file to use."); |
| 14 | |
Austin Schuh | 2755315 | 2020-11-18 21:26:37 -0800 | [diff] [blame] | 15 | DEFINE_bool(skip_renicing, false, |
| 16 | "If true, skip renicing the logger. This leaves it lower priority " |
| 17 | "and increases the likelihood of dropping messages and crashing."); |
| 18 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame^] | 19 | DEFINE_bool(snappy_compress, false, "If true, compress log data using snappy."); |
| 20 | |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 21 | int main(int argc, char *argv[]) { |
| 22 | gflags::SetUsageMessage( |
| 23 | "This program provides a simple logger binary that logs all SHMEM data " |
| 24 | "directly to a file specified at the command line. It does not manage " |
| 25 | "filenames, so it will just crash if you attempt to overwrite an " |
| 26 | "existing file, and the user must specify the logfile manually at the " |
| 27 | "command line."); |
| 28 | aos::InitGoogle(&argc, &argv); |
| 29 | |
| 30 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 31 | aos::configuration::ReadConfig(FLAGS_config); |
| 32 | |
| 33 | aos::ShmEventLoop event_loop(&config.message()); |
| 34 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame^] | 35 | std::unique_ptr<aos::logger::MultiNodeLogNamer> log_namer; |
Milind Upadhyay | d3a7bdc | 2020-12-26 16:07:03 -0800 | [diff] [blame] | 36 | log_namer = std::make_unique<aos::logger::MultiNodeLogNamer>( |
Austin Schuh | a499cea | 2021-07-31 19:49:53 -0700 | [diff] [blame] | 37 | absl::StrCat(aos::logging::GetLogName("fbs_log"), "/"), &event_loop); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 38 | |
James Kuszmaul | dd0a504 | 2021-10-28 23:38:04 -0700 | [diff] [blame^] | 39 | if (FLAGS_snappy_compress) { |
| 40 | log_namer->set_extension(aos::logger::SnappyDecoder::kExtension); |
| 41 | log_namer->set_encoder_factory( |
| 42 | []() { return std::make_unique<aos::logger::SnappyEncoder>(); }); |
| 43 | } |
| 44 | |
Brian Silverman | 1f34522 | 2020-09-24 21:14:48 -0700 | [diff] [blame] | 45 | aos::logger::Logger logger(&event_loop); |
Austin Schuh | 47aabde | 2020-10-10 17:46:37 -0700 | [diff] [blame] | 46 | event_loop.OnRun([&log_namer, &logger]() { |
Austin Schuh | 2755315 | 2020-11-18 21:26:37 -0800 | [diff] [blame] | 47 | if (FLAGS_skip_renicing) { |
| 48 | LOG(WARNING) << "Ignoring request to renice to -20 due to " |
| 49 | "--skip_renicing."; |
| 50 | } else { |
| 51 | errno = 0; |
| 52 | setpriority(PRIO_PROCESS, 0, -20); |
| 53 | PCHECK(errno == 0) |
| 54 | << ": Renicing to -20 failed, use --skip_renicing to skip renicing."; |
| 55 | } |
Austin Schuh | 47aabde | 2020-10-10 17:46:37 -0700 | [diff] [blame] | 56 | logger.StartLogging(std::move(log_namer)); |
| 57 | }); |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 58 | |
| 59 | event_loop.Run(); |
| 60 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 61 | LOG(INFO) << "Shutting down"; |
| 62 | |
James Kuszmaul | 38735e8 | 2019-12-07 16:42:06 -0800 | [diff] [blame] | 63 | return 0; |
| 64 | } |