blob: 3b298fa71ac85076b28d40ee9f238d4de757f12c [file] [log] [blame]
John Park398c74a2018-10-20 21:17:39 -07001#include "aos/init.h"
brians343bc112013-02-10 01:53:46 +00002
brians343bc112013-02-10 01:53:46 +00003#include <sched.h>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <sys/mman.h>
brians343bc112013-02-10 01:53:46 +00005#include <sys/resource.h>
brians343bc112013-02-10 01:53:46 +00006#include <sys/types.h>
7#include <unistd.h>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07008
9#include <cerrno>
10#include <cstdio>
11#include <cstdlib>
12#include <cstring>
brians343bc112013-02-10 01:53:46 +000013
Alex Perrycb7da4b2019-08-28 19:35:56 -070014#include "aos/realtime.h"
Austin Schuh094d09b2020-11-20 23:26:52 -080015#include "gflags/gflags.h"
16#include "glog/logging.h"
Brian Silverman40486622014-12-30 17:38:55 -080017
Austin Schuh707c8352020-03-15 14:27:25 -070018DEFINE_bool(coredump, false, "If true, write core dumps on failure.");
19
brians343bc112013-02-10 01:53:46 +000020namespace aos {
brians343bc112013-02-10 01:53:46 +000021namespace {
Austin Schuh094d09b2020-11-20 23:26:52 -080022bool initialized = false;
Austin Schuh3d4d5df2015-10-17 15:51:41 -070023} // namespace
24
Austin Schuh094d09b2020-11-20 23:26:52 -080025bool IsInitialized() { return initialized; }
26
Alex Perrycb7da4b2019-08-28 19:35:56 -070027void InitGoogle(int *argc, char ***argv) {
Austin Schuh094d09b2020-11-20 23:26:52 -080028 CHECK(!IsInitialized()) << "Only initialize once.";
Alex Perrycb7da4b2019-08-28 19:35:56 -070029 FLAGS_logtostderr = true;
30 google::InitGoogleLogging((*argv)[0]);
31 gflags::ParseCommandLineFlags(argc, argv, true);
32 google::InstallFailureSignalHandler();
Austin Schuh62288252020-11-18 23:26:04 -080033
Austin Schuh094d09b2020-11-20 23:26:52 -080034 if (FLAGS_coredump) {
35 WriteCoreDumps();
brians343bc112013-02-10 01:53:46 +000036 }
37
Austin Schuh094d09b2020-11-20 23:26:52 -080038 RegisterMallocHook();
39 initialized = true;
Brian Silvermane4d8b282015-12-24 13:44:48 -080040}
41
brians343bc112013-02-10 01:53:46 +000042} // namespace aos