Prefix LOG and CHECK with AOS_
This prepares us for introducing glog more widely and transitioning
things over where they make sense.
Change-Id: Ic6c208882407bc2153fe875ffc736d66f5c8ade5
diff --git a/aos/actions/action_test.cc b/aos/actions/action_test.cc
index 45cfd62..178b2b0 100644
--- a/aos/actions/action_test.cc
+++ b/aos/actions/action_test.cc
@@ -75,7 +75,7 @@
bool RunAction(const uint32_t &) override {
while (!ShouldCancel()) {
- LOG(FATAL, "NOT CANCELED!!\n");
+ AOS_LOG(FATAL, "NOT CANCELED!!\n");
}
return true;
}
diff --git a/aos/actions/actions.cc b/aos/actions/actions.cc
index 11a7f03..528a8b2 100644
--- a/aos/actions/actions.cc
+++ b/aos/actions/actions.cc
@@ -6,25 +6,25 @@
void ActionQueue::EnqueueAction(::std::unique_ptr<Action> action) {
if (current_action_) {
- LOG(INFO, "Queueing action, canceling prior\n");
+ AOS_LOG(INFO, "Queueing action, canceling prior\n");
current_action_->Cancel();
next_action_ = ::std::move(action);
} else {
- LOG(INFO, "Queueing action\n");
+ AOS_LOG(INFO, "Queueing action\n");
current_action_ = ::std::move(action);
current_action_->Start();
}
}
void ActionQueue::CancelCurrentAction() {
- LOG(INFO, "Canceling current action\n");
+ AOS_LOG(INFO, "Canceling current action\n");
if (current_action_) {
current_action_->Cancel();
}
}
void ActionQueue::CancelAllActions() {
- LOG(DEBUG, "Cancelling all actions\n");
+ AOS_LOG(DEBUG, "Cancelling all actions\n");
if (current_action_) {
current_action_->Cancel();
}
@@ -34,10 +34,10 @@
void ActionQueue::Tick() {
if (current_action_) {
if (!current_action_->Running()) {
- LOG(INFO, "Action is done.\n");
+ AOS_LOG(INFO, "Action is done.\n");
current_action_ = ::std::move(next_action_);
if (current_action_) {
- LOG(INFO, "Running next action\n");
+ AOS_LOG(INFO, "Running next action\n");
current_action_->Start();
}
}
diff --git a/aos/actions/actions.h b/aos/actions/actions.h
index 430a978..e2b9ca8 100644
--- a/aos/actions/actions.h
+++ b/aos/actions/actions.h
@@ -124,17 +124,17 @@
run_value_(run_counter_.fetch_add(1, ::std::memory_order_relaxed) |
((getpid() & 0xFFFF) << 16)),
params_(params) {
- LOG(DEBUG, "Action %" PRIx32 " created on queue %s\n", run_value_,
- goal_sender_->name());
+ AOS_LOG(DEBUG, "Action %" PRIx32 " created on queue %s\n", run_value_,
+ goal_sender_->name());
// Clear out any old status messages from before now.
status_fetcher_->Fetch();
if (status_fetcher_->get()) {
- LOG_STRUCT(DEBUG, "have status", *status_fetcher_->get());
+ AOS_LOG_STRUCT(DEBUG, "have status", *status_fetcher_->get());
}
}
virtual ~TypedAction() {
- LOG(DEBUG, "Calling destructor of %" PRIx32 "\n", run_value_);
+ AOS_LOG(DEBUG, "Calling destructor of %" PRIx32 "\n", run_value_);
DoCancel();
}
@@ -231,20 +231,21 @@
template <typename T>
void TypedAction<T>::DoCancel() {
if (!sent_started_) {
- LOG(INFO, "Action %" PRIx32 " on queue %s was never started\n", run_value_,
- goal_sender_->name());
+ AOS_LOG(INFO, "Action %" PRIx32 " on queue %s was never started\n",
+ run_value_, goal_sender_->name());
} else {
if (interrupted_) {
- LOG(INFO,
- "Action %" PRIx32 " on queue %s was interrupted -> not cancelling\n",
- run_value_, goal_sender_->name());
+ AOS_LOG(INFO,
+ "Action %" PRIx32
+ " on queue %s was interrupted -> not cancelling\n",
+ run_value_, goal_sender_->name());
} else {
if (sent_cancel_) {
- LOG(DEBUG, "Action %" PRIx32 " on queue %s already cancelled\n",
- run_value_, goal_sender_->name());
+ AOS_LOG(DEBUG, "Action %" PRIx32 " on queue %s already cancelled\n",
+ run_value_, goal_sender_->name());
} else {
- LOG(DEBUG, "Canceling action %" PRIx32 " on queue %s\n", run_value_,
- goal_sender_->name());
+ AOS_LOG(DEBUG, "Canceling action %" PRIx32 " on queue %s\n", run_value_,
+ goal_sender_->name());
{
auto goal_message = goal_sender_->MakeMessage();
goal_message->run = 0;
@@ -259,7 +260,7 @@
template <typename T>
bool TypedAction<T>::DoRunning() {
if (!sent_started_) {
- LOG(DEBUG, "haven't sent start message yet\n");
+ AOS_LOG(DEBUG, "haven't sent start message yet\n");
return false;
}
if (has_started_) {
@@ -267,7 +268,7 @@
CheckInterrupted();
} else {
while (status_fetcher_->FetchNext()) {
- LOG_STRUCT(DEBUG, "got status", *status_fetcher_->get());
+ AOS_LOG_STRUCT(DEBUG, "got status", *status_fetcher_->get());
CheckStarted();
if (has_started_) CheckInterrupted();
}
@@ -282,13 +283,13 @@
template <typename T>
bool TypedAction<T>::DoCheckIteration() {
- CHECK(sent_started_);
+ AOS_CHECK(sent_started_);
if (interrupted_) return true;
CheckStarted();
if (!status_fetcher_->FetchNext()) {
return false;
}
- LOG_STRUCT(DEBUG, "got status", *status_fetcher_->get());
+ AOS_LOG_STRUCT(DEBUG, "got status", *status_fetcher_->get());
CheckStarted();
CheckInterrupted();
if (has_started_ && (status_fetcher_->get() &&
@@ -307,20 +308,23 @@
status_fetcher_->get()->last_running == run_value_)) {
// It's currently running our instance.
has_started_ = true;
- LOG(DEBUG, "Action %" PRIx32 " on queue %s has been started\n",
- run_value_, goal_sender_->name());
+ AOS_LOG(DEBUG, "Action %" PRIx32 " on queue %s has been started\n",
+ run_value_, goal_sender_->name());
} else if (old_run_value_ != 0 &&
status_fetcher_->get()->running == old_run_value_) {
- LOG(DEBUG, "still running old instance %" PRIx32 "\n", old_run_value_);
+ AOS_LOG(DEBUG, "still running old instance %" PRIx32 "\n",
+ old_run_value_);
} else {
- LOG(WARNING, "Action %" PRIx32 " on queue %s interrupted by %" PRIx32
- " before starting\n",
- run_value_, goal_sender_->name(), status_fetcher_->get()->running);
+ AOS_LOG(WARNING,
+ "Action %" PRIx32 " on queue %s interrupted by %" PRIx32
+ " before starting\n",
+ run_value_, goal_sender_->name(),
+ status_fetcher_->get()->running);
has_started_ = true;
interrupted_ = true;
}
} else {
- LOG(WARNING, "No status message recieved.\n");
+ AOS_LOG(WARNING, "No status message recieved.\n");
}
}
@@ -329,9 +333,11 @@
if (!interrupted_ && has_started_ && status_fetcher_->get()) {
if (status_fetcher_->get()->running != 0 &&
status_fetcher_->get()->running != run_value_) {
- LOG(WARNING, "Action %" PRIx32 " on queue %s interrupted by %" PRIx32
- " after starting\n",
- run_value_, goal_sender_->name(), status_fetcher_->get()->running);
+ AOS_LOG(WARNING,
+ "Action %" PRIx32 " on queue %s interrupted by %" PRIx32
+ " after starting\n",
+ run_value_, goal_sender_->name(),
+ status_fetcher_->get()->running);
}
}
}
@@ -339,30 +345,30 @@
template <typename T>
void TypedAction<T>::DoStart() {
if (!sent_started_) {
- LOG(DEBUG, "Starting action %" PRIx32 "\n", run_value_);
+ AOS_LOG(DEBUG, "Starting action %" PRIx32 "\n", run_value_);
goal_->run = run_value_;
goal_->params = params_;
sent_started_ = true;
if (!goal_.Send()) {
- LOG(ERROR, "sending goal for action %" PRIx32 " on queue %s failed\n",
- run_value_, goal_sender_->name());
+ AOS_LOG(ERROR, "sending goal for action %" PRIx32 " on queue %s failed\n",
+ run_value_, goal_sender_->name());
// Don't wait to see a message with it.
has_started_ = true;
}
status_fetcher_->FetchNext();
if (status_fetcher_->get()) {
- LOG_STRUCT(DEBUG, "got status", *status_fetcher_->get());
+ AOS_LOG_STRUCT(DEBUG, "got status", *status_fetcher_->get());
}
if (status_fetcher_->get() && status_fetcher_->get()->running != 0) {
old_run_value_ = status_fetcher_->get()->running;
- LOG(INFO, "Action %" PRIx32 " on queue %s already running\n",
- old_run_value_, goal_sender_->name());
+ AOS_LOG(INFO, "Action %" PRIx32 " on queue %s already running\n",
+ old_run_value_, goal_sender_->name());
} else {
old_run_value_ = 0;
}
} else {
- LOG(WARNING, "Action %" PRIx32 " on queue %s already started\n", run_value_,
- goal_sender_->name());
+ AOS_LOG(WARNING, "Action %" PRIx32 " on queue %s already started\n",
+ run_value_, goal_sender_->name());
}
}
diff --git a/aos/actions/actor.h b/aos/actions/actor.h
index b55b336..a9b75e6 100644
--- a/aos/actions/actor.h
+++ b/aos/actions/actor.h
@@ -31,7 +31,7 @@
: event_loop_(event_loop),
status_sender_(event_loop->MakeSender<StatusType>(name + ".status")),
goal_fetcher_(event_loop->MakeFetcher<GoalType>(name + ".goal")) {
- LOG(INFO, "Constructing action %s\n", name.c_str());
+ AOS_LOG(INFO, "Constructing action %s\n", name.c_str());
event_loop->MakeWatcher(name + ".goal",
[this](const GoalType &goal) { HandleGoal(goal); });
@@ -43,7 +43,7 @@
status_message->last_running = 0;
status_message->success = !abort_;
if (!status_message.Send()) {
- LOG(ERROR, "Failed to send the status.\n");
+ AOS_LOG(ERROR, "Failed to send the status.\n");
}
});
}
@@ -118,7 +118,7 @@
template <class T>
void ActorBase<T>::HandleGoal(const GoalType &goal) {
- LOG_STRUCT(DEBUG, "action goal", goal);
+ AOS_LOG_STRUCT(DEBUG, "action goal", goal);
switch (state_) {
case State::WAITING_FOR_ACTION:
if (goal.run) {
@@ -129,7 +129,7 @@
status_message->last_running = 0;
status_message->success = !abort_;
if (!status_message.Send()) {
- LOG(ERROR, "Failed to send the status.\n");
+ AOS_LOG(ERROR, "Failed to send the status.\n");
}
break;
}
@@ -137,20 +137,20 @@
++running_count_;
const uint32_t running_id = goal.run;
current_id_ = running_id;
- LOG(INFO, "Starting action %" PRIx32 "\n", running_id);
+ AOS_LOG(INFO, "Starting action %" PRIx32 "\n", running_id);
{
auto status_message = status_sender_.MakeMessage();
status_message->running = running_id;
status_message->last_running = 0;
status_message->success = !abort_;
if (!status_message.Send()) {
- LOG(ERROR, "Failed to send the status.\n");
+ AOS_LOG(ERROR, "Failed to send the status.\n");
}
}
- LOG_STRUCT(INFO, "goal", goal);
+ AOS_LOG_STRUCT(INFO, "goal", goal);
abort_ = !RunAction(goal.params);
- LOG(INFO, "Done with action %" PRIx32 "\n", running_id);
+ AOS_LOG(INFO, "Done with action %" PRIx32 "\n", running_id);
current_id_ = 0u;
{
@@ -160,19 +160,19 @@
status_message->success = !abort_;
if (!status_message.Send()) {
- LOG(ERROR, "Failed to send the status.\n");
+ AOS_LOG(ERROR, "Failed to send the status.\n");
} else {
- LOG(INFO, "Sending Done status %" PRIx32 "\n", running_id);
+ AOS_LOG(INFO, "Sending Done status %" PRIx32 "\n", running_id);
}
}
state_ = State::WAITING_FOR_STOPPED;
- LOG(INFO, "Waiting for the action (%" PRIx32 ") to be stopped.\n",
- running_id);
+ AOS_LOG(INFO, "Waiting for the action (%" PRIx32 ") to be stopped.\n",
+ running_id);
} break;
case State::WAITING_FOR_STOPPED:
if (goal.run == 0) {
- LOG(INFO, "Action stopped.\n");
+ AOS_LOG(INFO, "Action stopped.\n");
state_ = State::WAITING_FOR_ACTION;
}
break;
@@ -194,7 +194,7 @@
}
if (end_time != ::aos::monotonic_clock::min_time &&
::aos::monotonic_clock::now() >= end_time) {
- LOG(DEBUG, "WaitUntil timed out\n");
+ AOS_LOG(DEBUG, "WaitUntil timed out\n");
return false;
}
phased_loop.SleepUntilNext();
@@ -211,11 +211,11 @@
template <class T>
bool ActorBase<T>::ShouldCancel() {
if (goal_fetcher_.Fetch()) {
- LOG_STRUCT(DEBUG, "goal queue", *goal_fetcher_);
+ AOS_LOG_STRUCT(DEBUG, "goal queue", *goal_fetcher_);
}
bool ans = !goal_fetcher_->run || goal_fetcher_->run != current_id_;
if (ans) {
- LOG(INFO, "Time to stop action\n");
+ AOS_LOG(INFO, "Time to stop action\n");
}
return ans;
}
diff --git a/aos/condition.cc b/aos/condition.cc
index 1e137b7..0c81e2c 100644
--- a/aos/condition.cc
+++ b/aos/condition.cc
@@ -28,7 +28,7 @@
const bool do_timeout = timeout != chrono::nanoseconds(0);
if (do_timeout) {
- PCHECK(clock_gettime(CLOCK_MONOTONIC, &end_time) == 0);
+ AOS_PCHECK(clock_gettime(CLOCK_MONOTONIC, &end_time) == 0);
timeout += chrono::nanoseconds(end_time.tv_nsec);
chrono::seconds timeout_seconds =
chrono::duration_cast<chrono::seconds>(timeout);
diff --git a/aos/condition_test.cc b/aos/condition_test.cc
index 602513e..1e8d06c 100644
--- a/aos/condition_test.cc
+++ b/aos/condition_test.cc
@@ -150,7 +150,7 @@
new (shared_) Shared();
}
~ConditionTestProcess() {
- CHECK_EQ(child_, -1);
+ AOS_CHECK_EQ(child_, -1);
}
void Start() {
@@ -162,7 +162,7 @@
Run();
exit(EXIT_SUCCESS);
} else { // in parent
- CHECK_NE(child_, -1);
+ AOS_CHECK_NE(child_, -1);
ASSERT_EQ(0, futex_wait(&shared_->ready));
@@ -189,7 +189,7 @@
return ::testing::AssertionSuccess() << "already been too long";
}
} else {
- CHECK_EQ(0, futex_wait(&shared_->done_delaying));
+ AOS_CHECK_EQ(0, futex_wait(&shared_->done_delaying));
}
::std::this_thread::sleep_for(chrono::milliseconds(10));
if (!shared_->finished) {
@@ -250,16 +250,16 @@
}
void Join() {
- CHECK_NE(child_, -1);
+ AOS_CHECK_NE(child_, -1);
int status;
do {
- CHECK_EQ(waitpid(child_, &status, 0), child_);
+ AOS_CHECK_EQ(waitpid(child_, &status, 0), child_);
} while (!(WIFEXITED(status) || WIFSIGNALED(status)));
child_ = -1;
}
void Kill() {
- CHECK_NE(child_, -1);
- PCHECK(kill(child_, SIGTERM));
+ AOS_CHECK_NE(child_, -1);
+ AOS_PCHECK(kill(child_, SIGTERM));
Join();
}
diff --git a/aos/controls/control_loop-tmpl.h b/aos/controls/control_loop-tmpl.h
index 4f48737..7628c26 100644
--- a/aos/controls/control_loop-tmpl.h
+++ b/aos/controls/control_loop-tmpl.h
@@ -28,26 +28,26 @@
no_sensor_state_.Print();
motors_off_log_.Print();
- LOG_STRUCT(DEBUG, "position", position);
+ AOS_LOG_STRUCT(DEBUG, "position", position);
// Fetch the latest control loop goal. If there is no new
// goal, we will just reuse the old one.
goal_fetcher_.Fetch();
const GoalType *goal = goal_fetcher_.get();
if (goal) {
- LOG_STRUCT(DEBUG, "goal", *goal);
+ AOS_LOG_STRUCT(DEBUG, "goal", *goal);
} else {
- LOG_INTERVAL(no_goal_);
+ AOS_LOG_INTERVAL(no_goal_);
}
const bool new_robot_state = robot_state_fetcher_.Fetch();
if (!robot_state_fetcher_.get()) {
- LOG_INTERVAL(no_sensor_state_);
+ AOS_LOG_INTERVAL(no_sensor_state_);
return;
}
if (sensor_reader_pid_ != robot_state_fetcher_->reader_pid) {
- LOG(INFO, "new sensor reader PID %" PRId32 ", old was %" PRId32 "\n",
- robot_state_fetcher_->reader_pid, sensor_reader_pid_);
+ AOS_LOG(INFO, "new sensor reader PID %" PRId32 ", old was %" PRId32 "\n",
+ robot_state_fetcher_->reader_pid, sensor_reader_pid_);
reset_ = true;
sensor_reader_pid_ = robot_state_fetcher_->reader_pid;
}
@@ -70,7 +70,7 @@
joystick_state_fetcher_.Fetch();
if (motors_off) {
if (joystick_state_fetcher_.get() && joystick_state_fetcher_->enabled) {
- LOG_INTERVAL(motors_off_log_);
+ AOS_LOG_INTERVAL(motors_off_log_);
}
outputs_enabled = false;
}
@@ -87,7 +87,7 @@
RunIteration(goal, &position, output.get(), status.get());
output->SetTimeToNow();
- LOG_STRUCT(DEBUG, "output", *output);
+ AOS_LOG_STRUCT(DEBUG, "output", *output);
output.Send();
} else {
// The outputs are disabled, so pass nullptr in for the output.
@@ -96,7 +96,7 @@
}
status->SetTimeToNow();
- LOG_STRUCT(DEBUG, "status", *status);
+ AOS_LOG_STRUCT(DEBUG, "status", *status);
status.Send();
}
diff --git a/aos/controls/control_loop_test.h b/aos/controls/control_loop_test.h
index 85d610e..ff11987 100644
--- a/aos/controls/control_loop_test.h
+++ b/aos/controls/control_loop_test.h
@@ -98,7 +98,7 @@
new_state->autonomous = false;
new_state->team_id = team_id_;
- LOG_STRUCT(INFO, "joystick_state", *new_state);
+ AOS_LOG_STRUCT(INFO, "joystick_state", *new_state);
new_state.Send();
last_ds_time_ = monotonic_now();
@@ -123,7 +123,7 @@
new_state->voltage_roborio_in = battery_voltage_;
new_state->voltage_battery = battery_voltage_;
- LOG_STRUCT(INFO, "robot_state", *new_state);
+ AOS_LOG_STRUCT(INFO, "robot_state", *new_state);
new_state.Send();
}
diff --git a/aos/controls/polytope.h b/aos/controls/polytope.h
index 145b904..5248ea3 100644
--- a/aos/controls/polytope.h
+++ b/aos/controls/polytope.h
@@ -191,9 +191,9 @@
if (error != dd_NoError || polyhedra == NULL) {
dd_WriteErrorMessages(stderr, error);
dd_FreeMatrix(matrix);
- LOG_MATRIX(ERROR, "bad H", H);
- LOG_MATRIX(ERROR, "bad k_", k);
- LOG(FATAL, "dd_DDMatrix2Poly failed\n");
+ AOS_LOG_MATRIX(ERROR, "bad H", H);
+ AOS_LOG_MATRIX(ERROR, "bad k_", k);
+ AOS_LOG(FATAL, "dd_DDMatrix2Poly failed\n");
}
dd_MatrixPtr vertex_matrix = dd_CopyGenerators(polyhedra);
@@ -209,7 +209,7 @@
}
// Rays are unsupported right now. This may change in the future.
- CHECK_EQ(0, num_rays);
+ AOS_CHECK_EQ(0, num_rays);
Eigen::Matrix<double, number_of_dimensions, Eigen::Dynamic> vertices(
number_of_dimensions, num_vertices);
diff --git a/aos/controls/replay_control_loop.h b/aos/controls/replay_control_loop.h
index 1626c0a..23593ab 100644
--- a/aos/controls/replay_control_loop.h
+++ b/aos/controls/replay_control_loop.h
@@ -74,7 +74,7 @@
CaptureMessage() {}
void operator()(const S &message) {
- CHECK(!have_new_message_);
+ AOS_CHECK(!have_new_message_);
saved_message_ = message;
have_new_message_ = true;
}
@@ -118,14 +118,14 @@
fd = open(filename, O_RDONLY);
}
if (fd == -1) {
- PLOG(FATAL, "couldn't open file '%s' for reading", filename);
+ AOS_PLOG(FATAL, "couldn't open file '%s' for reading", filename);
}
replayer_.OpenFile(fd);
DoProcessFile();
replayer_.CloseCurrentFile();
- PCHECK(close(fd));
+ AOS_PCHECK(close(fd));
}
template <class T>
@@ -140,7 +140,7 @@
// Send out the position message (after adjusting the time offset) so the
// loop will run right now.
if (!position_.have_new_message()) {
- LOG(WARNING, "don't have a new position this cycle -> skipping\n");
+ AOS_LOG(WARNING, "don't have a new position this cycle -> skipping\n");
status_.clear_new_message();
position_.clear_new_message();
output_.clear_new_message();
@@ -150,7 +150,7 @@
{
auto position_message = loop_group_->position.MakeMessage();
*position_message = position_.saved_message();
- CHECK(position_message.Send());
+ AOS_CHECK(position_message.Send());
}
position_.clear_new_message();
@@ -159,8 +159,8 @@
// Point out if the status is different.
if (!loop_group_->status->EqualsNoTime(status_.saved_message())) {
- LOG_STRUCT(WARNING, "expected status", status_.saved_message());
- LOG_STRUCT(WARNING, "got status", *loop_group_->status);
+ AOS_LOG_STRUCT(WARNING, "expected status", status_.saved_message());
+ AOS_LOG_STRUCT(WARNING, "got status", *loop_group_->status);
}
status_.clear_new_message();
@@ -169,17 +169,17 @@
bool loop_new_output = loop_group_->output.FetchLatest();
if (output_.have_new_message()) {
if (!loop_new_output) {
- LOG_STRUCT(WARNING, "no output, expected", output_.saved_message());
+ AOS_LOG_STRUCT(WARNING, "no output, expected", output_.saved_message());
} else if (!loop_group_->output->EqualsNoTime(output_.saved_message())) {
- LOG_STRUCT(WARNING, "expected output", output_.saved_message());
- LOG_STRUCT(WARNING, "got output", *loop_group_->output);
+ AOS_LOG_STRUCT(WARNING, "expected output", output_.saved_message());
+ AOS_LOG_STRUCT(WARNING, "got output", *loop_group_->output);
}
} else if (loop_new_output) {
if (zero_output_.have_new_message()) {
if (!loop_group_->output->EqualsNoTime(zero_output_.saved_message())) {
- LOG_STRUCT(WARNING, "expected null output",
- zero_output_.saved_message());
- LOG_STRUCT(WARNING, "got output", *loop_group_->output);
+ AOS_LOG_STRUCT(WARNING, "expected null output",
+ zero_output_.saved_message());
+ AOS_LOG_STRUCT(WARNING, "got output", *loop_group_->output);
}
} else {
zero_output_(*loop_group_->output);
diff --git a/aos/dump_rtprio.cc b/aos/dump_rtprio.cc
index 2b821cf..12000f0 100644
--- a/aos/dump_rtprio.cc
+++ b/aos/dump_rtprio.cc
@@ -55,17 +55,17 @@
int r;
FILE *pid_max_file = fopen("/proc/sys/kernel/pid_max", "r");
if (pid_max_file == nullptr) {
- PLOG(FATAL, "fopen(\"/proc/sys/kernel/pid_max\")");
+ AOS_PLOG(FATAL, "fopen(\"/proc/sys/kernel/pid_max\")");
}
- CHECK_EQ(1, fscanf(pid_max_file, "%d", &r));
- PCHECK(fclose(pid_max_file));
+ AOS_CHECK_EQ(1, fscanf(pid_max_file, "%d", &r));
+ AOS_PCHECK(fclose(pid_max_file));
return r;
}
cpu_set_t find_all_cpus() {
long nproc = sysconf(_SC_NPROCESSORS_CONF);
if (nproc == -1) {
- PLOG(FATAL, "sysconf(_SC_NPROCESSORS_CONF)");
+ AOS_PLOG(FATAL, "sysconf(_SC_NPROCESSORS_CONF)");
}
cpu_set_t r;
CPU_ZERO(&r);
@@ -83,7 +83,7 @@
return cpu_set_t();
}
if (result != 0) {
- PLOG(FATAL, "sched_getaffinity(%d, %zu, %p)", process, sizeof(r), &r);
+ AOS_PLOG(FATAL, "sched_getaffinity(%d, %zu, %p)", process, sizeof(r), &r);
}
return r;
}
@@ -96,7 +96,7 @@
return sched_param();
}
if (result != 0) {
- PLOG(FATAL, "sched_getparam(%d)", process);
+ AOS_PLOG(FATAL, "sched_getparam(%d)", process);
}
return r;
}
@@ -108,7 +108,7 @@
return 0;
}
if (scheduler == -1) {
- PLOG(FATAL, "sched_getscheduler(%d)", process);
+ AOS_PLOG(FATAL, "sched_getscheduler(%d)", process);
}
return scheduler;
}
@@ -126,8 +126,8 @@
return "";
}
if (exe_size == -1) {
- PLOG(FATAL, "readlink(%s, %p, %zu)", exe_filename.c_str(), exe_buffer,
- sizeof(exe_buffer));
+ AOS_PLOG(FATAL, "readlink(%s, %p, %zu)", exe_filename.c_str(), exe_buffer,
+ sizeof(exe_buffer));
}
return ::std::string(exe_buffer, exe_size);
}
@@ -141,7 +141,7 @@
return 0;
}
if (errno != 0) {
- PLOG(FATAL, "getpriority(PRIO_PROCESS, %d)", process);
+ AOS_PLOG(FATAL, "getpriority(PRIO_PROCESS, %d)", process);
}
return nice_value;
}
@@ -154,7 +154,7 @@
return;
}
if (stat == nullptr) {
- PLOG(FATAL, "fopen(%s, \"r\")", stat_filename.c_str());
+ AOS_PLOG(FATAL, "fopen(%s, \"r\")", stat_filename.c_str());
}
char buffer[2048];
@@ -164,7 +164,7 @@
*not_there = true;
return;
}
- PLOG(FATAL, "fgets(%p, %zu, %p)", buffer, sizeof(buffer), stat);
+ AOS_PLOG(FATAL, "fgets(%p, %zu, %p)", buffer, sizeof(buffer), stat);
}
}
@@ -197,12 +197,12 @@
field_start = i + 1;
}
}
- PCHECK(fclose(stat));
+ AOS_PCHECK(fclose(stat));
if (field < 4) {
- LOG(FATAL, "couldn't get fields from /proc/%d/stat\n", process);
+ AOS_LOG(FATAL, "couldn't get fields from /proc/%d/stat\n", process);
}
- CHECK_EQ(pid, process);
+ AOS_CHECK_EQ(pid, process);
}
void read_status(int process, int ppid, int *pgrp, ::std::string *name,
@@ -215,7 +215,7 @@
return;
}
if (status == nullptr) {
- PLOG(FATAL, "fopen(%s, \"r\")", status_filename.c_str());
+ AOS_PLOG(FATAL, "fopen(%s, \"r\")", status_filename.c_str());
}
int pid = 0, status_ppid = 0;
@@ -223,7 +223,7 @@
char buffer[1024];
if (fgets(buffer, sizeof(buffer), status) == nullptr) {
if (ferror(status)) {
- PLOG(FATAL, "fgets(%p, %zu, %p)", buffer, sizeof(buffer), status);
+ AOS_PLOG(FATAL, "fgets(%p, %zu, %p)", buffer, sizeof(buffer), status);
} else {
break;
}
@@ -239,9 +239,9 @@
*pgrp = ::std::stoi(strip_string_prefix(5, line));
}
}
- PCHECK(fclose(status));
- CHECK_EQ(pid, process);
- CHECK_EQ(status_ppid, ppid);
+ AOS_PCHECK(fclose(status));
+ AOS_CHECK_EQ(pid, process);
+ AOS_CHECK_EQ(status_ppid, ppid);
}
} // namespace
diff --git a/aos/event.cc b/aos/event.cc
index dd43dc8..a0115dc 100644
--- a/aos/event.cc
+++ b/aos/event.cc
@@ -16,8 +16,8 @@
while (__atomic_load_n(&impl_, __ATOMIC_SEQ_CST) == 0) {
const int ret = futex_wait(&impl_);
if (ret != 0) {
- CHECK_EQ(-1, ret);
- PLOG(FATAL, "futex_wait(%p) failed", &impl_);
+ AOS_CHECK_EQ(-1, ret);
+ AOS_PLOG(FATAL, "futex_wait(%p) failed", &impl_);
}
}
}
@@ -37,8 +37,8 @@
const int ret = futex_wait_timeout(&impl_, &timeout_timespec);
if (ret != 0) {
if (ret == 2) return false;
- CHECK_EQ(-1, ret);
- PLOG(FATAL, "futex_wait(%p) failed", &impl_);
+ AOS_CHECK_EQ(-1, ret);
+ AOS_PLOG(FATAL, "futex_wait(%p) failed", &impl_);
}
}
}
@@ -47,7 +47,7 @@
// to condition variable-based implementations.
void Event::Set() {
if (futex_set(&impl_) == -1) {
- PLOG(FATAL, "futex_set(%p) failed", &impl_);
+ AOS_PLOG(FATAL, "futex_set(%p) failed", &impl_);
}
}
diff --git a/aos/events/BUILD b/aos/events/BUILD
index ef033f8..b69fc66 100644
--- a/aos/events/BUILD
+++ b/aos/events/BUILD
@@ -4,8 +4,8 @@
hdrs = ["epoll.h"],
visibility = ["//visibility:public"],
deps = [
- "//aos/logging",
"//aos/time",
+ "@com_github_google_glog//:glog",
],
)
diff --git a/aos/events/epoll.cc b/aos/events/epoll.cc
index 83f44c3..3da04cf 100644
--- a/aos/events/epoll.cc
+++ b/aos/events/epoll.cc
@@ -7,8 +7,8 @@
#include <atomic>
#include <vector>
-#include "aos/logging/logging.h"
#include "aos/time/time.h"
+#include "glog/logging.h"
namespace aos {
namespace internal {
@@ -19,6 +19,8 @@
Disable();
}
+TimerFd::~TimerFd() { PCHECK(close(fd_) == 0); }
+
void TimerFd::SetTime(monotonic_clock::time_point start,
monotonic_clock::duration interval) {
struct itimerspec new_value;
@@ -56,7 +58,8 @@
DeleteFd(quit_epoll_fd_);
close(quit_signal_fd_);
close(quit_epoll_fd_);
- CHECK_EQ(fns_.size(), 0u);
+ CHECK_EQ(fns_.size(), 0u)
+ << ": Not all file descriptors were unregistered before shutting down.";
close(epoll_fd_);
}
@@ -96,14 +99,15 @@
struct epoll_event event;
event.events = EPOLLIN | EPOLLPRI;
event.data.ptr = event_data.get();
- PCHECK(epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, fd, &event) != 0);
+ PCHECK(epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, fd, &event) == 0)
+ << ": Failed to add fd " << fd;
fns_.push_back(::std::move(event_data));
}
// Removes fd from the event loop.
void EPoll::DeleteFd(int fd) {
auto element = fns_.begin();
- PCHECK(epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, fd, nullptr) != 0);
+ PCHECK(epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, fd, nullptr) == 0);
while (fns_.end() != element) {
if (element->get()->fd == fd) {
fns_.erase(element);
@@ -111,7 +115,7 @@
}
++element;
}
- LOG(FATAL, "fd %d not found\n", fd);
+ LOG(FATAL) << "fd " << fd << " not found";
}
} // namespace internal
diff --git a/aos/events/epoll.h b/aos/events/epoll.h
index 29311c9..f6ebe95 100644
--- a/aos/events/epoll.h
+++ b/aos/events/epoll.h
@@ -8,7 +8,6 @@
#include <atomic>
#include <vector>
-#include "aos/logging/logging.h"
#include "aos/time/time.h"
namespace aos {
@@ -18,7 +17,7 @@
class TimerFd {
public:
TimerFd();
- ~TimerFd() { PCHECK(close(fd_) == 0); }
+ ~TimerFd();
TimerFd(const TimerFd &) = delete;
TimerFd &operator=(const TimerFd &) = delete;
diff --git a/aos/events/event-loop_param_test.cc b/aos/events/event-loop_param_test.cc
index 1dcc258..04343cc 100644
--- a/aos/events/event-loop_param_test.cc
+++ b/aos/events/event-loop_param_test.cc
@@ -5,7 +5,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "aos/logging/queue_logging.h"
+#include "glog/logging.h"
namespace aos {
namespace testing {
@@ -564,7 +564,7 @@
[×, &loop1, this](int count) {
EXPECT_EQ(count, 1);
times.push_back(loop1->monotonic_now());
- LOG(INFO, "%zu\n", times.size());
+ LOG(INFO) << times.size();
if (times.size() == kCount) {
this->Exit();
}
diff --git a/aos/events/shm-event-loop.cc b/aos/events/shm-event-loop.cc
index 4984f59..5034f0b 100644
--- a/aos/events/shm-event-loop.cc
+++ b/aos/events/shm-event-loop.cc
@@ -128,7 +128,7 @@
// Try joining. If we fail, we weren't asleep on the condition in the
// queue. So hit it again and again until that's true.
struct timespec end_time;
- PCHECK(clock_gettime(CLOCK_REALTIME, &end_time) == 0);
+ AOS_PCHECK(clock_gettime(CLOCK_REALTIME, &end_time) == 0);
while (true) {
void *retval = nullptr;
end_time.tv_nsec += 100000000;
@@ -138,7 +138,7 @@
}
int ret = pthread_timedjoin_np(pthread_, &retval, &end_time);
if (ret == ETIMEDOUT) continue;
- PCHECK(ret == 0);
+ AOS_PCHECK(ret == 0);
break;
}
}
@@ -146,11 +146,11 @@
// Starts the thread and waits until it is running.
void Start() {
- PCHECK(pthread_create(&pthread_, nullptr, &StaticRun, this) == 0);
+ AOS_PCHECK(pthread_create(&pthread_, nullptr, &StaticRun, this) == 0);
IPCRecursiveMutexLocker locker(&thread_started_mutex_);
if (locker.owner_died()) ::aos::Die("Owner died");
while (!running_) {
- CHECK(!thread_started_condition_.Wait());
+ AOS_CHECK(!thread_started_condition_.Wait());
}
}
diff --git a/aos/events/shm-event-loop_test.cc b/aos/events/shm-event-loop_test.cc
index 8af00f0..e0d0b49 100644
--- a/aos/events/shm-event-loop_test.cc
+++ b/aos/events/shm-event-loop_test.cc
@@ -22,9 +22,9 @@
return ::std::move(loop);
}
- void Run() override { CHECK_NOTNULL(primary_event_loop_)->Run(); }
+ void Run() override { AOS_CHECK_NOTNULL(primary_event_loop_)->Run(); }
- void Exit() override { CHECK_NOTNULL(primary_event_loop_)->Exit(); }
+ void Exit() override { AOS_CHECK_NOTNULL(primary_event_loop_)->Exit(); }
void SleepFor(::std::chrono::nanoseconds duration) override {
::std::this_thread::sleep_for(duration);
@@ -61,9 +61,9 @@
bool IsRealtime() {
int scheduler;
if ((scheduler = sched_getscheduler(0)) == -1) {
- PLOG(FATAL, "sched_getscheduler(0) failed\n");
+ AOS_PLOG(FATAL, "sched_getscheduler(0) failed\n");
}
- LOG(INFO, "scheduler is %d\n", scheduler);
+ AOS_LOG(INFO, "scheduler is %d\n", scheduler);
return scheduler == SCHED_FIFO || scheduler == SCHED_RR;
}
diff --git a/aos/events/simulated-event-loop.h b/aos/events/simulated-event-loop.h
index 0828382..2fcc9d1 100644
--- a/aos/events/simulated-event-loop.h
+++ b/aos/events/simulated-event-loop.h
@@ -148,7 +148,7 @@
EventScheduler *scheduler)
: type_(type), name_(name), scheduler_(scheduler){};
- ~SimulatedQueue() { CHECK_EQ(0u, fetchers_.size()); }
+ ~SimulatedQueue() { AOS_CHECK_EQ(0u, fetchers_.size()); }
// Makes a connected raw sender which calls Send below.
::std::unique_ptr<RawSender> MakeRawSender(EventLoop *event_loop);
diff --git a/aos/init.cc b/aos/init.cc
index 8ce70ea..fdb1800 100644
--- a/aos/init.cc
+++ b/aos/init.cc
@@ -78,9 +78,9 @@
}
// Don't give freed memory back to the OS.
- CHECK_EQ(1, mallopt(M_TRIM_THRESHOLD, -1));
+ AOS_CHECK_EQ(1, mallopt(M_TRIM_THRESHOLD, -1));
// Don't use mmap for large malloc chunks.
- CHECK_EQ(1, mallopt(M_MMAP_MAX, 0));
+ AOS_CHECK_EQ(1, mallopt(M_MMAP_MAX, 0));
if (&FLAGS_tcmalloc_release_rate) {
// Tell tcmalloc not to return memory.
@@ -103,14 +103,14 @@
InitStart();
aos_core_create_shared_mem(false, for_realtime && ShouldBeRealtime());
logging::RegisterQueueImplementation();
- LOG(INFO, "%s initialized non-realtime\n", program_invocation_short_name);
+ AOS_LOG(INFO, "%s initialized non-realtime\n", program_invocation_short_name);
}
void InitCreate() {
InitStart();
aos_core_create_shared_mem(true, false);
logging::RegisterQueueImplementation();
- LOG(INFO, "%s created shm\n", program_invocation_short_name);
+ AOS_LOG(INFO, "%s created shm\n", program_invocation_short_name);
}
void Init(int relative_priority) {
@@ -148,7 +148,7 @@
printf("no realtime for %s. see stderr\n", program_invocation_short_name);
}
- LOG(INFO, "%s initialized realtime\n", program_invocation_short_name);
+ AOS_LOG(INFO, "%s initialized realtime\n", program_invocation_short_name);
}
void Cleanup() {
@@ -167,7 +167,7 @@
struct sched_param param;
param.sched_priority = priority;
if (sched_setscheduler(0, SCHED_FIFO, ¶m) == -1) {
- PLOG(FATAL, "sched_setscheduler(0, SCHED_FIFO, %d) failed\n", priority);
+ AOS_PLOG(FATAL, "sched_setscheduler(0, SCHED_FIFO, %d) failed\n", priority);
}
}
@@ -175,7 +175,7 @@
struct sched_param param;
param.sched_priority = 0;
if (sched_setscheduler(0, SCHED_OTHER, ¶m) == -1) {
- PLOG(FATAL, "sched_setscheduler(0, SCHED_OTHER, 0) failed\n");
+ AOS_PLOG(FATAL, "sched_setscheduler(0, SCHED_OTHER, 0) failed\n");
}
}
@@ -183,15 +183,15 @@
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(number, &cpuset);
- PRCHECK(pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset));
+ AOS_PRCHECK(pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset));
}
void SetCurrentThreadName(const ::std::string &name) {
if (name.size() > 16) {
- LOG(FATAL, "thread name '%s' too long\n", name.c_str());
+ AOS_LOG(FATAL, "thread name '%s' too long\n", name.c_str());
}
- LOG(INFO, "this thread is changing to '%s'\n", name.c_str());
- PCHECK(prctl(PR_SET_NAME, name.c_str()));
+ AOS_LOG(INFO, "this thread is changing to '%s'\n", name.c_str());
+ AOS_PCHECK(prctl(PR_SET_NAME, name.c_str()));
logging::internal::ReloadThreadName();
}
diff --git a/aos/input/action_joystick_input.cc b/aos/input/action_joystick_input.cc
index 4c3fef1..509f4c5 100644
--- a/aos/input/action_joystick_input.cc
+++ b/aos/input/action_joystick_input.cc
@@ -31,7 +31,7 @@
}
if (!data.GetControlBit(ControlBit::kEnabled)) {
action_queue_.CancelAllActions();
- LOG(DEBUG, "Canceling\n");
+ AOS_LOG(DEBUG, "Canceling\n");
}
drivetrain_input_reader_->HandleDrivetrain(data);
HandleTeleop(data);
@@ -48,14 +48,14 @@
}
void ActionJoystickInput::StartAuto() {
- LOG(INFO, "Starting auto mode\n");
+ AOS_LOG(INFO, "Starting auto mode\n");
action_queue_.EnqueueAction(
autonomous_action_factory_.Make(GetAutonomousMode()));
auto_action_running_ = true;
}
void ActionJoystickInput::StopAuto() {
- LOG(INFO, "Stopping auto mode\n");
+ AOS_LOG(INFO, "Stopping auto mode\n");
action_queue_.CancelAllActions();
auto_action_running_ = false;
AutoEnded();
diff --git a/aos/input/action_joystick_input.h b/aos/input/action_joystick_input.h
index 2536a8d..3057ace 100644
--- a/aos/input/action_joystick_input.h
+++ b/aos/input/action_joystick_input.h
@@ -96,7 +96,7 @@
virtual uint32_t GetAutonomousMode() {
autonomous_mode_fetcher_.Fetch();
if (autonomous_mode_fetcher_.get() == nullptr) {
- LOG(WARNING, "no auto mode values\n");
+ AOS_LOG(WARNING, "no auto mode values\n");
return 0;
}
return autonomous_mode_fetcher_->mode;
diff --git a/aos/input/drivetrain_input.cc b/aos/input/drivetrain_input.cc
index eddbdc5..a0bbf2c 100644
--- a/aos/input/drivetrain_input.cc
+++ b/aos/input/drivetrain_input.cc
@@ -100,7 +100,7 @@
new_drivetrain_goal->linear.max_acceleration = 20.0;
if (!new_drivetrain_goal.Send()) {
- LOG(WARNING, "sending stick values failed\n");
+ AOS_LOG(WARNING, "sending stick values failed\n");
}
last_is_control_loop_driving_ = is_control_loop_driving;
diff --git a/aos/input/joystick_input.cc b/aos/input/joystick_input.cc
index 0bbba41..d1bd302 100644
--- a/aos/input/joystick_input.cc
+++ b/aos/input/joystick_input.cc
@@ -24,37 +24,37 @@
for (int button = 1; button <= ButtonLocation::kButtons; ++button) {
ButtonLocation location(joystick, button);
if (data_.PosEdge(location)) {
- LOG(INFO, "PosEdge(%d, %d)\n", joystick, button);
+ AOS_LOG(INFO, "PosEdge(%d, %d)\n", joystick, button);
}
if (data_.NegEdge(location)) {
- LOG(INFO, "NegEdge(%d, %d)\n", joystick, button);
+ AOS_LOG(INFO, "NegEdge(%d, %d)\n", joystick, button);
}
}
if (data_.GetPOV(joystick) != data_.GetOldPOV(joystick)) {
- LOG(INFO, "POV %d %d->%d\n", joystick, data_.GetOldPOV(joystick),
- data_.GetPOV(joystick));
+ AOS_LOG(INFO, "POV %d %d->%d\n", joystick, data_.GetOldPOV(joystick),
+ data_.GetPOV(joystick));
}
}
}
{
using driver_station::ControlBit;
if (data_.PosEdge(ControlBit::kFmsAttached)) {
- LOG(INFO, "PosEdge(kFmsAttached)\n");
+ AOS_LOG(INFO, "PosEdge(kFmsAttached)\n");
}
if (data_.NegEdge(ControlBit::kFmsAttached)) {
- LOG(INFO, "NegEdge(kFmsAttached)\n");
+ AOS_LOG(INFO, "NegEdge(kFmsAttached)\n");
}
if (data_.PosEdge(ControlBit::kAutonomous)) {
- LOG(INFO, "PosEdge(kAutonomous)\n");
+ AOS_LOG(INFO, "PosEdge(kAutonomous)\n");
}
if (data_.NegEdge(ControlBit::kAutonomous)) {
- LOG(INFO, "NegEdge(kAutonomous)\n");
+ AOS_LOG(INFO, "NegEdge(kAutonomous)\n");
}
if (data_.PosEdge(ControlBit::kEnabled)) {
- LOG(INFO, "PosEdge(kEnabled)\n");
+ AOS_LOG(INFO, "PosEdge(kEnabled)\n");
}
if (data_.NegEdge(ControlBit::kEnabled)) {
- LOG(INFO, "NegEdge(kEnabled)\n");
+ AOS_LOG(INFO, "NegEdge(kEnabled)\n");
}
}
diff --git a/aos/ipc_lib/BUILD b/aos/ipc_lib/BUILD
index 76c5324..1e8b118 100644
--- a/aos/ipc_lib/BUILD
+++ b/aos/ipc_lib/BUILD
@@ -192,6 +192,7 @@
"//aos/logging",
"//aos/time",
"//aos/util:compiler_memory_barrier",
+ "@com_github_google_glog//:glog",
],
)
diff --git a/aos/ipc_lib/aos_sync.cc b/aos/ipc_lib/aos_sync.cc
index 572b864..101a189 100644
--- a/aos/ipc_lib/aos_sync.cc
+++ b/aos/ipc_lib/aos_sync.cc
@@ -354,16 +354,16 @@
return r;
}
-// This gets called by functions before LOG(FATAL)ing with error messages that
-// would be incorrect if the error was caused by a process forking without
+// This gets called by functions before AOS_LOG(FATAL)ing with error messages
+// that would be incorrect if the error was caused by a process forking without
// initialize_in_new_thread getting called in the fork.
void check_cached_tid(pid_t tid) {
pid_t actual = do_get_tid();
if (tid != actual) {
- LOG(FATAL,
- "task %jd forked into %jd without letting aos_sync know"
- " so we're not really sure what's going on\n",
- static_cast<intmax_t>(tid), static_cast<intmax_t>(actual));
+ AOS_LOG(FATAL,
+ "task %jd forked into %jd without letting aos_sync know"
+ " so we're not really sure what's going on\n",
+ static_cast<intmax_t>(tid), static_cast<intmax_t>(actual));
}
}
@@ -379,7 +379,7 @@
void *InstallAtforkHook() {
if (pthread_atfork(NULL, NULL, atfork_child) != 0) {
- PLOG(FATAL, "pthread_atfork(NULL, NULL, %p) failed", atfork_child);
+ AOS_PLOG(FATAL, "pthread_atfork(NULL, NULL, %p) failed", atfork_child);
}
return nullptr;
}
@@ -475,8 +475,8 @@
robust_head.pending_next = 0;
if (syscall(SYS_set_robust_list, robust_head_next_value(), sizeof(robust_head)) !=
0) {
- PLOG(FATAL, "set_robust_list(%p, %zd) failed",
- reinterpret_cast<void *>(robust_head.next), sizeof(robust_head));
+ AOS_PLOG(FATAL, "set_robust_list(%p, %zd) failed",
+ reinterpret_cast<void *>(robust_head.next), sizeof(robust_head));
}
if (kRobustListDebug) {
printf("%" PRId32 ": init done\n", get_tid());
@@ -677,10 +677,11 @@
}
my_robust_list::robust_head.pending_next = 0;
if (ret == -EDEADLK) {
- LOG(FATAL, "multiple lock of %p by %" PRId32 "\n", m, tid);
+ AOS_LOG(FATAL, "multiple lock of %p by %" PRId32 "\n", m, tid);
}
- PELOG(FATAL, -ret, "FUTEX_LOCK_PI(%p(=%" PRIu32 "), 1, %p) failed",
- &m->futex, __atomic_load_n(&m->futex, __ATOMIC_SEQ_CST), timeout);
+ AOS_PELOG(FATAL, -ret, "FUTEX_LOCK_PI(%p(=%" PRIu32 "), 1, %p) failed",
+ &m->futex, __atomic_load_n(&m->futex, __ATOMIC_SEQ_CST),
+ timeout);
} else {
if (kLockDebug) {
printf("%" PRId32 ": %p kernel lock done\n", tid, m);
@@ -746,8 +747,8 @@
continue;
}
my_robust_list::robust_head.pending_next = 0;
- PELOG(FATAL, -ret, "FUTEX_CMP_REQUEUE_PI(%p, 1, %d, %p, *%p) failed", c,
- number_requeue, &m->futex, c);
+ AOS_PELOG(FATAL, -ret, "FUTEX_CMP_REQUEUE_PI(%p, 1, %d, %p, *%p) failed",
+ c, number_requeue, &m->futex, c);
} else {
return;
}
@@ -778,10 +779,11 @@
my_robust_list::robust_head.pending_next = 0;
check_cached_tid(tid);
if ((value & FUTEX_TID_MASK) == 0) {
- LOG(FATAL, "multiple unlock of aos_mutex %p by %" PRId32 "\n", m, tid);
+ AOS_LOG(FATAL, "multiple unlock of aos_mutex %p by %" PRId32 "\n", m,
+ tid);
} else {
- LOG(FATAL, "aos_mutex %p is locked by %" PRId32 ", not %" PRId32 "\n",
- m, value & FUTEX_TID_MASK, tid);
+ AOS_LOG(FATAL, "aos_mutex %p is locked by %" PRId32 ", not %" PRId32 "\n",
+ m, value & FUTEX_TID_MASK, tid);
}
}
@@ -794,7 +796,7 @@
const int ret = sys_futex_unlock_pi(&m->futex);
if (ret != 0) {
my_robust_list::robust_head.pending_next = 0;
- PELOG(FATAL, -ret, "FUTEX_UNLOCK_PI(%p) failed", &m->futex);
+ AOS_PELOG(FATAL, -ret, "FUTEX_UNLOCK_PI(%p) failed", &m->futex);
}
} else {
// There aren't any waiters, so no need to call into the kernel.
@@ -831,7 +833,8 @@
return 4;
}
my_robust_list::robust_head.pending_next = 0;
- PELOG(FATAL, -ret, "FUTEX_TRYLOCK_PI(%p, 0, NULL) failed", &m->futex);
+ AOS_PELOG(FATAL, -ret, "FUTEX_TRYLOCK_PI(%p, 0, NULL) failed",
+ &m->futex);
}
}
}
@@ -896,8 +899,9 @@
continue;
}
my_robust_list::robust_head.pending_next = 0;
- PELOG(FATAL, -ret, "FUTEX_WAIT_REQUEUE_PI(%p, %" PRIu32 ", %p) failed", c,
- wait_start, &m->futex);
+ AOS_PELOG(FATAL, -ret,
+ "FUTEX_WAIT_REQUEUE_PI(%p, %" PRIu32 ", %p) failed", c,
+ wait_start, &m->futex);
} else {
// Record that the kernel relocked it for us.
lock_pthread_mutex(m);
diff --git a/aos/ipc_lib/ipc_comparison.cc b/aos/ipc_lib/ipc_comparison.cc
index 2c73397..5ea1c8b 100644
--- a/aos/ipc_lib/ipc_comparison.cc
+++ b/aos/ipc_lib/ipc_comparison.cc
@@ -131,8 +131,8 @@
size_t remaining = sizeof(*data);
uint8_t *current = &(*data)[0];
while (remaining > 0) {
- const ssize_t result = PCHECK(read(fd, current, remaining));
- CHECK_LE(static_cast<size_t>(result), remaining);
+ const ssize_t result = AOS_PCHECK(read(fd, current, remaining));
+ AOS_CHECK_LE(static_cast<size_t>(result), remaining);
remaining -= result;
current += result;
}
@@ -142,8 +142,8 @@
size_t remaining = sizeof(data);
const uint8_t *current = &data[0];
while (remaining > 0) {
- const ssize_t result = PCHECK(write(fd, current, remaining));
- CHECK_LE(static_cast<size_t>(result), remaining);
+ const ssize_t result = AOS_PCHECK(write(fd, current, remaining));
+ AOS_CHECK_LE(static_cast<size_t>(result), remaining);
remaining -= result;
current += result;
}
@@ -157,15 +157,15 @@
class PipePingPonger : public FDPingPonger {
public:
PipePingPonger() {
- PCHECK(pipe(to_server));
- PCHECK(pipe(from_server));
+ AOS_PCHECK(pipe(to_server));
+ AOS_PCHECK(pipe(from_server));
Init(to_server[0], from_server[1], from_server[0], to_server[1]);
}
~PipePingPonger() {
- PCHECK(close(to_server[0]));
- PCHECK(close(to_server[1]));
- PCHECK(close(from_server[0]));
- PCHECK(close(from_server[1]));
+ AOS_PCHECK(close(to_server[0]));
+ AOS_PCHECK(close(to_server[1]));
+ AOS_PCHECK(close(from_server[0]));
+ AOS_PCHECK(close(from_server[1]));
}
private:
@@ -181,10 +181,10 @@
Init(server_read_, server_write_, client_read_, client_write_);
}
~NamedPipePingPonger() {
- PCHECK(close(server_read_));
- PCHECK(close(client_write_));
- PCHECK(close(client_read_));
- PCHECK(close(server_write_));
+ AOS_PCHECK(close(server_read_));
+ AOS_PCHECK(close(client_write_));
+ AOS_PCHECK(close(client_read_));
+ AOS_PCHECK(close(server_write_));
}
private:
@@ -192,15 +192,15 @@
{
const int ret = unlink(name);
if (ret == -1 && errno != ENOENT) {
- PLOG(FATAL, "unlink(%s)", name);
+ AOS_PLOG(FATAL, "unlink(%s)", name);
}
- PCHECK(mkfifo(name, S_IWUSR | S_IRUSR));
+ AOS_PCHECK(mkfifo(name, S_IWUSR | S_IRUSR));
// Have to open it nonblocking because the other end isn't open yet...
- *read = PCHECK(open(name, O_RDONLY | O_NONBLOCK));
- *write = PCHECK(open(name, O_WRONLY));
+ *read = AOS_PCHECK(open(name, O_RDONLY | O_NONBLOCK));
+ *write = AOS_PCHECK(open(name, O_WRONLY));
{
- const int flags = PCHECK(fcntl(*read, F_GETFL));
- PCHECK(fcntl(*read, F_SETFL, flags & ~O_NONBLOCK));
+ const int flags = AOS_PCHECK(fcntl(*read, F_GETFL));
+ AOS_PCHECK(fcntl(*read, F_SETFL, flags & ~O_NONBLOCK));
}
}
}
@@ -211,15 +211,15 @@
class UnixPingPonger : public FDPingPonger {
public:
UnixPingPonger(int type) {
- PCHECK(socketpair(AF_UNIX, type, 0, to_server));
- PCHECK(socketpair(AF_UNIX, type, 0, from_server));
+ AOS_PCHECK(socketpair(AF_UNIX, type, 0, to_server));
+ AOS_PCHECK(socketpair(AF_UNIX, type, 0, from_server));
Init(to_server[0], from_server[1], from_server[0], to_server[1]);
}
~UnixPingPonger() {
- PCHECK(close(to_server[0]));
- PCHECK(close(to_server[1]));
- PCHECK(close(from_server[0]));
- PCHECK(close(from_server[1]));
+ AOS_PCHECK(close(to_server[0]));
+ AOS_PCHECK(close(to_server[1]));
+ AOS_PCHECK(close(from_server[0]));
+ AOS_PCHECK(close(from_server[1]));
}
private:
@@ -229,42 +229,44 @@
class TCPPingPonger : public FDPingPonger {
public:
TCPPingPonger(bool nodelay) {
- server_ = PCHECK(socket(AF_INET, SOCK_STREAM, 0));
+ server_ = AOS_PCHECK(socket(AF_INET, SOCK_STREAM, 0));
if (nodelay) {
const int yes = 1;
- PCHECK(setsockopt(server_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
+ AOS_PCHECK(
+ setsockopt(server_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
}
{
sockaddr_in server_address;
memset(&server_address, 0, sizeof(server_address));
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- PCHECK(bind(server_, reinterpret_cast<sockaddr *>(&server_address),
- sizeof(server_address)));
+ AOS_PCHECK(bind(server_, reinterpret_cast<sockaddr *>(&server_address),
+ sizeof(server_address)));
}
- PCHECK(listen(server_, 1));
+ AOS_PCHECK(listen(server_, 1));
- client_ = PCHECK(socket(AF_INET, SOCK_STREAM, 0));
+ client_ = AOS_PCHECK(socket(AF_INET, SOCK_STREAM, 0));
if (nodelay) {
const int yes = 1;
- PCHECK(setsockopt(client_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
+ AOS_PCHECK(
+ setsockopt(client_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
}
{
sockaddr_in client_address;
unsigned int length = sizeof(client_address);
- PCHECK(getsockname(server_, reinterpret_cast<sockaddr *>(&client_address),
- &length));
- PCHECK(connect(client_, reinterpret_cast<sockaddr *>(&client_address),
- length));
+ AOS_PCHECK(getsockname(
+ server_, reinterpret_cast<sockaddr *>(&client_address), &length));
+ AOS_PCHECK(connect(client_, reinterpret_cast<sockaddr *>(&client_address),
+ length));
}
- server_connection_ = PCHECK(accept(server_, nullptr, 0));
+ server_connection_ = AOS_PCHECK(accept(server_, nullptr, 0));
Init(server_connection_, server_connection_, client_, client_);
}
~TCPPingPonger() {
- PCHECK(close(client_));
- PCHECK(close(server_connection_));
- PCHECK(close(server_));
+ AOS_PCHECK(close(client_));
+ AOS_PCHECK(close(server_connection_));
+ AOS_PCHECK(close(server_));
}
private:
@@ -280,32 +282,32 @@
Init(server_read_, server_write_, client_read_, client_write_);
}
~UDPPingPonger() {
- PCHECK(close(server_read_));
- PCHECK(close(client_write_));
- PCHECK(close(client_read_));
- PCHECK(close(server_write_));
+ AOS_PCHECK(close(server_read_));
+ AOS_PCHECK(close(client_write_));
+ AOS_PCHECK(close(client_read_));
+ AOS_PCHECK(close(server_write_));
}
private:
void CreatePair(int *server, int *client) {
- *server = PCHECK(socket(AF_INET, SOCK_DGRAM, 0));
+ *server = AOS_PCHECK(socket(AF_INET, SOCK_DGRAM, 0));
{
sockaddr_in server_address;
memset(&server_address, 0, sizeof(server_address));
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
// server_address.sin_port = htons(server_ + 3000);
- PCHECK(bind(*server, reinterpret_cast<sockaddr *>(&server_address),
- sizeof(server_address)));
+ AOS_PCHECK(bind(*server, reinterpret_cast<sockaddr *>(&server_address),
+ sizeof(server_address)));
}
- *client = PCHECK(socket(AF_INET, SOCK_DGRAM, 0));
+ *client = AOS_PCHECK(socket(AF_INET, SOCK_DGRAM, 0));
{
sockaddr_in client_address;
unsigned int length = sizeof(client_address);
- PCHECK(getsockname(*server, reinterpret_cast<sockaddr *>(&client_address),
- &length));
- PCHECK(connect(*client, reinterpret_cast<sockaddr *>(&client_address),
- length));
+ AOS_PCHECK(getsockname(
+ *server, reinterpret_cast<sockaddr *>(&client_address), &length));
+ AOS_PCHECK(connect(*client, reinterpret_cast<sockaddr *>(&client_address),
+ length));
}
}
@@ -442,9 +444,9 @@
AOSConditionVariable() : condition_(&mutex_) {}
private:
- void Lock() override { CHECK(!mutex_.Lock()); }
+ void Lock() override { AOS_CHECK(!mutex_.Lock()); }
void Unlock() override { mutex_.Unlock(); }
- void Wait() override { CHECK(!condition_.Wait()); }
+ void Wait() override { AOS_CHECK(!condition_.Wait()); }
void Signal() override { condition_.Broadcast(); }
Mutex mutex_;
@@ -487,40 +489,42 @@
PthreadConditionVariable(bool pshared, bool pi) {
{
pthread_condattr_t cond_attr;
- PRCHECK(pthread_condattr_init(&cond_attr));
+ AOS_PRCHECK(pthread_condattr_init(&cond_attr));
if (pshared) {
- PRCHECK(
+ AOS_PRCHECK(
pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED));
}
- PRCHECK(pthread_cond_init(&condition_, &cond_attr));
- PRCHECK(pthread_condattr_destroy(&cond_attr));
+ AOS_PRCHECK(pthread_cond_init(&condition_, &cond_attr));
+ AOS_PRCHECK(pthread_condattr_destroy(&cond_attr));
}
{
pthread_mutexattr_t mutex_attr;
- PRCHECK(pthread_mutexattr_init(&mutex_attr));
+ AOS_PRCHECK(pthread_mutexattr_init(&mutex_attr));
if (pshared) {
- PRCHECK(pthread_mutexattr_setpshared(&mutex_attr,
- PTHREAD_PROCESS_SHARED));
+ AOS_PRCHECK(pthread_mutexattr_setpshared(&mutex_attr,
+ PTHREAD_PROCESS_SHARED));
}
if (pi) {
- PRCHECK(
+ AOS_PRCHECK(
pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT));
}
- PRCHECK(pthread_mutex_init(&mutex_, nullptr));
- PRCHECK(pthread_mutexattr_destroy(&mutex_attr));
+ AOS_PRCHECK(pthread_mutex_init(&mutex_, nullptr));
+ AOS_PRCHECK(pthread_mutexattr_destroy(&mutex_attr));
}
}
~PthreadConditionVariable() {
- PRCHECK(pthread_mutex_destroy(&mutex_));
- PRCHECK(pthread_cond_destroy(&condition_));
+ AOS_PRCHECK(pthread_mutex_destroy(&mutex_));
+ AOS_PRCHECK(pthread_cond_destroy(&condition_));
}
private:
- void Lock() override { PRCHECK(pthread_mutex_lock(&mutex_)); }
- void Unlock() override { PRCHECK(pthread_mutex_unlock(&mutex_)); }
- void Wait() override { PRCHECK(pthread_cond_wait(&condition_, &mutex_)); }
- void Signal() override { PRCHECK(pthread_cond_broadcast(&condition_)); }
+ void Lock() override { AOS_PRCHECK(pthread_mutex_lock(&mutex_)); }
+ void Unlock() override { AOS_PRCHECK(pthread_mutex_unlock(&mutex_)); }
+ void Wait() override {
+ AOS_PRCHECK(pthread_cond_wait(&condition_, &mutex_));
+ }
+ void Signal() override { AOS_PRCHECK(pthread_cond_broadcast(&condition_)); }
pthread_cond_t condition_;
pthread_mutex_t mutex_;
@@ -537,21 +541,21 @@
private:
class EventFDSemaphore : public SemaphoreInterface {
public:
- EventFDSemaphore() : fd_(PCHECK(eventfd(0, 0))) {}
- ~EventFDSemaphore() { PCHECK(close(fd_)); }
+ EventFDSemaphore() : fd_(AOS_PCHECK(eventfd(0, 0))) {}
+ ~EventFDSemaphore() { AOS_PCHECK(close(fd_)); }
private:
void Get() override {
uint64_t value;
if (read(fd_, &value, sizeof(value)) != sizeof(value)) {
- PLOG(FATAL, "reading from eventfd %d failed\n", fd_);
+ AOS_PLOG(FATAL, "reading from eventfd %d failed\n", fd_);
}
- CHECK_EQ(1u, value);
+ AOS_CHECK_EQ(1u, value);
}
void Put() override {
uint64_t value = 1;
if (write(fd_, &value, sizeof(value)) != sizeof(value)) {
- PLOG(FATAL, "writing to eventfd %d failed\n", fd_);
+ AOS_PLOG(FATAL, "writing to eventfd %d failed\n", fd_);
}
}
@@ -569,7 +573,7 @@
private:
class SysvSemaphore : public SemaphoreInterface {
public:
- SysvSemaphore() : sem_id_(PCHECK(semget(IPC_PRIVATE, 1, 0600))) {}
+ SysvSemaphore() : sem_id_(AOS_PCHECK(semget(IPC_PRIVATE, 1, 0600))) {}
private:
void Get() override {
@@ -577,14 +581,14 @@
op.sem_num = 0;
op.sem_op = -1;
op.sem_flg = 0;
- PCHECK(semop(sem_id_, &op, 1));
+ AOS_PCHECK(semop(sem_id_, &op, 1));
}
void Put() override {
struct sembuf op;
op.sem_num = 0;
op.sem_op = 1;
op.sem_flg = 0;
- PCHECK(semop(sem_id_, &op, 1));
+ AOS_PCHECK(semop(sem_id_, &op, 1));
}
const int sem_id_;
@@ -605,8 +609,8 @@
PosixSemaphore(sem_t *sem) : sem_(sem) {}
private:
- void Get() override { PCHECK(sem_wait(sem_)); }
- void Put() override { PCHECK(sem_post(sem_)); }
+ void Get() override { AOS_PCHECK(sem_wait(sem_)); }
+ void Put() override { AOS_PCHECK(sem_post(sem_)); }
sem_t *const sem_;
};
@@ -615,18 +619,18 @@
class SysvQueuePingPonger : public StaticPingPonger {
public:
SysvQueuePingPonger()
- : ping_(PCHECK(msgget(IPC_PRIVATE, 0600))),
- pong_(PCHECK(msgget(IPC_PRIVATE, 0600))) {}
+ : ping_(AOS_PCHECK(msgget(IPC_PRIVATE, 0600))),
+ pong_(AOS_PCHECK(msgget(IPC_PRIVATE, 0600))) {}
const Data *Ping() override {
{
Message to_send;
memcpy(&to_send.data, PingData(), sizeof(Data));
- PCHECK(msgsnd(ping_, &to_send, sizeof(Data), 0));
+ AOS_PCHECK(msgsnd(ping_, &to_send, sizeof(Data), 0));
}
{
Message received;
- PCHECK(msgrcv(pong_, &received, sizeof(Data), 1, 0));
+ AOS_PCHECK(msgrcv(pong_, &received, sizeof(Data), 1, 0));
memcpy(&pong_received_, &received.data, sizeof(Data));
}
return &pong_received_;
@@ -635,7 +639,7 @@
const Data *Wait() override {
{
Message received;
- PCHECK(msgrcv(ping_, &received, sizeof(Data), 1, 0));
+ AOS_PCHECK(msgrcv(ping_, &received, sizeof(Data), 1, 0));
memcpy(&ping_received_, &received.data, sizeof(Data));
}
return &ping_received_;
@@ -644,7 +648,7 @@
virtual void Pong() override {
Message to_send;
memcpy(&to_send.data, PongData(), sizeof(Data));
- PCHECK(msgsnd(pong_, &to_send, sizeof(Data), 0));
+ AOS_PCHECK(msgsnd(pong_, &to_send, sizeof(Data), 0));
}
private:
@@ -662,35 +666,37 @@
public:
PosixQueuePingPonger() : ping_(Open("/ping")), pong_(Open("/pong")) {}
~PosixQueuePingPonger() {
- PCHECK(mq_close(ping_));
- PCHECK(mq_close(pong_));
+ AOS_PCHECK(mq_close(ping_));
+ AOS_PCHECK(mq_close(pong_));
}
const Data *Ping() override {
- PCHECK(mq_send(ping_, static_cast<char *>(static_cast<void *>(PingData())),
- sizeof(Data), 1));
- PCHECK(mq_receive(pong_,
- static_cast<char *>(static_cast<void *>(&pong_received_)),
- sizeof(Data), nullptr));
+ AOS_PCHECK(mq_send(ping_,
+ static_cast<char *>(static_cast<void *>(PingData())),
+ sizeof(Data), 1));
+ AOS_PCHECK(mq_receive(
+ pong_, static_cast<char *>(static_cast<void *>(&pong_received_)),
+ sizeof(Data), nullptr));
return &pong_received_;
}
const Data *Wait() override {
- PCHECK(mq_receive(ping_,
- static_cast<char *>(static_cast<void *>(&ping_received_)),
- sizeof(Data), nullptr));
+ AOS_PCHECK(mq_receive(
+ ping_, static_cast<char *>(static_cast<void *>(&ping_received_)),
+ sizeof(Data), nullptr));
return &ping_received_;
}
virtual void Pong() override {
- PCHECK(mq_send(pong_, static_cast<char *>(static_cast<void *>(PongData())),
- sizeof(Data), 1));
+ AOS_PCHECK(mq_send(pong_,
+ static_cast<char *>(static_cast<void *>(PongData())),
+ sizeof(Data), 1));
}
private:
mqd_t Open(const char *name) {
if (mq_unlink(name) == -1 && errno != ENOENT) {
- PLOG(FATAL, "mq_unlink(%s) failed", name);
+ AOS_PLOG(FATAL, "mq_unlink(%s) failed", name);
}
struct mq_attr attr;
attr.mq_flags = 0;
@@ -699,7 +705,7 @@
attr.mq_curmsgs = 0;
const mqd_t r = mq_open(name, O_CREAT | O_RDWR | O_EXCL, 0600, &attr);
if (r == reinterpret_cast<mqd_t>(-1)) {
- PLOG(FATAL, "mq_open(%s, O_CREAT | O_RDWR | O_EXCL) failed", name);
+ AOS_PLOG(FATAL, "mq_open(%s, O_CREAT | O_RDWR | O_EXCL) failed", name);
}
return r;
}
@@ -712,12 +718,12 @@
public:
PosixUnnamedSemaphorePingPonger(int pshared)
: PosixSemaphorePingPonger(&ping_sem_, &pong_sem_) {
- PCHECK(sem_init(&ping_sem_, pshared, 0));
- PCHECK(sem_init(&pong_sem_, pshared, 0));
+ AOS_PCHECK(sem_init(&ping_sem_, pshared, 0));
+ AOS_PCHECK(sem_init(&pong_sem_, pshared, 0));
}
~PosixUnnamedSemaphorePingPonger() {
- PCHECK(sem_destroy(&ping_sem_));
- PCHECK(sem_destroy(&pong_sem_));
+ AOS_PCHECK(sem_destroy(&ping_sem_));
+ AOS_PCHECK(sem_destroy(&pong_sem_));
}
private:
@@ -730,18 +736,18 @@
: PosixSemaphorePingPonger(ping_sem_ = Open("/ping"),
pong_sem_ = Open("/pong")) {}
~PosixNamedSemaphorePingPonger() {
- PCHECK(sem_close(ping_sem_));
- PCHECK(sem_close(pong_sem_));
+ AOS_PCHECK(sem_close(ping_sem_));
+ AOS_PCHECK(sem_close(pong_sem_));
}
private:
sem_t *Open(const char *name) {
if (sem_unlink(name) == -1 && errno != ENOENT) {
- PLOG(FATAL, "shm_unlink(%s) failed", name);
+ AOS_PLOG(FATAL, "shm_unlink(%s) failed", name);
}
sem_t *const r = sem_open(name, O_CREAT | O_RDWR | O_EXCL, 0600, 0);
if (r == SEM_FAILED) {
- PLOG(FATAL, "sem_open(%s, O_CREAT | O_RDWR | O_EXCL) failed", name);
+ AOS_PLOG(FATAL, "sem_open(%s, O_CREAT | O_RDWR | O_EXCL) failed", name);
}
return r;
}
@@ -756,14 +762,14 @@
pong_queue_(RawQueue::Fetch("pong", sizeof(Data), 0, 1)) {}
Data *PingData() override {
- CHECK_EQ(nullptr, ping_to_send_);
+ AOS_CHECK_EQ(nullptr, ping_to_send_);
ping_to_send_ = static_cast<Data *>(ping_queue_->GetMessage());
return ping_to_send_;
}
const Data *Ping() override {
- CHECK_NE(nullptr, ping_to_send_);
- CHECK(ping_queue_->WriteMessage(ping_to_send_, RawQueue::kBlock));
+ AOS_CHECK_NE(nullptr, ping_to_send_);
+ AOS_CHECK(ping_queue_->WriteMessage(ping_to_send_, RawQueue::kBlock));
ping_to_send_ = nullptr;
pong_queue_->FreeMessage(pong_received_);
pong_received_ =
@@ -779,14 +785,14 @@
}
Data *PongData() override {
- CHECK_EQ(nullptr, pong_to_send_);
+ AOS_CHECK_EQ(nullptr, pong_to_send_);
pong_to_send_ = static_cast<Data *>(pong_queue_->GetMessage());
return pong_to_send_;
}
void Pong() override {
- CHECK_NE(nullptr, pong_to_send_);
- CHECK(pong_queue_->WriteMessage(pong_to_send_, RawQueue::kBlock));
+ AOS_CHECK_NE(nullptr, pong_to_send_);
+ AOS_CHECK(pong_queue_->WriteMessage(pong_to_send_, RawQueue::kBlock));
pong_to_send_ = nullptr;
}
@@ -887,7 +893,7 @@
memset(*to_send, i % 123, sizeof(*to_send));
const PingPongerInterface::Data *received = ping_ponger->Ping();
for (size_t ii = 0; ii < sizeof(*received); ++ii) {
- CHECK_EQ(((i % 123) + 1) % 255, (*received)[ii]);
+ AOS_CHECK_EQ(((i % 123) + 1) % 255, (*received)[ii]);
}
}
@@ -903,14 +909,14 @@
ping_ponger->Ping();
server.join();
- LOG(INFO, "Took %f seconds to send %" PRId32 " messages\n",
- ::aos::time::DurationInSeconds(end - start), FLAGS_messages);
+ AOS_LOG(INFO, "Took %f seconds to send %" PRId32 " messages\n",
+ ::aos::time::DurationInSeconds(end - start), FLAGS_messages);
const chrono::nanoseconds per_message = (end - start) / FLAGS_messages;
if (per_message >= chrono::seconds(1)) {
- LOG(INFO, "More than 1 second per message ?!?\n");
+ AOS_LOG(INFO, "More than 1 second per message ?!?\n");
} else {
- LOG(INFO, "That is %" PRId32 " nanoseconds per message\n",
- static_cast<int>(per_message.count()));
+ AOS_LOG(INFO, "That is %" PRId32 " nanoseconds per message\n",
+ static_cast<int>(per_message.count()));
}
return 0;
diff --git a/aos/ipc_lib/lockless_queue.cc b/aos/ipc_lib/lockless_queue.cc
index fb9c0b6..cd0e2ae 100644
--- a/aos/ipc_lib/lockless_queue.cc
+++ b/aos/ipc_lib/lockless_queue.cc
@@ -13,6 +13,7 @@
#include "aos/ipc_lib/lockless_queue_memory.h"
#include "aos/logging/logging.h"
#include "aos/util/compiler_memory_barrier.h"
+#include "glog/logging.h"
namespace aos {
namespace ipc_lib {
@@ -490,7 +491,7 @@
}
if (sender_index_ == -1) {
- LOG(FATAL, "Too many senders\n");
+ LOG(FATAL) << "Too many senders";
}
::aos::ipc_lib::Sender *s = memory_->GetSender(sender_index_);
diff --git a/aos/ipc_lib/lockless_queue_death_test.cc b/aos/ipc_lib/lockless_queue_death_test.cc
index 100821c..7a68273 100644
--- a/aos/ipc_lib/lockless_queue_death_test.cc
+++ b/aos/ipc_lib/lockless_queue_death_test.cc
@@ -15,10 +15,10 @@
#include "aos/ipc_lib/aos_sync.h"
#include "aos/ipc_lib/lockless_queue_memory.h"
#include "aos/libc/aos_strsignal.h"
-#include "aos/logging/logging.h"
#include "aos/testing/prevent_exit.h"
#include "aos/testing/test_logging.h"
#include "gflags/gflags.h"
+#include "glog/logging.h"
#include "gtest/gtest.h"
namespace aos {
@@ -148,12 +148,11 @@
// Calls mprotect(2) for the entire shared memory region with the given prot.
void ShmProtectOrDie(int prot) {
GlobalState *my_global_state = global_state.load(::std::memory_order_relaxed);
- if (mprotect(my_global_state->lockless_queue_memory,
- my_global_state->lockless_queue_memory_size, prot) == -1) {
- PLOG(FATAL, "mprotect(%p, %zu, %x) failed",
- my_global_state->lockless_queue_memory,
- my_global_state->lockless_queue_memory_size, prot);
- }
+ PCHECK(mprotect(my_global_state->lockless_queue_memory,
+ my_global_state->lockless_queue_memory_size, prot) != -1)
+ << ": mprotect(" << my_global_state->lockless_queue_memory << ", "
+ << my_global_state->lockless_queue_memory_size << ", 0x" << std::hex
+ << prot << ") failed";
}
// Checks a write into the queue and conditionally dies. Tracks the write.
@@ -277,13 +276,13 @@
SigactionType real_sigaction =
reinterpret_cast<SigactionType>(dlsym(RTLD_NEXT, "sigaction"));
if (sigaction == real_sigaction) {
- LOG(WARNING, "failed to work around tsan signal handling weirdness\n");
+ LOG(WARNING) << "failed to work around tsan signal handling weirdness";
}
- PCHECK(real_sigaction(signal, &action, old_action));
+ PCHECK(real_sigaction(signal, &action, old_action) == 0);
return;
}
#endif
- PCHECK(sigaction(signal, &action, old_action));
+ PCHECK(sigaction(signal, &action, old_action) == 0);
}
#endif // ifndef __ARM_EABI__
@@ -318,9 +317,7 @@
if (!prepare_in_child) prepare(my_global_state->lockless_queue_memory);
const pid_t pid = fork();
- if (pid == -1) {
- PLOG(FATAL, "fork() failed\n");
- }
+ PCHECK(pid != -1) << ": fork() failed";
if (pid == 0) {
// Run the test.
::aos::testing::PreventExit();
@@ -350,12 +347,13 @@
pid_t waited_on = waitpid(pid, &status, 0);
if (waited_on == -1) {
if (errno == EINTR) continue;
- PLOG(FATAL, "waitpid(%jd, %p, 0) failed\n", static_cast<intmax_t>(pid),
- &status);
+ PCHECK(false) << ": waitpid(" << static_cast<intmax_t>(pid) << ", "
+ << &status << ", 0) failed";
}
if (waited_on != pid) {
- LOG(FATAL, "waitpid got child %jd instead of %jd\n",
- static_cast<intmax_t>(waited_on), static_cast<intmax_t>(pid));
+ PCHECK(false) << ": waitpid got child "
+ << static_cast<intmax_t>(waited_on) << " instead of "
+ << static_cast<intmax_t>(pid);
}
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 0) return true;
diff --git a/aos/ipc_lib/queue.cc b/aos/ipc_lib/queue.cc
index 295e854..5b6a0fa 100644
--- a/aos/ipc_lib/queue.cc
+++ b/aos/ipc_lib/queue.cc
@@ -172,7 +172,7 @@
MessageHeader *header = __atomic_load_n(&free_messages_, __ATOMIC_RELAXED);
do {
if (__builtin_expect(header == nullptr, 0)) {
- LOG(FATAL, "overused pool of queue %p (%s)\n", this, name_);
+ AOS_LOG(FATAL, "overused pool of queue %p (%s)\n", this, name_);
}
} while (__builtin_expect(
!__atomic_compare_exchange_n(&free_messages_, &header, header->next, true,
@@ -196,8 +196,8 @@
"need to revalidate size/alignent assumptions");
if (queue_length < 1) {
- LOG(FATAL, "queue length %d of %s needs to be at least 1\n", queue_length,
- name);
+ AOS_LOG(FATAL, "queue length %d of %s needs to be at least 1\n",
+ queue_length, name);
}
const size_t name_size = strlen(name) + 1;
@@ -249,8 +249,8 @@
printf("fetching queue %s\n", name);
}
if (mutex_lock(&global_core->mem_struct->queues.lock) != 0) {
- LOG(FATAL, "mutex_lock(%p) failed\n",
- &global_core->mem_struct->queues.lock);
+ AOS_LOG(FATAL, "mutex_lock(%p) failed\n",
+ &global_core->mem_struct->queues.lock);
}
RawQueue *current =
static_cast<RawQueue *>(global_core->mem_struct->queues.pointer);
@@ -309,7 +309,7 @@
{
IPCMutexLocker locker(&data_lock_);
- CHECK(!locker.owner_died());
+ AOS_CHECK(!locker.owner_died());
int new_end;
while (true) {
@@ -334,7 +334,7 @@
if (kWriteDebug) {
printf("queue: going to wait for writable_ of %p\n", this);
}
- CHECK(!writable_.Wait());
+ AOS_CHECK(!writable_.Wait());
}
}
data_[data_end_] = msg;
@@ -390,7 +390,7 @@
if (wait_result == Condition::WaitResult::kOk) {
break;
}
- CHECK(wait_result != Condition::WaitResult::kOwnerDied);
+ AOS_CHECK(wait_result != Condition::WaitResult::kOwnerDied);
if (wait_result == Condition::WaitResult::kTimeout) {
return false;
}
@@ -427,7 +427,7 @@
void *msg = NULL;
IPCMutexLocker locker(&data_lock_);
- CHECK(!locker.owner_died());
+ AOS_CHECK(!locker.owner_died());
if (!ReadCommonStart(options, nullptr, chrono::nanoseconds(0))) {
if (kReadDebug) {
@@ -490,7 +490,7 @@
void *msg = NULL;
IPCMutexLocker locker(&data_lock_);
- CHECK(!locker.owner_died());
+ AOS_CHECK(!locker.owner_died());
if (!ReadCommonStart(options, index, timeout)) {
if (kReadDebug) {
diff --git a/aos/ipc_lib/queue.h b/aos/ipc_lib/queue.h
index b93cc42..5b68f2e 100644
--- a/aos/ipc_lib/queue.h
+++ b/aos/ipc_lib/queue.h
@@ -90,10 +90,10 @@
static constexpr Options<RawQueue> kWriteFailureOptions =
kNonBlock | kBlock | kOverride;
if (!options.NoOthersSet(kWriteFailureOptions)) {
- LOG(FATAL, "illegal write options in %x\n", options.printable());
+ AOS_LOG(FATAL, "illegal write options in %x\n", options.printable());
}
if (!options.ExactlyOneSet(kWriteFailureOptions)) {
- LOG(FATAL, "invalid write options %x\n", options.printable());
+ AOS_LOG(FATAL, "invalid write options %x\n", options.printable());
}
return DoWriteMessage(msg, options);
}
@@ -123,7 +123,7 @@
CheckReadOptions(options);
static constexpr Options<RawQueue> kFromEndAndPeek = kFromEnd | kPeek;
if (options.AllSet(kFromEndAndPeek)) {
- LOG(FATAL, "ReadMessageIndex(kFromEnd | kPeek) is not allowed\n");
+ AOS_LOG(FATAL, "ReadMessageIndex(kFromEnd | kPeek) is not allowed\n");
}
return DoReadMessageIndex(options, index, timeout);
}
@@ -161,11 +161,11 @@
static constexpr Options<RawQueue> kValidOptions =
kPeek | kFromEnd | kNonBlock | kBlock;
if (!options.NoOthersSet(kValidOptions)) {
- LOG(FATAL, "illegal read options in %x\n", options.printable());
+ AOS_LOG(FATAL, "illegal read options in %x\n", options.printable());
}
static constexpr Options<RawQueue> kBlockChoices = kNonBlock | kBlock;
if (!options.ExactlyOneSet(kBlockChoices)) {
- LOG(FATAL, "invalid read options %x\n", options.printable());
+ AOS_LOG(FATAL, "invalid read options %x\n", options.printable());
}
}
diff --git a/aos/ipc_lib/raw_queue_test.cc b/aos/ipc_lib/raw_queue_test.cc
index ab98b1f..aa3b335 100644
--- a/aos/ipc_lib/raw_queue_test.cc
+++ b/aos/ipc_lib/raw_queue_test.cc
@@ -99,23 +99,25 @@
printf("process %jd was already dead\n",
static_cast<intmax_t>(pid_));
} else {
- PLOG(FATAL, "kill(SIGKILL, %jd) failed",
- static_cast<intmax_t>(pid_));
+ AOS_PLOG(FATAL, "kill(SIGKILL, %jd) failed",
+ static_cast<intmax_t>(pid_));
}
}
}
const pid_t ret = wait(NULL);
if (ret == -1) {
- LOG(WARNING, "wait(NULL) failed."
- " child %jd might still be alive\n",
- static_cast<intmax_t>(pid_));
+ AOS_LOG(WARNING,
+ "wait(NULL) failed."
+ " child %jd might still be alive\n",
+ static_cast<intmax_t>(pid_));
} else if (ret == 0) {
- LOG(WARNING, "child %jd wasn't waitable. it might still be alive\n",
- static_cast<intmax_t>(pid_));
+ AOS_LOG(WARNING, "child %jd wasn't waitable. it might still be alive\n",
+ static_cast<intmax_t>(pid_));
} else if (ret != pid_) {
- LOG(WARNING, "child %d is now confirmed dead"
- ", but child %jd might still be alive\n",
- ret, static_cast<intmax_t>(pid_));
+ AOS_LOG(WARNING,
+ "child %d is now confirmed dead"
+ ", but child %jd might still be alive\n",
+ ret, static_cast<intmax_t>(pid_));
}
}
@@ -188,16 +190,16 @@
switch (pid) {
case 0: // child
if (kForkSleep != chrono::milliseconds(0)) {
- LOG(INFO, "pid %jd sleeping for %" PRId64 "ns\n",
- static_cast<intmax_t>(getpid()), kForkSleep.count());
+ AOS_LOG(INFO, "pid %jd sleeping for %" PRId64 "ns\n",
+ static_cast<intmax_t>(getpid()), kForkSleep.count());
this_thread::sleep_for(kForkSleep);
}
::aos::testing::PreventExit();
function(arg);
- CHECK_NE(-1, futex_set(done));
+ AOS_CHECK_NE(-1, futex_set(done));
exit(EXIT_SUCCESS);
case -1: // parent failure
- PLOG(ERROR, "fork() failed");
+ AOS_PLOG(ERROR, "fork() failed");
return std::unique_ptr<ForkedProcess>();
default: // parent
return std::unique_ptr<ForkedProcess>(new ForkedProcess(pid, done));
@@ -237,7 +239,7 @@
static_cast<char *>(fatal_failure)[0] = '\0';
children_[id] = ForkExecute(Hangs_, to_call).release();
if (!children_[id]) return AssertionFailure() << "ForkExecute failed";
- CHECK_EQ(0, futex_wait(&to_call->started));
+ AOS_CHECK_EQ(0, futex_wait(&to_call->started));
to_calls_[id] = reinterpret_cast<FunctionToCall<void> *>(to_call);
return AssertionSuccess();
}
diff --git a/aos/ipc_lib/shared_mem.c b/aos/ipc_lib/shared_mem.c
index e8edc9e..da55ebc 100644
--- a/aos/ipc_lib/shared_mem.c
+++ b/aos/ipc_lib/shared_mem.c
@@ -61,7 +61,7 @@
if (shm == -1 && errno == EEXIST) {
printf("shared_mem: going to shm_unlink(%s)\n", global_core->shm_name);
if (shm_unlink(global_core->shm_name) == -1) {
- PLOG(WARNING, "shm_unlink(%s) failed", global_core->shm_name);
+ AOS_PLOG(WARNING, "shm_unlink(%s) failed", global_core->shm_name);
break;
}
} else {
@@ -73,12 +73,12 @@
global_core->owner = 0;
}
if (shm == -1) {
- PLOG(FATAL, "shm_open(%s, O_RDWR [| O_CREAT | O_EXCL, 0|0666) failed",
- global_core->shm_name);
+ AOS_PLOG(FATAL, "shm_open(%s, O_RDWR [| O_CREAT | O_EXCL, 0|0666) failed",
+ global_core->shm_name);
}
if (global_core->owner) {
if (ftruncate(shm, SIZEOFSHMSEG) == -1) {
- PLOG(FATAL, "fruncate(%d, 0x%zx) failed", shm, (size_t)SIZEOFSHMSEG);
+ AOS_PLOG(FATAL, "fruncate(%d, 0x%zx) failed", shm, (size_t)SIZEOFSHMSEG);
}
}
int flags = MAP_SHARED | MAP_FIXED;
@@ -86,8 +86,8 @@
void *shm_address = mmap((void *)SHM_START, SIZEOFSHMSEG,
PROT_READ | PROT_WRITE, flags, shm, 0);
if (shm_address == MAP_FAILED) {
- PLOG(FATAL, "shared_mem: mmap(%p, 0x%zx, stuff, %x, %d, 0) failed",
- (void *)SHM_START, (size_t)SIZEOFSHMSEG, flags, shm);
+ AOS_PLOG(FATAL, "shared_mem: mmap(%p, 0x%zx, stuff, %x, %d, 0) failed",
+ (void *)SHM_START, (size_t)SIZEOFSHMSEG, flags, shm);
}
if (create) {
printf("shared_mem: creating %s, shm at: %p\n", global_core->shm_name,
@@ -96,14 +96,14 @@
printf("shared_mem: not creating, shm at: %p\n", shm_address);
}
if (close(shm) == -1) {
- PLOG(WARNING, "close(%d(=shm) failed", shm);
+ AOS_PLOG(WARNING, "close(%d(=shm) failed", shm);
}
if (shm_address != (void *)SHM_START) {
- LOG(FATAL, "shm isn't at hard-coded %p. at %p instead\n",
- (void *)SHM_START, shm_address);
+ AOS_LOG(FATAL, "shm isn't at hard-coded %p. at %p instead\n",
+ (void *)SHM_START, shm_address);
}
aos_core_use_address_as_shared_mem(shm_address, SIZEOFSHMSEG);
- LOG(INFO, "shared_mem: end of create_shared_mem owner=%d\n",
+ AOS_LOG(INFO, "shared_mem: end of create_shared_mem owner=%d\n",
global_core->owner);
}
@@ -118,7 +118,7 @@
futex_set(&global_core->mem_struct->creation_condition);
} else {
if (futex_wait(&global_core->mem_struct->creation_condition) != 0) {
- LOG(FATAL, "waiting on creation_condition failed\n");
+ AOS_LOG(FATAL, "waiting on creation_condition failed\n");
}
}
}
@@ -126,12 +126,13 @@
void aos_core_free_shared_mem() {
void *shm_address = global_core->shared_mem;
if (munmap((void *)SHM_START, SIZEOFSHMSEG) == -1) {
- PLOG(FATAL, "munmap(%p, 0x%zx) failed", shm_address,
- (size_t)SIZEOFSHMSEG);
+ AOS_PLOG(FATAL, "munmap(%p, 0x%zx) failed", shm_address,
+ (size_t)SIZEOFSHMSEG);
}
if (global_core->owner) {
if (shm_unlink(global_core->shm_name)) {
- PLOG(FATAL, "shared_mem: shm_unlink(%s) failed", global_core->shm_name);
+ AOS_PLOG(FATAL, "shared_mem: shm_unlink(%s) failed",
+ global_core->shm_name);
}
}
}
diff --git a/aos/ipc_lib/signalfd.cc b/aos/ipc_lib/signalfd.cc
index 1679b46..045444b 100644
--- a/aos/ipc_lib/signalfd.cc
+++ b/aos/ipc_lib/signalfd.cc
@@ -18,7 +18,7 @@
}
// Then build a signalfd. Make it nonblocking so it works well with an epoll
// loop, and have it close on exec.
- PCHECK(fd_ = signalfd(-1, &mask_, SFD_NONBLOCK | SFD_CLOEXEC));
+ AOS_PCHECK(fd_ = signalfd(-1, &mask_, SFD_NONBLOCK | SFD_CLOEXEC));
// Now that we have a consumer of the signal, block the signals so the
// signalfd gets them.
pthread_sigmask(SIG_BLOCK, &mask_, nullptr);
@@ -27,7 +27,7 @@
SignalFd::~SignalFd() {
// Unwind the constructor. Unblock the signals and close the fd.
pthread_sigmask(SIG_UNBLOCK, &mask_, nullptr);
- PCHECK(close(fd_));
+ AOS_PCHECK(close(fd_));
}
signalfd_siginfo SignalFd::Read() {
diff --git a/aos/libc/aos_strsignal.cc b/aos/libc/aos_strsignal.cc
index 77f0b90..a3331f9 100644
--- a/aos/libc/aos_strsignal.cc
+++ b/aos/libc/aos_strsignal.cc
@@ -8,8 +8,8 @@
static thread_local char buffer[512];
if (signal >= SIGRTMIN && signal <= SIGRTMAX) {
- CHECK(snprintf(buffer, sizeof(buffer), "Real-time signal %d",
- signal - SIGRTMIN) > 0);
+ AOS_CHECK(snprintf(buffer, sizeof(buffer), "Real-time signal %d",
+ signal - SIGRTMIN) > 0);
return buffer;
}
@@ -17,6 +17,6 @@
return sys_siglist[signal];
}
- CHECK(snprintf(buffer, sizeof(buffer), "Unknown signal %d", signal) > 0);
+ AOS_CHECK(snprintf(buffer, sizeof(buffer), "Unknown signal %d", signal) > 0);
return buffer;
}
diff --git a/aos/logging/binary_log_file.cc b/aos/logging/binary_log_file.cc
index ca62b73..9ea5c82 100644
--- a/aos/logging/binary_log_file.cc
+++ b/aos/logging/binary_log_file.cc
@@ -24,8 +24,8 @@
: fd_(fd), writable_(writable), offset_(0), current_(0), position_(0) {
// Check to make sure that mmap will allow mmaping in chunks of kPageSize.
if (SystemPageSize() > kPageSize || (kPageSize % SystemPageSize()) != 0) {
- LOG(FATAL, "system page size (%lu) not factor of kPageSize (%zd).\n",
- SystemPageSize(), kPageSize);
+ AOS_LOG(FATAL, "system page size (%lu) not factor of kPageSize (%zd).\n",
+ SystemPageSize(), kPageSize);
}
MapNextPage();
@@ -36,14 +36,14 @@
}
void LogFileAccessor::SkipToLastSeekablePage() {
- CHECK(definitely_use_mmap());
+ AOS_CHECK(definitely_use_mmap());
struct stat info;
if (fstat(fd_, &info) == -1) {
- PLOG(FATAL, "fstat(%d, %p) failed", fd_, &info);
+ AOS_PLOG(FATAL, "fstat(%d, %p) failed", fd_, &info);
}
- CHECK((info.st_size % kPageSize) == 0);
+ AOS_CHECK((info.st_size % kPageSize) == 0);
const auto last_readable_page_number = (info.st_size / kPageSize) - 1;
const auto last_seekable_page_number =
last_readable_page_number / kSeekPages * kSeekPages;
@@ -66,7 +66,7 @@
struct stat info;
if (fstat(fd_, &info) == -1) {
- PLOG(FATAL, "fstat(%d, %p) failed", fd_, &info);
+ AOS_PLOG(FATAL, "fstat(%d, %p) failed", fd_, &info);
}
bool r = offset_ == static_cast<off_t>(info.st_size - kPageSize);
is_last_page_ = r ? Maybe::kYes : Maybe::kNo;
@@ -76,7 +76,7 @@
void LogFileAccessor::MapNextPage() {
if (writable_) {
if (ftruncate(fd_, offset_ + kPageSize) == -1) {
- PLOG(FATAL, "ftruncate(%d, %zd) failed", fd_, kPageSize);
+ AOS_PLOG(FATAL, "ftruncate(%d, %zd) failed", fd_, kPageSize);
}
}
@@ -85,49 +85,51 @@
while (todo > 0) {
ssize_t result = read(fd_, current_ + (kPageSize - todo), todo);
if (result == -1) {
- PLOG(FATAL, "read(%d, %p, %zu) failed", fd_,
- current_ + (kPageSize - todo), todo);
+ AOS_PLOG(FATAL, "read(%d, %p, %zu) failed", fd_,
+ current_ + (kPageSize - todo), todo);
} else if (result == 0) {
memset(current_, 0, todo);
result = todo;
}
todo -= result;
}
- CHECK_EQ(0, todo);
+ AOS_CHECK_EQ(0, todo);
} else {
current_ = static_cast<char *>(
mmap(NULL, kPageSize, PROT_READ | (writable_ ? PROT_WRITE : 0),
MAP_SHARED, fd_, offset_));
if (current_ == MAP_FAILED) {
if (!writable_ && use_read_ == Maybe::kUnknown && errno == ENODEV) {
- LOG(INFO, "Falling back to reading the file using read(2).\n");
+ AOS_LOG(INFO, "Falling back to reading the file using read(2).\n");
use_read_ = Maybe::kYes;
current_ = new char[kPageSize];
MapNextPage();
return;
} else {
- PLOG(FATAL,
- "mmap(NULL, %zd, PROT_READ [ | PROT_WRITE], MAP_SHARED, %d, %jd)"
- " failed",
- kPageSize, fd_, static_cast<intmax_t>(offset_));
+ AOS_PLOG(
+ FATAL,
+ "mmap(NULL, %zd, PROT_READ [ | PROT_WRITE], MAP_SHARED, %d, %jd)"
+ " failed",
+ kPageSize, fd_, static_cast<intmax_t>(offset_));
}
} else {
use_read_ = Maybe::kNo;
}
if (madvise(current_, kPageSize, MADV_SEQUENTIAL | MADV_WILLNEED) == -1) {
- PLOG(WARNING, "madvise(%p, %zd, MADV_SEQUENTIAL | MADV_WILLNEED) failed",
- current_, kPageSize);
+ AOS_PLOG(WARNING,
+ "madvise(%p, %zd, MADV_SEQUENTIAL | MADV_WILLNEED) failed",
+ current_, kPageSize);
}
}
offset_ += kPageSize;
}
void LogFileAccessor::Unmap(void *location) {
- CHECK_NE(Maybe::kUnknown, use_read_);
+ AOS_CHECK_NE(Maybe::kUnknown, use_read_);
if (use_read_ == Maybe::kNo) {
if (munmap(location, kPageSize) == -1) {
- PLOG(FATAL, "munmap(%p, %zd) failed", location, kPageSize);
+ AOS_PLOG(FATAL, "munmap(%p, %zd) failed", location, kPageSize);
}
}
is_last_page_ = Maybe::kUnknown;
@@ -140,7 +142,7 @@
r = static_cast<LogFileMessageHeader *>(
static_cast<void *>(¤t()[position()]));
if (wait) {
- CHECK(definitely_use_mmap());
+ AOS_CHECK(definitely_use_mmap());
if (futex_wait(&r->marker) != 0) continue;
}
if (r->marker == 2) {
@@ -158,7 +160,7 @@
if (position() >= kPageSize) {
// It's a lot better to blow up here rather than getting SIGBUS errors the
// next time we try to read...
- LOG(FATAL, "corrupt log file running over page size\n");
+ AOS_LOG(FATAL, "corrupt log file running over page size\n");
}
return r;
}
@@ -189,31 +191,31 @@
action.sa_flags = SA_RESETHAND | SA_SIGINFO;
struct sigaction previous_bus, previous_segv;
if (sigaction(SIGBUS, &action, &previous_bus) == -1) {
- PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, %p) failed",
- SIGBUS, &action, &previous_bus);
+ AOS_PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, %p) failed", SIGBUS, &action,
+ &previous_bus);
}
if (sigaction(SIGSEGV, &action, &previous_segv) == -1) {
- PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, %p) failed",
- SIGSEGV, &action, &previous_segv);
+ AOS_PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, %p) failed", SIGSEGV,
+ &action, &previous_segv);
}
char __attribute__((unused)) c = current()[0];
if (sigaction(SIGBUS, &previous_bus, NULL) == -1) {
- PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, NULL) failed",
- SIGBUS, &previous_bus);
+ AOS_PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, NULL) failed", SIGBUS,
+ &previous_bus);
}
if (sigaction(SIGSEGV, &previous_segv, NULL) == -1) {
- PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, NULL) failed",
- SIGSEGV, &previous_segv);
+ AOS_PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, NULL) failed", SIGSEGV,
+ &previous_segv);
}
} else {
if (fault_address == current()) {
- LOG(FATAL, "could not read 1 byte at offset 0x%jx into log file\n",
- static_cast<uintmax_t>(offset()));
+ AOS_LOG(FATAL, "could not read 1 byte at offset 0x%jx into log file\n",
+ static_cast<uintmax_t>(offset()));
} else {
- LOG(FATAL, "faulted at %p, not %p like we were (maybe) supposed to\n",
- fault_address, current());
+ AOS_LOG(FATAL, "faulted at %p, not %p like we were (maybe) supposed to\n",
+ fault_address, current());
}
}
}
@@ -234,7 +236,7 @@
++next_message_page;
}
const off_t current_seekable_page = next_message_page / kSeekPages;
- CHECK_LE(*cookie, current_seekable_page);
+ AOS_CHECK_LE(*cookie, current_seekable_page);
const bool r = *cookie != current_seekable_page;
*cookie = current_seekable_page;
return r;
@@ -252,8 +254,8 @@
if (futex_set_value(
static_cast<aos_futex *>(static_cast<void *>(&temp[position()])),
2) == -1) {
- PLOG(WARNING, "readers will hang because futex_set_value(%p, 2) failed",
- &temp[position()]);
+ AOS_PLOG(WARNING, "readers will hang because futex_set_value(%p, 2) failed",
+ &temp[position()]);
}
Unmap(temp);
}
diff --git a/aos/logging/binary_log_writer.cc b/aos/logging/binary_log_writer.cc
index e335b53..be19d45 100644
--- a/aos/logging/binary_log_writer.cc
+++ b/aos/logging/binary_log_writer.cc
@@ -42,8 +42,8 @@
char buffer[1024];
ssize_t size = type.Serialize(buffer, sizeof(buffer));
if (size == -1) {
- LOG(WARNING, "%zu-byte buffer is too small to serialize type %s\n",
- sizeof(buffer), type.name.c_str());
+ AOS_LOG(WARNING, "%zu-byte buffer is too small to serialize type %s\n",
+ sizeof(buffer), type.name.c_str());
return;
}
LogFileMessageHeader *const output =
@@ -78,7 +78,7 @@
if (errno == 0) {
break;
} else {
- PLOG(FATAL, "readdir(%p) failed", d);
+ AOS_PLOG(FATAL, "readdir(%p) failed", d);
}
} else {
if (sscanf(dir->d_name, "aos_log-%d", &index) == 1) {
@@ -97,15 +97,16 @@
previous[len] = '\0';
} else {
previous[0] = '\0';
- LOG(INFO, "Could not find aos_log-current\n");
+ AOS_LOG(INFO, "Could not find aos_log-current\n");
printf("Could not find aos_log-current\n");
}
if (asprintf(filename, "%s/aos_log-%03d", directory, fileindex) == -1) {
PDie("couldn't create final name");
}
- LOG(INFO, "Created log file (aos_log-%d) in directory (%s). Previous file "
- "was (%s).\n",
- fileindex, directory, previous);
+ AOS_LOG(INFO,
+ "Created log file (aos_log-%d) in directory (%s). Previous file "
+ "was (%s).\n",
+ fileindex, directory, previous);
printf("Created log file (aos_log-%d) in directory (%s). Previous file was "
"(%s).\n",
fileindex, directory, previous);
@@ -138,7 +139,7 @@
char test_device[10];
for (char i = 'a'; i < 'z'; ++i) {
snprintf(test_device, sizeof(test_device), "/dev/sd%c", i);
- LOG(INFO, "Trying to access %s\n", test_device);
+ AOS_LOG(INFO, "Trying to access %s\n", test_device);
if (access(test_device, F_OK) != -1) {
snprintf(device, device_size, "sd%c", i);
return true;
@@ -157,13 +158,13 @@
{
char dev_name[8];
while (!FindDevice(dev_name, sizeof(dev_name))) {
- LOG(INFO, "Waiting for a device\n");
+ AOS_LOG(INFO, "Waiting for a device\n");
printf("Waiting for a device\n");
sleep(5);
}
snprintf(folder, sizeof(folder), "/media/%s1", dev_name);
while (!FoundThumbDrive(folder)) {
- LOG(INFO, "Waiting for %s\n", folder);
+ AOS_LOG(INFO, "Waiting for %s\n", folder);
printf("Waiting for %s\n", folder);
sleep(1);
}
@@ -175,21 +176,21 @@
const char *folder = configuration::GetLoggingDirectory();
if (access(folder, R_OK | W_OK) == -1) {
#endif
- LOG(FATAL, "folder '%s' does not exist. please create it\n", folder);
+ AOS_LOG(FATAL, "folder '%s' does not exist. please create it\n", folder);
}
- LOG(INFO, "logging to folder '%s'\n", folder);
+ AOS_LOG(INFO, "logging to folder '%s'\n", folder);
char *tmp;
AllocateLogName(&tmp, folder);
char *tmp2;
if (asprintf(&tmp2, "%s/aos_log-current", folder) == -1) {
- PLOG(WARNING, "couldn't create current symlink name");
+ AOS_PLOG(WARNING, "couldn't create current symlink name");
} else {
if (unlink(tmp2) == -1 && (errno != EROFS && errno != ENOENT)) {
- LOG(WARNING, "unlink('%s') failed", tmp2);
+ AOS_LOG(WARNING, "unlink('%s') failed", tmp2);
}
if (symlink(tmp, tmp2) == -1) {
- PLOG(WARNING, "symlink('%s', '%s') failed", tmp, tmp2);
+ AOS_PLOG(WARNING, "symlink('%s', '%s') failed", tmp, tmp2);
}
free(tmp2);
}
@@ -197,7 +198,7 @@
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
free(tmp);
if (fd == -1) {
- PLOG(FATAL, "opening file '%s' failed", tmp);
+ AOS_PLOG(FATAL, "opening file '%s' failed", tmp);
}
LogFileWriter writer(fd);
@@ -234,7 +235,7 @@
output_length +=
sizeof(msg->matrix.type) + sizeof(uint32_t) + sizeof(uint16_t) +
sizeof(uint16_t) + msg->matrix.string_length;
- CHECK(MessageType::IsPrimitive(msg->matrix.type));
+ AOS_CHECK(MessageType::IsPrimitive(msg->matrix.type));
}
LogFileMessageHeader *const output = writer.GetWritePosition(output_length);
char *output_strings = reinterpret_cast<char *>(output) + sizeof(*output);
@@ -289,8 +290,8 @@
memcpy(position, &cols, sizeof(cols));
position += sizeof(cols);
output->message_size += sizeof(rows) + sizeof(cols);
- CHECK_EQ(msg->message_length,
- MessageType::Sizeof(msg->matrix.type) * rows * cols);
+ AOS_CHECK_EQ(msg->message_length,
+ MessageType::Sizeof(msg->matrix.type) * rows * cols);
memcpy(position, msg->matrix.data, msg->message_length + length);
output->message_size += length;
@@ -301,8 +302,8 @@
if (output->message_size - msg->message_length !=
output_length - raw_output_length) {
- LOG(FATAL, "%zu != %zu\n", output->message_size - msg->message_length,
- output_length - raw_output_length);
+ AOS_LOG(FATAL, "%zu != %zu\n", output->message_size - msg->message_length,
+ output_length - raw_output_length);
}
futex_set(&output->marker);
diff --git a/aos/logging/implementations.cc b/aos/logging/implementations.cc
index 273c583..632d90b 100644
--- a/aos/logging/implementations.cc
+++ b/aos/logging/implementations.cc
@@ -21,15 +21,15 @@
// The root LogImplementation. It only logs to stderr/stdout.
// Some of the things specified in the LogImplementation documentation doesn't
-// apply here (mostly the parts about being able to use LOG) because this is the
-// root one.
+// apply here (mostly the parts about being able to use AOS_LOG) because this is
+// the root one.
class RootLogImplementation : public SimpleLogImplementation {
public:
void have_other_implementation() { only_implementation_ = false; }
private:
void set_next(LogImplementation *) override {
- LOG(FATAL, "can't have a next logger from here\n");
+ AOS_LOG(FATAL, "can't have a next logger from here\n");
}
__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
@@ -68,8 +68,7 @@
if (pthread_atfork(NULL /*prepare*/, NULL /*parent*/,
NewContext /*child*/) != 0) {
- LOG(FATAL, "pthread_atfork(NULL, NULL, %p) failed\n",
- NewContext);
+ AOS_LOG(FATAL, "pthread_atfork(NULL, NULL, %p) failed\n", NewContext);
}
return NULL;
@@ -116,7 +115,8 @@
FillInMessageBase(level, monotonic_now, message);
if (message_string.size() + size > sizeof(message->structure.serialized)) {
- LOG(FATAL,
+ AOS_LOG(
+ FATAL,
"serialized struct %s (size %zd + %zd > %zd) and message %s too big\n",
type->name.c_str(), message_string.size(), size,
sizeof(message->structure.serialized), message_string.c_str());
@@ -135,7 +135,7 @@
const ::std::string &message_string, uint32_t type_id,
int rows, int cols, const void *data,
LogMessage *message) {
- CHECK(MessageType::IsPrimitive(type_id));
+ AOS_CHECK(MessageType::IsPrimitive(type_id));
message->matrix.type = type_id;
const auto element_size = MessageType::Sizeof(type_id);
@@ -145,9 +145,10 @@
message->message_length = rows * cols * element_size;
if (message_string.size() + message->message_length >
sizeof(message->matrix.data)) {
- LOG(FATAL, "%dx%d matrix of type %" PRIu32
- " (size %u) and message %s is too big\n",
- rows, cols, type_id, element_size, message_string.c_str());
+ AOS_LOG(FATAL,
+ "%dx%d matrix of type %" PRIu32
+ " (size %u) and message %s is too big\n",
+ rows, cols, type_id, element_size, message_string.c_str());
}
message->matrix.string_length = message_string.size();
memcpy(message->matrix.data, message_string.data(),
@@ -187,15 +188,17 @@
buffer, &output_length,
message.structure.serialized + message.structure.string_length,
&input_length, type_cache::Get(message.structure.type_id))) {
- LOG(FATAL,
+ AOS_LOG(
+ FATAL,
"printing message (%.*s) of type %s into %zu-byte buffer failed\n",
static_cast<int>(message.message_length), message.message,
type_cache::Get(message.structure.type_id).name.c_str(),
sizeof(buffer));
}
if (input_length > 0) {
- LOG(WARNING, "%zu extra bytes on message of type %s\n", input_length,
- type_cache::Get(message.structure.type_id).name.c_str());
+ AOS_LOG(WARNING, "%zu extra bytes on message of type %s\n",
+ input_length,
+ type_cache::Get(message.structure.type_id).name.c_str());
}
fprintf(output, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
static_cast<int>(message.structure.string_length),
@@ -208,17 +211,17 @@
if (message.message_length !=
static_cast<size_t>(message.matrix.rows * message.matrix.cols *
MessageType::Sizeof(message.matrix.type))) {
- LOG(FATAL, "expected %d bytes of matrix data but have %zu\n",
- message.matrix.rows * message.matrix.cols *
- MessageType::Sizeof(message.matrix.type),
- message.message_length);
+ AOS_LOG(FATAL, "expected %d bytes of matrix data but have %zu\n",
+ message.matrix.rows * message.matrix.cols *
+ MessageType::Sizeof(message.matrix.type),
+ message.message_length);
}
if (!PrintMatrix(buffer, &output_length,
message.matrix.data + message.matrix.string_length,
message.matrix.type, message.matrix.rows,
message.matrix.cols)) {
- LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n",
- message.matrix.rows, message.matrix.cols, message.matrix.type);
+ AOS_LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n",
+ message.matrix.rows, message.matrix.cols, message.matrix.type);
}
fprintf(output, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
static_cast<int>(message.matrix.string_length),
@@ -236,16 +239,17 @@
const MessageType *type, const ::std::function<size_t(char *)> &serialize) {
char serialized[1024];
if (size > sizeof(serialized)) {
- LOG(FATAL, "structure of type %s too big to serialize\n",
- type->name.c_str());
+ AOS_LOG(FATAL, "structure of type %s too big to serialize\n",
+ type->name.c_str());
}
size_t used = serialize(serialized);
char printed[1024];
size_t printed_bytes = sizeof(printed);
if (!PrintMessage(printed, &printed_bytes, serialized, &used, *type)) {
- LOG(FATAL, "PrintMessage(%p, %p(=%zd), %p, %p(=%zd), %p(name=%s)) failed\n",
- printed, &printed_bytes, printed_bytes, serialized, &used, used, type,
- type->name.c_str());
+ AOS_LOG(FATAL,
+ "PrintMessage(%p, %p(=%zd), %p, %p(=%zd), %p(name=%s)) failed\n",
+ printed, &printed_bytes, printed_bytes, serialized, &used, used,
+ type, type->name.c_str());
}
DoLogVariadic(level, "%.*s: %.*s\n", static_cast<int>(message.size()),
message.data(),
@@ -258,16 +262,17 @@
char serialized[1024];
if (static_cast<size_t>(rows * cols * MessageType::Sizeof(type_id)) >
sizeof(serialized)) {
- LOG(FATAL, "matrix of size %u too big to serialize\n",
- rows * cols * MessageType::Sizeof(type_id));
+ AOS_LOG(FATAL, "matrix of size %u too big to serialize\n",
+ rows * cols * MessageType::Sizeof(type_id));
}
SerializeMatrix(type_id, serialized, data, rows, cols);
char printed[1024];
size_t printed_bytes = sizeof(printed);
if (!PrintMatrix(printed, &printed_bytes, serialized, type_id, rows, cols)) {
- LOG(FATAL, "PrintMatrix(%p, %p(=%zd), %p, %" PRIu32 ", %d, %d) failed\n",
- printed, &printed_bytes, printed_bytes, serialized, type_id, rows,
- cols);
+ AOS_LOG(FATAL,
+ "PrintMatrix(%p, %p(=%zd), %p, %" PRIu32 ", %d, %d) failed\n",
+ printed, &printed_bytes, printed_bytes, serialized, type_id, rows,
+ cols);
}
DoLogVariadic(level, "%.*s: %.*s\n", static_cast<int>(message.size()),
message.data(),
@@ -311,8 +316,10 @@
internal::Context *context = internal::Context::Get();
if (implementation->next() != NULL) {
- LOG(FATAL, "%p already has a next implementation, but it's not"
- " being used yet\n", implementation);
+ AOS_LOG(FATAL,
+ "%p already has a next implementation, but it's not"
+ " being used yet\n",
+ implementation);
}
LogImplementation *old = context->implementation;
@@ -348,7 +355,7 @@
LogMessage *GetMessageOrDie() {
LogMessage *message = static_cast<LogMessage *>(queue->GetMessage());
if (message == NULL) {
- LOG(FATAL, "%p->GetMessage() failed\n", queue);
+ AOS_LOG(FATAL, "%p->GetMessage() failed\n", queue);
} else {
return message;
}
diff --git a/aos/logging/implementations_test.cc b/aos/logging/implementations_test.cc
index ecf66e9..2accf35 100644
--- a/aos/logging/implementations_test.cc
+++ b/aos/logging/implementations_test.cc
@@ -63,17 +63,17 @@
}
internal::Context *context = internal::Context::Get();
if (log_implementation->message().source != context->source) {
- LOG(FATAL, "got a message from %" PRIu32 ", but we're %" PRIu32 "\n",
- static_cast<uint32_t>(log_implementation->message().source),
- static_cast<uint32_t>(context->source));
+ AOS_LOG(FATAL, "got a message from %" PRIu32 ", but we're %" PRIu32 "\n",
+ static_cast<uint32_t>(log_implementation->message().source),
+ static_cast<uint32_t>(context->source));
}
if (log_implementation->message().name_length != context->name_size ||
memcmp(log_implementation->message().name, context->name,
context->name_size) !=
0) {
- LOG(FATAL, "got a message from %.*s, but we're %s\n",
- static_cast<int>(log_implementation->message().name_length),
- log_implementation->message().name, context->name);
+ AOS_LOG(FATAL, "got a message from %.*s, but we're %s\n",
+ static_cast<int>(log_implementation->message().name_length),
+ log_implementation->message().name, context->name);
}
if (strstr(log_implementation->message().message, message.c_str())
== NULL) {
@@ -110,26 +110,26 @@
// correctly.
TEST_F(LoggingTest, Basic) {
EXPECT_FALSE(WasAnythingLogged());
- LOG(INFO, "test log 1\n");
+ AOS_LOG(INFO, "test log 1\n");
EXPECT_TRUE(WasLogged(INFO, "test log 1\n"));
- LOG(INFO, "test log 1.5\n");
+ AOS_LOG(INFO, "test log 1.5\n");
// there's a subtle typo on purpose...
EXPECT_FALSE(WasLogged(INFO, "test log 15\n"));
- LOG(ERROR, "test log 2=%d\n", 55);
+ AOS_LOG(ERROR, "test log 2=%d\n", 55);
EXPECT_TRUE(WasLogged(ERROR, "test log 2=55\n"));
- LOG(ERROR, "test log 3\n");
+ AOS_LOG(ERROR, "test log 3\n");
EXPECT_FALSE(WasLogged(WARNING, "test log 3\n"));
- LOG(WARNING, "test log 4\n");
+ AOS_LOG(WARNING, "test log 4\n");
EXPECT_TRUE(WasAnythingLogged());
}
TEST_F(LoggingTest, Cork) {
static const int begin_line = __LINE__;
- LOG_CORK("first part ");
- LOG_CORK("second part (=%d) ", 19);
+ AOS_LOG_CORK("first part ");
+ AOS_LOG_CORK("second part (=%d) ", 19);
EXPECT_FALSE(WasAnythingLogged());
- LOG_CORK("third part ");
+ AOS_LOG_CORK("third part ");
static const int end_line = __LINE__;
- LOG_UNCORK(WARNING, "last part %d\n", 5);
+ AOS_LOG_UNCORK(WARNING, "last part %d\n", 5);
std::stringstream expected;
expected << "implementations_test.cc: ";
expected << (begin_line + 1);
@@ -142,27 +142,24 @@
}
TEST_F(LoggingDeathTest, Fatal) {
- ASSERT_EXIT(LOG(FATAL, "this should crash it\n"),
- ::testing::KilledBySignal(SIGABRT),
- "this should crash it");
+ ASSERT_EXIT(AOS_LOG(FATAL, "this should crash it\n"),
+ ::testing::KilledBySignal(SIGABRT), "this should crash it");
}
TEST_F(LoggingDeathTest, PCHECK) {
- EXPECT_DEATH(PCHECK(fprintf(stdin, "nope")),
+ EXPECT_DEATH(AOS_PCHECK(fprintf(stdin, "nope")),
".*fprintf\\(stdin, \"nope\"\\).*failed.*");
}
-TEST_F(LoggingTest, PCHECK) {
- EXPECT_EQ(7, PCHECK(printf("abc123\n")));
-}
+TEST_F(LoggingTest, PCHECK) { EXPECT_EQ(7, AOS_PCHECK(printf("abc123\n"))); }
TEST_F(LoggingTest, PrintfDirectives) {
- LOG(INFO, "test log %%1 %%d\n");
+ AOS_LOG(INFO, "test log %%1 %%d\n");
EXPECT_TRUE(WasLogged(INFO, "test log %1 %d\n"));
- LOG_DYNAMIC(WARNING, "test log %%2 %%f\n");
+ AOS_LOG_DYNAMIC(WARNING, "test log %%2 %%f\n");
EXPECT_TRUE(WasLogged(WARNING, "test log %2 %f\n"));
- LOG_CORK("log 3 part %%1 %%d ");
- LOG_UNCORK(DEBUG, "log 3 part %%2 %%f\n");
+ AOS_LOG_CORK("log 3 part %%1 %%d ");
+ AOS_LOG_UNCORK(DEBUG, "log 3 part %%2 %%f\n");
EXPECT_TRUE(WasLogged(DEBUG, "log 3 part %1 %d log 3 part %2 %f\n"));
}
@@ -173,7 +170,7 @@
monotonic_clock::time_point start = monotonic_clock::now();
for (long i = 0; i < kTimingCycles; ++i) {
- LOG(INFO, "a\n");
+ AOS_LOG(INFO, "a\n");
}
monotonic_clock::time_point end = monotonic_clock::now();
auto diff = end - start;
@@ -183,7 +180,7 @@
start = monotonic_clock::now();
for (long i = 0; i < kTimingCycles; ++i) {
- LOG(INFO, "something longer than just \"a\" to log to test timing\n");
+ AOS_LOG(INFO, "something longer than just \"a\" to log to test timing\n");
}
end = monotonic_clock::now();
diff = end - start;
diff --git a/aos/logging/interface.cc b/aos/logging/interface.cc
index fb3b60e..bcd8470 100644
--- a/aos/logging/interface.cc
+++ b/aos/logging/interface.cc
@@ -21,7 +21,7 @@
const int ret = vsnprintf(output, size, format, ap);
typedef ::std::common_type<typeof(ret), typeof(size)>::type RetType;
if (ret < 0) {
- PLOG(FATAL, "vsnprintf(%p, %zd, %s, args) failed",
+ AOS_PLOG(FATAL, "vsnprintf(%p, %zd, %s, args) failed",
output, size, format);
} else if (static_cast<RetType>(ret) >= static_cast<RetType>(size)) {
// Overwrite the '\0' at the end of the existing data and
@@ -84,8 +84,9 @@
context->cork_data.function = function;
} else {
if (strcmp(context->cork_data.function, function) != 0) {
- LOG(FATAL, "started corking data in function %s but then moved to %s\n",
- context->cork_data.function, function);
+ AOS_LOG(FATAL,
+ "started corking data in function %s but then moved to %s\n",
+ context->cork_data.function, function);
}
}
diff --git a/aos/logging/log_displayer.cc b/aos/logging/log_displayer.cc
index 0480b4b..e63bdc3 100644
--- a/aos/logging/log_displayer.cc
+++ b/aos/logging/log_displayer.cc
@@ -75,28 +75,28 @@
"possible arguments for the -n option cannot be shown. log_displayer\n"
"looks for start_list.txt in the current working directory and in\n"
"%s.\n\n", ::aos::configuration::GetRootDirectory());
- PLOG(FATAL, "Unable to open start_list.txt");
+ AOS_PLOG(FATAL, "Unable to open start_list.txt");
}
}
// Get file size.
if (fseek(start_list, 0, SEEK_END)) {
- PLOG(FATAL, "fseek() failed while reading start_list.txt");
+ AOS_PLOG(FATAL, "fseek() failed while reading start_list.txt");
}
int size = ftell(start_list);
if (size < 0) {
- PLOG(FATAL, "ftell() failed while reading start_list.txt");
+ AOS_PLOG(FATAL, "ftell() failed while reading start_list.txt");
}
rewind(start_list);
::std::unique_ptr<char[]> contents(new char[size + 1]);
if (contents == NULL) {
- LOG(FATAL, "malloc() failed while reading start_list.txt.\n");
+ AOS_LOG(FATAL, "malloc() failed while reading start_list.txt.\n");
}
size_t bytes_read = fread(contents.get(), 1, size, start_list);
if (bytes_read < static_cast<size_t>(size)) {
- LOG(FATAL, "Read %zu bytes from start_list.txt, expected %d.\n",
- bytes_read, size);
+ AOS_LOG(FATAL, "Read %zu bytes from start_list.txt, expected %d.\n",
+ bytes_read, size);
}
// printf doesn't like strings without the \0.
@@ -104,7 +104,7 @@
fprintf(stderr, "\nPossible arguments for the -n option:\n%s", contents.get());
if (fclose(start_list)) {
- LOG(FATAL, "fclose() failed.\n");
+ AOS_LOG(FATAL, "fclose() failed.\n");
}
exit(EXIT_SUCCESS);
@@ -249,7 +249,7 @@
::aos::logging::log_str(filter_level), filename);
if (fd == -1) {
- PLOG(FATAL, "couldn't open file '%s' for reading", filename);
+ AOS_PLOG(FATAL, "couldn't open file '%s' for reading", filename);
}
::aos::logging::linux_code::LogFileReader reader(fd);
@@ -272,16 +272,17 @@
::aos::MessageType *type = ::aos::MessageType::Deserialize(
reinterpret_cast<const char *>(msg + 1), &bytes);
if (type == nullptr) {
- LOG(INFO, "Trying old version of type decoding.\n");
+ AOS_LOG(INFO, "Trying old version of type decoding.\n");
bytes = msg->message_size;
type = ::aos::MessageType::Deserialize(
reinterpret_cast<const char *>(msg + 1), &bytes, false);
}
if (type == nullptr) {
- LOG(WARNING, "Error deserializing MessageType of size %" PRIx32
- " starting at %zx.\n",
- msg->message_size, reader.file_offset(msg + 1));
+ AOS_LOG(WARNING,
+ "Error deserializing MessageType of size %" PRIx32
+ " starting at %zx.\n",
+ msg->message_size, reader.file_offset(msg + 1));
} else {
::aos::type_cache::Add(*type);
}
@@ -357,14 +358,15 @@
(sizeof(type_id) + sizeof(uint32_t) + string_length);
if (!PrintMessage(buffer, &output_length, position + string_length,
&input_length, ::aos::type_cache::Get(type_id))) {
- LOG(FATAL, "printing message (%.*s) of type %s into %zu-byte buffer "
- "failed\n",
- static_cast<int>(string_length), position,
- ::aos::type_cache::Get(type_id).name.c_str(), sizeof(buffer));
+ AOS_LOG(FATAL,
+ "printing message (%.*s) of type %s into %zu-byte buffer "
+ "failed\n",
+ static_cast<int>(string_length), position,
+ ::aos::type_cache::Get(type_id).name.c_str(), sizeof(buffer));
}
if (input_length > 0) {
- LOG(WARNING, "%zu extra bytes on message of type %s\n",
- input_length, ::aos::type_cache::Get(type_id).name.c_str());
+ AOS_LOG(WARNING, "%zu extra bytes on message of type %s\n",
+ input_length, ::aos::type_cache::Get(type_id).name.c_str());
}
fprintf(stdout, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
static_cast<int>(string_length), position,
@@ -390,20 +392,21 @@
msg->message_size -
(sizeof(type) + sizeof(uint32_t) + sizeof(uint16_t) +
sizeof(uint16_t) + string_length);
- CHECK_EQ(matrix_bytes, ::aos::MessageType::Sizeof(type) * rows * cols);
+ AOS_CHECK_EQ(matrix_bytes,
+ ::aos::MessageType::Sizeof(type) * rows * cols);
char buffer[4096];
size_t output_length = sizeof(buffer);
if (!::aos::PrintMatrix(buffer, &output_length,
position + string_length, type, rows, cols)) {
- LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n", rows,
- cols, type);
+ AOS_LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n",
+ rows, cols, type);
}
fprintf(stdout, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
static_cast<int>(string_length), position,
static_cast<int>(sizeof(buffer) - output_length), buffer);
} break;
case LogFileMessageHeader::MessageType::kStructType:
- LOG(FATAL, "shouldn't get here\n");
+ AOS_LOG(FATAL, "shouldn't get here\n");
break;
}
#undef BASE_ARGS
diff --git a/aos/logging/logging.h b/aos/logging/logging.h
index 6682098..bd9b103 100644
--- a/aos/logging/logging.h
+++ b/aos/logging/logging.h
@@ -4,14 +4,14 @@
// This file contains the logging client interface. It works with both C and C++
// code.
-#include <stdio.h>
+#include <errno.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
-#include "aos/macros.h"
#include "aos/libc/aos_strerror.h"
+#include "aos/macros.h"
#ifdef __cplusplus
extern "C" {
@@ -19,16 +19,16 @@
typedef uint8_t log_level;
-#define DECL_LEVELS \
-DECL_LEVEL(DEBUG, 0); /* stuff that gets printed out every cycle */ \
-DECL_LEVEL(INFO, 1); /* things like PosEdge/NegEdge */ \
-/* things that might still work if they happen occasionally */ \
-DECL_LEVEL(WARNING, 2); \
-/*-1 so that vxworks macro of same name will have same effect if used*/ \
-DECL_LEVEL(ERROR, -1); /* errors */ \
-/* serious errors. the logging code will terminate the process/task */ \
-DECL_LEVEL(FATAL, 4); \
-DECL_LEVEL(LOG_UNKNOWN, 5); /* unknown logging level */
+#define DECL_LEVELS \
+ DECL_LEVEL(DEBUG, 0); /* stuff that gets printed out every cycle */ \
+ DECL_LEVEL(INFO, 1); /* things like PosEdge/NegEdge */ \
+ /* things that might still work if they happen occasionally */ \
+ DECL_LEVEL(WARNING, 2); \
+ /*-1 so that vxworks macro of same name will have same effect if used*/ \
+ DECL_LEVEL(ERROR, -1); /* errors */ \
+ /* serious errors. the logging code will terminate the process/task */ \
+ DECL_LEVEL(FATAL, 4); \
+ DECL_LEVEL(LOG_UNKNOWN, 5); /* unknown logging level */
#define DECL_LEVEL(name, value) static const log_level name = value;
DECL_LEVELS;
#undef DECL_LEVEL
@@ -40,14 +40,14 @@
// Actually implements the basic logging call.
// Does not check that level is valid.
void log_do(log_level level, const char *format, ...)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 3)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 3)));
void log_cork(int line, const char *function, const char *format, ...)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)));
// Implements the uncork logging call.
void log_uncork(int line, const char *function, log_level level,
const char *file, const char *format, ...)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 6)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 6)));
#ifdef __cplusplus
}
@@ -64,7 +64,7 @@
#define LOG_SOURCENAME __FILE__
// The basic logging call.
-#define LOG(level, format, args...) \
+#define AOS_LOG(level, format, args...) \
do { \
log_do(level, LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": %s: " format, \
LOG_CURRENT_FUNCTION, ##args); \
@@ -78,39 +78,39 @@
// Same as LOG except appends " due to %d (%s)\n" (formatted with errno and
// aos_strerror(errno)) to the message.
-#define PLOG(level, format, args...) PELOG(level, errno, format, ##args)
+#define AOS_PLOG(level, format, args...) AOS_PELOG(level, errno, format, ##args)
// Like PLOG except allows specifying an error other than errno.
-#define PELOG(level, error_in, format, args...) \
- do { \
- const int error = error_in; \
- LOG(level, format " due to %d (%s)\n", ##args, error, \
- aos_strerror(error)); \
+#define AOS_PELOG(level, error_in, format, args...) \
+ do { \
+ const int error = error_in; \
+ AOS_LOG(level, format " due to %d (%s)\n", ##args, error, \
+ aos_strerror(error)); \
} while (0);
// Allows format to not be a string constant.
-#define LOG_DYNAMIC(level, format, args...) \
- do { \
- static char log_buf[LOG_MESSAGE_LEN]; \
- int ret = snprintf(log_buf, sizeof(log_buf), format, ##args); \
- if (ret < 0 || (uintmax_t)ret >= LOG_MESSAGE_LEN) { \
- LOG(ERROR, "next message was too long so not subbing in args\n"); \
- LOG(level, "%s", format); \
- } else { \
- LOG(level, "%s", log_buf); \
- } \
+#define AOS_LOG_DYNAMIC(level, format, args...) \
+ do { \
+ static char log_buf[LOG_MESSAGE_LEN]; \
+ int ret = snprintf(log_buf, sizeof(log_buf), format, ##args); \
+ if (ret < 0 || (uintmax_t)ret >= LOG_MESSAGE_LEN) { \
+ AOS_LOG(ERROR, "next message was too long so not subbing in args\n"); \
+ AOS_LOG(level, "%s", format); \
+ } else { \
+ AOS_LOG(level, "%s", log_buf); \
+ } \
} while (0)
// Allows "bottling up" multiple log fragments which can then all be logged in
// one message with LOG_UNCORK.
// Calls from a given thread/task will be grouped together.
-#define LOG_CORK(format, args...) \
+#define AOS_LOG_CORK(format, args...) \
do { \
log_cork(__LINE__, LOG_CURRENT_FUNCTION, format, ##args); \
} while (0)
// Actually logs all of the saved up log fragments (including format and args on
// the end).
-#define LOG_UNCORK(level, format, args...) \
+#define AOS_LOG_UNCORK(level, format, args...) \
do { \
log_uncork(__LINE__, LOG_CURRENT_FUNCTION, level, LOG_SOURCENAME, format, \
##args); \
@@ -162,16 +162,16 @@
// controlled by NDEBUG, so the check will be executed regardless of
// compilation mode. Therefore, it is safe to do things like:
// CHECK(fp->Write(x) == 4)
-#define CHECK(condition) \
- if (__builtin_expect(!(condition), 0)) { \
- LOG(FATAL, "CHECK(%s) failed\n", #condition); \
+#define AOS_CHECK(condition) \
+ if (__builtin_expect(!(condition), 0)) { \
+ AOS_LOG(FATAL, "CHECK(%s) failed\n", #condition); \
}
// Helper functions for CHECK_OP macro.
// The (int, int) specialization works around the issue that the compiler
// will not instantiate the template version of the function on values of
// unnamed enum type.
-#define DEFINE_CHECK_OP_IMPL(name, op) \
+#define AOS_DEFINE_CHECK_OP_IMPL(name, op) \
template <typename T1, typename T2> \
inline void LogImpl##name(const T1 &v1, const T2 &v2, \
const char *exprtext) { \
@@ -192,47 +192,47 @@
// base/logging.h provides its own #defines for the simpler names EQ, NE, etc.
// This happens if, for example, those are used as token names in a
// yacc grammar.
-DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(NULL, x)?
-DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead.
-DEFINE_CHECK_OP_IMPL(Check_LE, <=)
-DEFINE_CHECK_OP_IMPL(Check_LT, < )
-DEFINE_CHECK_OP_IMPL(Check_GE, >=)
-DEFINE_CHECK_OP_IMPL(Check_GT, > )
+AOS_DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(NULL, x)?
+AOS_DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead.
+AOS_DEFINE_CHECK_OP_IMPL(Check_LE, <=)
+AOS_DEFINE_CHECK_OP_IMPL(Check_LT, <)
+AOS_DEFINE_CHECK_OP_IMPL(Check_GE, >=)
+AOS_DEFINE_CHECK_OP_IMPL(Check_GT, >)
-#define CHECK_OP(name, op, val1, val2) \
- ::aos::LogImplCheck##name(val1, val2, \
+#define AOS_CHECK_OP(name, op, val1, val2) \
+ ::aos::LogImplCheck##name(val1, val2, \
STRINGIFY(val1) STRINGIFY(op) STRINGIFY(val2))
-#define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2)
-#define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2)
-#define CHECK_LE(val1, val2) CHECK_OP(_LE, <=, val1, val2)
-#define CHECK_LT(val1, val2) CHECK_OP(_LT, < , val1, val2)
-#define CHECK_GE(val1, val2) CHECK_OP(_GE, >=, val1, val2)
-#define CHECK_GT(val1, val2) CHECK_OP(_GT, > , val1, val2)
+#define AOS_CHECK_EQ(val1, val2) AOS_CHECK_OP(_EQ, ==, val1, val2)
+#define AOS_CHECK_NE(val1, val2) AOS_CHECK_OP(_NE, !=, val1, val2)
+#define AOS_CHECK_LE(val1, val2) AOS_CHECK_OP(_LE, <=, val1, val2)
+#define AOS_CHECK_LT(val1, val2) AOS_CHECK_OP(_LT, <, val1, val2)
+#define AOS_CHECK_GE(val1, val2) AOS_CHECK_OP(_GE, >=, val1, val2)
+#define AOS_CHECK_GT(val1, val2) AOS_CHECK_OP(_GT, >, val1, val2)
// A small helper for CHECK_NOTNULL().
template <typename T>
-inline T* CheckNotNull(const char *value_name, T *t) {
+inline T *CheckNotNull(const char *value_name, T *t) {
if (t == NULL) {
- LOG(FATAL, "'%s' must not be NULL\n", value_name);
+ AOS_LOG(FATAL, "'%s' must not be NULL\n", value_name);
}
return t;
}
// Check that the input is non NULL. This very useful in constructor
// initializer lists.
-#define CHECK_NOTNULL(val) ::aos::CheckNotNull(STRINGIFY(val), val)
+#define AOS_CHECK_NOTNULL(val) ::aos::CheckNotNull(STRINGIFY(val), val)
inline int CheckSyscall(const char *syscall_string, int value) {
if (__builtin_expect(value == -1, false)) {
- PLOG(FATAL, "%s failed", syscall_string);
+ AOS_PLOG(FATAL, "%s failed", syscall_string);
}
return value;
}
inline void CheckSyscallReturn(const char *syscall_string, int value) {
if (__builtin_expect(value != 0, false)) {
- PELOG(FATAL, value, "%s failed", syscall_string);
+ AOS_PELOG(FATAL, value, "%s failed", syscall_string);
}
}
@@ -240,16 +240,17 @@
// useful for quickly checking syscalls where it's not very useful to print out
// the values of any of the arguments. Returns the result otherwise.
//
-// Example: const int fd = PCHECK(open("/tmp/whatever", O_WRONLY))
-#define PCHECK(syscall) ::aos::CheckSyscall(STRINGIFY(syscall), syscall)
+// Example: const int fd = AOS_PCHECK(open("/tmp/whatever", O_WRONLY))
+#define AOS_PCHECK(syscall) ::aos::CheckSyscall(STRINGIFY(syscall), syscall)
// PELOG(FATAL)s with the result of syscall if it returns anything other than 0.
// This is useful for quickly checking things like many of the pthreads
// functions where it's not very useful to print out the values of any of the
// arguments.
//
-// Example: PRCHECK(munmap(address, length))
-#define PRCHECK(syscall) ::aos::CheckSyscallReturn(STRINGIFY(syscall), syscall)
+// Example: AOS_PRCHECK(munmap(address, length))
+#define AOS_PRCHECK(syscall) \
+ ::aos::CheckSyscallReturn(STRINGIFY(syscall), syscall)
} // namespace aos
diff --git a/aos/logging/matrix_logging.h b/aos/logging/matrix_logging.h
index 630e85e..ef51d56 100644
--- a/aos/logging/matrix_logging.h
+++ b/aos/logging/matrix_logging.h
@@ -15,7 +15,7 @@
// Logs the contents of a matrix and a constant string.
// matrix must be an instance of an Eigen matrix (or something similar).
-#define LOG_MATRIX(level, message, matrix) \
+#define AOS_LOG_MATRIX(level, message, matrix) \
do { \
static const ::std::string kAosLoggingMessage( \
LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message); \
diff --git a/aos/logging/queue_logging.h b/aos/logging/queue_logging.h
index a390412..fdebcc3 100644
--- a/aos/logging/queue_logging.h
+++ b/aos/logging/queue_logging.h
@@ -15,7 +15,7 @@
// Logs the contents of a structure (or Queue message) and a constant string.
// structure must be an instance of one of the generated queue types.
-#define LOG_STRUCT(level, message, structure) \
+#define AOS_LOG_STRUCT(level, message, structure) \
do { \
static const ::std::string kAosLoggingMessage( \
LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message); \
diff --git a/aos/logging/replay.h b/aos/logging/replay.h
index 45a4cd2..6604591 100644
--- a/aos/logging/replay.h
+++ b/aos/logging/replay.h
@@ -57,11 +57,13 @@
void AddHandler(const ::std::string &process_name,
const ::std::string &log_message,
::std::function<void(const T &message)> handler) {
- CHECK(handlers_.emplace(
- ::std::piecewise_construct,
- ::std::forward_as_tuple(process_name, log_message),
- ::std::forward_as_tuple(::std::unique_ptr<StructHandlerInterface>(
- new TypedStructHandler<T>(handler)))).second);
+ AOS_CHECK(handlers_
+ .emplace(::std::piecewise_construct,
+ ::std::forward_as_tuple(process_name, log_message),
+ ::std::forward_as_tuple(
+ ::std::unique_ptr<StructHandlerInterface>(
+ new TypedStructHandler<T>(handler))))
+ .second);
}
// Adds a handler which takes messages and places them directly on a queue.
@@ -98,10 +100,11 @@
void HandleStruct(::aos::monotonic_clock::time_point log_time,
uint32_t type_id, const void *data,
size_t data_size) override {
- CHECK_EQ(type_id, T::GetType()->id);
+ AOS_CHECK_EQ(type_id, T::GetType()->id);
T message;
- CHECK_EQ(data_size, T::Size());
- CHECK_EQ(data_size, message.Deserialize(static_cast<const char *>(data)));
+ AOS_CHECK_EQ(data_size, T::Size());
+ AOS_CHECK_EQ(data_size,
+ message.Deserialize(static_cast<const char *>(data)));
message.sent_time = log_time;
handler_(message);
}
@@ -119,11 +122,11 @@
T::kQueueLength)) {}
void operator()(const T &message) {
- LOG_STRUCT(DEBUG, "re-sending", message);
+ AOS_LOG_STRUCT(DEBUG, "re-sending", message);
void *raw_message = queue_->GetMessage();
- CHECK_NOTNULL(raw_message);
+ AOS_CHECK_NOTNULL(raw_message);
memcpy(raw_message, &message, sizeof(message));
- CHECK(queue_->WriteMessage(raw_message, RawQueue::kOverride));
+ AOS_CHECK(queue_->WriteMessage(raw_message, RawQueue::kOverride));
}
private:
diff --git a/aos/mutex/mutex.cc b/aos/mutex/mutex.cc
index a35f0cd..c5570aa 100644
--- a/aos/mutex/mutex.cc
+++ b/aos/mutex/mutex.cc
@@ -19,8 +19,8 @@
} else if (ret == 1) {
return true;
} else {
- LOG(FATAL, "mutex_grab(%p(=%" PRIu32 ")) failed with %d\n",
- &impl_, impl_.futex, ret);
+ AOS_LOG(FATAL, "mutex_grab(%p(=%" PRIu32 ")) failed with %d\n", &impl_,
+ impl_.futex, ret);
}
}
@@ -38,8 +38,8 @@
case 4:
return State::kLockFailed;
default:
- LOG(FATAL, "mutex_trylock(%p(=%" PRIu32 ")) failed with %d\n",
- &impl_, impl_.futex, ret);
+ AOS_LOG(FATAL, "mutex_trylock(%p(=%" PRIu32 ")) failed with %d\n", &impl_,
+ impl_.futex, ret);
}
}
diff --git a/aos/network/team_number.cc b/aos/network/team_number.cc
index 4e3f472..c4fa5c2 100644
--- a/aos/network/team_number.cc
+++ b/aos/network/team_number.cc
@@ -47,7 +47,7 @@
::std::string GetHostname() {
char buf[256];
buf[sizeof(buf) - 1] = '\0';
- PCHECK(gethostname(buf, sizeof(buf) - 1));
+ AOS_PCHECK(gethostname(buf, sizeof(buf) - 1));
return buf;
}
@@ -59,16 +59,16 @@
const char *override_number = getenv("AOS_TEAM_NUMBER");
if (override_number != nullptr) {
if (!::aos::util::StringToNumber(override_number, &r)) {
- LOG(FATAL, "error parsing AOS_TEAM_NUMBER '%s'\n", override_number);
+ AOS_LOG(FATAL, "error parsing AOS_TEAM_NUMBER '%s'\n", override_number);
}
- LOG(WARNING, "team number overridden by AOS_TEAM_NUMBER to %" PRIu16 "\n",
- r);
+ AOS_LOG(WARNING,
+ "team number overridden by AOS_TEAM_NUMBER to %" PRIu16 "\n", r);
} else {
int error = internal::ParseTeamNumber(GetHostname(), &r);
if (error) {
- LOG(FATAL, "Invalid hostname %s\n", GetHostname().c_str());
+ AOS_LOG(FATAL, "Invalid hostname %s\n", GetHostname().c_str());
}
- LOG(INFO, "team number is %" PRIu16 "\n", r);
+ AOS_LOG(INFO, "team number is %" PRIu16 "\n", r);
}
return &r;
}
diff --git a/aos/protobuf/stack_arena.cc b/aos/protobuf/stack_arena.cc
index da9b004..c085fcb 100644
--- a/aos/protobuf/stack_arena.cc
+++ b/aos/protobuf/stack_arena.cc
@@ -4,11 +4,11 @@
namespace protobuf {
void FatalArenaBlockAlloc(size_t) {
- LOG(FATAL, "trying to allocate in arena code");
+ AOS_LOG(FATAL, "trying to allocate in arena code");
}
void FatalArenaBlockDealloc(void*, size_t) {
- LOG(FATAL, "trying to deallocate in arena code");
+ AOS_LOG(FATAL, "trying to deallocate in arena code");
}
} // namespace protobuf
diff --git a/aos/protobuf/stack_arena_test.cc b/aos/protobuf/stack_arena_test.cc
index c9eb5e8..a07ceea 100644
--- a/aos/protobuf/stack_arena_test.cc
+++ b/aos/protobuf/stack_arena_test.cc
@@ -22,7 +22,7 @@
TestStruct* msg =
google::protobuf::Arena::Create<TestStruct>(stack_arena.arena());
- CHECK_NOTNULL(msg);
+ AOS_CHECK_NOTNULL(msg);
}
} // namespace
diff --git a/aos/queue_types.cc b/aos/queue_types.cc
index 367d54a..a48c5a0 100644
--- a/aos/queue_types.cc
+++ b/aos/queue_types.cc
@@ -188,7 +188,7 @@
output += output_bytes_before - *output_bytes;
input = static_cast<const char *>(input) + type.super_size;
first = false;
- CHECK(start_input_bytes == (*input_bytes + 8));
+ AOS_CHECK(start_input_bytes == (*input_bytes + 8));
} else {
*input_bytes -= type.super_size;
input = static_cast<const char *>(input) + type.super_size;
@@ -247,7 +247,7 @@
bool PrintMatrix(char *output, size_t *output_bytes, const void *input,
uint32_t type_id, int rows, int cols) {
- CHECK(MessageType::IsPrimitive(type_id));
+ AOS_CHECK(MessageType::IsPrimitive(type_id));
const size_t element_size = MessageType::Sizeof(type_id);
if (*output_bytes < 1) return false;
@@ -288,7 +288,7 @@
&input_bytes, type_id)) {
return false;
}
- CHECK_EQ(0u, input_bytes);
+ AOS_CHECK_EQ(0u, input_bytes);
// Update the output pointer.
output += output_bytes_before - *output_bytes;
}
@@ -309,7 +309,7 @@
char *const output = static_cast<char *>(output_void);
const char *const input = static_cast<const char *>(input_void);
- CHECK(MessageType::IsPrimitive(type_id));
+ AOS_CHECK(MessageType::IsPrimitive(type_id));
const size_t element_size = MessageType::Sizeof(type_id);
for (int i = 0; i < rows * cols; ++i) {
@@ -327,7 +327,7 @@
to_network<8>(&input[i * element_size], &output[i * element_size]);
break;
default:
- LOG(FATAL, "illegal primitive type size %zu\n", element_size);
+ AOS_LOG(FATAL, "illegal primitive type size %zu\n", element_size);
}
}
}
@@ -392,15 +392,15 @@
c = c->next;
}
} else {
- LOG(INFO, "FYI: no shm. going to LOG(FATAL) now\n");
+ AOS_LOG(INFO, "FYI: no shm. going to LOG(FATAL) now\n");
}
- LOG(FATAL, "MessageType for id 0x%" PRIx32 " not found\n", type_id);
+ AOS_LOG(FATAL, "MessageType for id 0x%" PRIx32 " not found\n", type_id);
}
void AddShm(uint32_t type_id) {
if (!aos_core_is_init()) {
- LOG(FATAL, "can't AddShm(%" PRIu32 ") without shm!\n", type_id);
+ AOS_LOG(FATAL, "can't AddShm(%" PRIu32 ") without shm!\n", type_id);
}
const MessageType::Field **fields;
@@ -414,7 +414,7 @@
number_fields = cached.type.number_fields;
if (mutex_lock(&global_core->mem_struct->queue_types.lock) != 0) {
- LOG(FATAL, "locking queue_types lock failed\n");
+ AOS_LOG(FATAL, "locking queue_types lock failed\n");
}
volatile ShmType *current = static_cast<volatile ShmType *>(
global_core->mem_struct->queue_types.pointer);
@@ -432,8 +432,8 @@
char buffer[1024];
ssize_t size = cached.type.Serialize(buffer, sizeof(buffer));
if (size == -1) {
- LOG(FATAL, "type %s is too big to fit into %zd bytes\n",
- cached.type.name.c_str(), sizeof(buffer));
+ AOS_LOG(FATAL, "type %s is too big to fit into %zd bytes\n",
+ cached.type.name.c_str(), sizeof(buffer));
}
volatile ShmType *shm =
diff --git a/aos/queue_types_test.cc b/aos/queue_types_test.cc
index 91a1f74..6503f02 100644
--- a/aos/queue_types_test.cc
+++ b/aos/queue_types_test.cc
@@ -167,7 +167,7 @@
input_bytes = sizeof(kData) + kExtraInputBytes;
to_network(&kData, input);
output_bytes = kString.size() + 1;
- CHECK_LE(output_bytes, sizeof(output));
+ ASSERT_LE(output_bytes, sizeof(output));
ASSERT_TRUE(PrintField(output, &output_bytes, input, &input_bytes,
Structure::GetType()->fields[2]->type));
EXPECT_EQ(kExtraInputBytes, input_bytes);
@@ -211,7 +211,7 @@
"struct_int:973, struct_float:3.140000}]}";
TEST_F(PrintMessageTest, Basic) {
- CHECK_GE(sizeof(input), kTestMessage1.Size());
+ ASSERT_GE(sizeof(input), kTestMessage1.Size());
input_bytes = kTestMessage1.Serialize(input);
output_bytes = sizeof(output);
ASSERT_TRUE(PrintMessage(output, &output_bytes, input, &input_bytes,
@@ -221,7 +221,7 @@
}
TEST_F(PrintMessageTest, OutputTooSmall) {
- CHECK_GE(sizeof(input), kTestMessage1.Size());
+ ASSERT_GE(sizeof(input), kTestMessage1.Size());
input_bytes = kTestMessage1.Serialize(input);
output_bytes = kTestMessage1String.size();
EXPECT_FALSE(PrintMessage(output, &output_bytes, input, &input_bytes,
@@ -236,7 +236,7 @@
}
TEST_F(PrintMessageTest, Structure) {
- CHECK_GE(sizeof(input), kTestStructure1.Size());
+ ASSERT_GE(sizeof(input), kTestStructure1.Size());
input_bytes = kTestStructure1.Serialize(input);
output_bytes = sizeof(output);
ASSERT_TRUE(PrintMessage(output, &output_bytes, input, &input_bytes,
@@ -260,7 +260,7 @@
}
TEST_F(PrintMessageTest, Array) {
- CHECK_GE(sizeof(input), kTestMessageWithArrays.Size());
+ ASSERT_GE(sizeof(input), kTestMessageWithArrays.Size());
input_bytes = kTestMessageWithArrays.Serialize(input);
output_bytes = sizeof(output);
ASSERT_TRUE(PrintMessage(output, &output_bytes, input, &input_bytes,
diff --git a/aos/scoped/scoped_fd.cc b/aos/scoped/scoped_fd.cc
index a570df0..74f8882 100644
--- a/aos/scoped/scoped_fd.cc
+++ b/aos/scoped/scoped_fd.cc
@@ -7,7 +7,7 @@
void ScopedFD::Close() {
if (fd_ != -1) {
if (close(fd_) == -1) {
- PLOG(WARNING, "close(%d) failed", fd_);
+ AOS_PLOG(WARNING, "close(%d) failed", fd_);
}
}
}
diff --git a/aos/seasocks/seasocks_logger.cc b/aos/seasocks/seasocks_logger.cc
index dad9970..53d05e8 100644
--- a/aos/seasocks/seasocks_logger.cc
+++ b/aos/seasocks/seasocks_logger.cc
@@ -26,7 +26,7 @@
aos_level = DEBUG;
break;
}
- LOG(aos_level, "Seasocks: %s\n", message);
+ AOS_LOG(aos_level, "Seasocks: %s\n", message);
}
} // namespace seasocks
diff --git a/aos/starter/starter.cc b/aos/starter/starter.cc
index bb72523..8b137ff 100644
--- a/aos/starter/starter.cc
+++ b/aos/starter/starter.cc
@@ -73,7 +73,7 @@
void operator()(event *evt) {
if (evt == NULL) return;
if (event_del(evt) != 0) {
- LOG(WARNING, "event_del(%p) failed\n", evt);
+ AOS_LOG(WARNING, "event_del(%p) failed\n", evt);
}
}
};
@@ -115,11 +115,11 @@
// After calling this method, this object won't really be doing much of
// anything besides possibly running its callback or something.
void RemoveWatch() {
- CHECK_NE(watch_, -1);
- CHECK_EQ(watch_to_remove_, -1);
+ AOS_CHECK_NE(watch_, -1);
+ AOS_CHECK_EQ(watch_to_remove_, -1);
if (inotify_rm_watch(notify_fd, watch_) == -1) {
- PLOG(WARNING, "inotify_rm_watch(%d, %d) failed", notify_fd, watch_);
+ AOS_PLOG(WARNING, "inotify_rm_watch(%d, %d) failed", notify_fd, watch_);
}
watch_to_remove_ = watch_;
watch_ = -1;
@@ -140,16 +140,16 @@
void RemoveWatchFromMap() {
int watch = watch_to_remove_;
if (watch == -1) {
- CHECK_NE(watch_, -1);
+ AOS_CHECK_NE(watch_, -1);
watch = watch_;
}
if (watchers[watch] != this) {
- LOG(WARNING, "watcher for %s (%p) didn't find itself in the map\n",
- filename_.c_str(), this);
+ AOS_LOG(WARNING, "watcher for %s (%p) didn't find itself in the map\n",
+ filename_.c_str(), this);
} else {
watchers.erase(watch);
}
- LOG(DEBUG, "removed watch ID %d\n", watch);
+ AOS_LOG(DEBUG, "removed watch ID %d\n", watch);
if (watch_to_remove_ == -1) {
watch_ = -1;
} else {
@@ -158,19 +158,20 @@
}
void CreateWatch() {
- CHECK_EQ(watch_, -1);
+ AOS_CHECK_EQ(watch_, -1);
watch_ = inotify_add_watch(notify_fd, filename_.c_str(),
create_ ? IN_CREATE : (IN_ATTRIB |
IN_MODIFY |
IN_DELETE_SELF |
IN_MOVE_SELF));
if (watch_ == -1) {
- PLOG(FATAL, "inotify_add_watch(%d, %s,"
- " %s ? IN_CREATE : (IN_ATTRIB | IN_MODIFY)) failed",
- notify_fd, filename_.c_str(), create_ ? "true" : "false");
+ AOS_PLOG(FATAL,
+ "inotify_add_watch(%d, %s,"
+ " %s ? IN_CREATE : (IN_ATTRIB | IN_MODIFY)) failed",
+ notify_fd, filename_.c_str(), create_ ? "true" : "false");
}
watchers[watch_] = this;
- LOG(DEBUG, "watch for %s is %d\n", filename_.c_str(), watch_);
+ AOS_LOG(DEBUG, "watch for %s is %d\n", filename_.c_str(), watch_);
}
// This gets set up as the callback for EV_READ on the inotify file
@@ -179,7 +180,7 @@
unsigned int to_read;
// Use FIONREAD to figure out how many bytes there are to read.
if (ioctl(notify_fd, FIONREAD, &to_read) < 0) {
- PLOG(FATAL, "FIONREAD(%d, %p) failed", notify_fd, &to_read);
+ AOS_PLOG(FATAL, "FIONREAD(%d, %p) failed", notify_fd, &to_read);
}
inotify_event *notifyevt = static_cast<inotify_event *>(malloc(to_read));
const char *end = reinterpret_cast<char *>(notifyevt) + to_read;
@@ -187,11 +188,11 @@
ssize_t ret = read(notify_fd, notifyevt, to_read);
if (ret < 0) {
- PLOG(FATAL, "read(%d, %p, %u) failed", notify_fd, notifyevt, to_read);
+ AOS_PLOG(FATAL, "read(%d, %p, %u) failed", notify_fd, notifyevt, to_read);
}
if (static_cast<size_t>(ret) != to_read) {
- LOG(ERROR, "read(%d, %p, %u) returned %zd instead of %u\n",
- notify_fd, notifyevt, to_read, ret, to_read);
+ AOS_LOG(ERROR, "read(%d, %p, %u) returned %zd instead of %u\n", notify_fd,
+ notifyevt, to_read, ret, to_read);
return;
}
@@ -199,9 +200,9 @@
// multiple events at once.
while (reinterpret_cast<char *>(notifyevt) < end) {
if (watchers.count(notifyevt->wd) != 1) {
- LOG(WARNING, "couldn't find whose watch ID %d is\n", notifyevt->wd);
+ AOS_LOG(WARNING, "couldn't find whose watch ID %d is\n", notifyevt->wd);
} else {
- LOG(DEBUG, "mask=%" PRIu32 "\n", notifyevt->mask);
+ AOS_LOG(DEBUG, "mask=%" PRIu32 "\n", notifyevt->mask);
// If the watch was removed.
if (notifyevt->mask & IN_IGNORED) {
watchers[notifyevt->wd]->WatchDeleted();
@@ -221,15 +222,15 @@
// INotifyReadable calls this method whenever the watch for our file gets
// removed somehow.
void WatchDeleted() {
- LOG(DEBUG, "watch for %s deleted\n", filename_.c_str());
+ AOS_LOG(DEBUG, "watch for %s deleted\n", filename_.c_str());
RemoveWatchFromMap();
CreateWatch();
}
// INotifyReadable calls this method whenever the watch for our file triggers.
void FileNotified(const char *filename) {
- CHECK_NE(watch_, -1);
- LOG(DEBUG, "got a notification for %s\n", filename_.c_str());
+ AOS_CHECK_NE(watch_, -1);
+ AOS_LOG(DEBUG, "got a notification for %s\n", filename_.c_str());
if (!check_filename_.empty()) {
if (filename == NULL) {
@@ -280,7 +281,7 @@
errno = 0;
FILE *pipe = popen(command.c_str(), "r");
if (pipe == NULL) {
- PLOG(FATAL, "popen(\"%s\", \"r\") failed", command.c_str());
+ AOS_PLOG(FATAL, "popen(\"%s\", \"r\") failed", command.c_str());
}
// result_size is how many bytes result is currently allocated to.
@@ -292,7 +293,7 @@
result_size *= 2;
void *new_result = realloc(result.get(), result_size);
if (new_result == NULL) {
- PLOG(FATAL, "realloc(%p, %zd) failed", result.get(), result_size);
+ AOS_PLOG(FATAL, "realloc(%p, %zd) failed", result.get(), result_size);
} else {
result.release();
result = unique_c_ptr<char>(static_cast<char *>(new_result));
@@ -304,8 +305,8 @@
// because of an error.
if (ret < result_size - read) {
if (ferror(pipe)) {
- PLOG(FATAL, "couldn't finish reading output of \"%s\"\n",
- command.c_str());
+ AOS_PLOG(FATAL, "couldn't finish reading output of \"%s\"\n",
+ command.c_str());
}
}
read += ret;
@@ -314,7 +315,8 @@
}
if (feof(pipe)) {
- LOG(FATAL, "`%s` failed. didn't print a whole line\n", command.c_str());
+ AOS_LOG(FATAL, "`%s` failed. didn't print a whole line\n",
+ command.c_str());
}
}
@@ -323,11 +325,11 @@
int child_status = pclose(pipe);
if (child_status == -1) {
- PLOG(FATAL, "pclose(%p) failed", pipe);
+ AOS_PLOG(FATAL, "pclose(%p) failed", pipe);
}
if (child_status != 0) {
- LOG(FATAL, "`%s` failed. return %d\n", command.c_str(), child_status);
+ AOS_LOG(FATAL, "`%s` failed. return %d\n", command.c_str(), child_status);
}
return std::string(result.get());
@@ -347,8 +349,8 @@
time_timeval.tv_usec = usec.count();
}
if (evtimer_add(timeout.release(), &time_timeval) != 0) {
- LOG(FATAL, "evtimer_add(%p, %p) failed\n", timeout.release(),
- &time_timeval);
+ AOS_LOG(FATAL, "evtimer_add(%p, %p) failed\n", timeout.release(),
+ &time_timeval);
}
}
@@ -399,7 +401,7 @@
monotonic_clock::time_point oldest = restarts_.front();
restarts_.pop();
if (monotonic_clock::now() <= kMaxRestartsTime + oldest) {
- LOG(WARNING, "process %s getting restarted too often\n", name());
+ AOS_LOG(WARNING, "process %s getting restarted too often\n", name());
Timeout(kResumeWait, StaticStart, this);
return;
}
@@ -439,7 +441,7 @@
}
void FileModified() {
- LOG(DEBUG, "file for %s modified\n", name());
+ AOS_LOG(DEBUG, "file for %s modified\n", name());
struct timeval restart_time_timeval;
{
::std::chrono::seconds sec =
@@ -453,14 +455,14 @@
}
// This will reset the timeout again if it hasn't run yet.
if (evtimer_add(restart_timeout.get(), &restart_time_timeval) != 0) {
- LOG(FATAL, "evtimer_add(%p, %p) failed\n", restart_timeout.get(),
- &restart_time_timeval);
+ AOS_LOG(FATAL, "evtimer_add(%p, %p) failed\n", restart_timeout.get(),
+ &restart_time_timeval);
}
waiting_to_restart.insert(this);
}
static void StaticDoRestart(int, short, void *) {
- LOG(DEBUG, "restarting everything that needs it\n");
+ AOS_LOG(DEBUG, "restarting everything that needs it\n");
if (waiting_to_restart.find(core.get()) != waiting_to_restart.end()) {
core->DoRestart();
waiting_to_restart.erase(core.get());
@@ -477,12 +479,12 @@
if (stat_at_start_valid_) {
struct stat current_stat;
if (stat(original_binary_.c_str(), ¤t_stat) == -1) {
- PLOG(FATAL, "stat(%s, %p) failed",
- original_binary_.c_str(), ¤t_stat);
+ AOS_PLOG(FATAL, "stat(%s, %p) failed", original_binary_.c_str(),
+ ¤t_stat);
}
if (current_stat.st_mtime == stat_at_start_.st_mtime) {
- LOG(DEBUG, "ignoring trigger for %s because mtime didn't change\n",
- name());
+ AOS_LOG(DEBUG, "ignoring trigger for %s because mtime didn't change\n",
+ name());
return;
}
}
@@ -492,16 +494,16 @@
exit(0);
}
if (pid_ != -1) {
- LOG(DEBUG, "sending SIGTERM to child %d to restart it\n", pid_);
+ AOS_LOG(DEBUG, "sending SIGTERM to child %d to restart it\n", pid_);
if (kill(pid_, SIGTERM) == -1) {
- PLOG(WARNING, "kill(%d, SIGTERM) failed", pid_);
+ AOS_PLOG(WARNING, "kill(%d, SIGTERM) failed", pid_);
}
CheckDiedStatus *status = new CheckDiedStatus();
status->self = this;
status->old_pid = pid_;
Timeout(kProcessDieTime, StaticCheckDied, status);
} else {
- LOG(WARNING, "%s restart attempted but not running\n", name());
+ AOS_LOG(WARNING, "%s restart attempted but not running\n", name());
}
}
@@ -514,9 +516,9 @@
// Checks to see if the child using the PID old_pid is still running.
void CheckDied(pid_t old_pid) {
if (pid_ == old_pid) {
- LOG(WARNING, "child %d refused to die\n", old_pid);
+ AOS_LOG(WARNING, "child %d refused to die\n", old_pid);
if (kill(old_pid, SIGKILL) == -1) {
- PLOG(WARNING, "kill(%d, SIGKILL) failed", old_pid);
+ AOS_PLOG(WARNING, "kill(%d, SIGKILL) failed", old_pid);
}
}
}
@@ -528,10 +530,10 @@
// Actually starts the child.
void Start() {
if (pid_ != -1) {
- LOG(WARNING, "calling Start() but already have child %d running\n",
- pid_);
+ AOS_LOG(WARNING, "calling Start() but already have child %d running\n",
+ pid_);
if (kill(pid_, SIGKILL) == -1) {
- PLOG(WARNING, "kill(%d, SIGKILL) failed", pid_);
+ AOS_PLOG(WARNING, "kill(%d, SIGKILL) failed", pid_);
return;
}
pid_ = -1;
@@ -540,16 +542,16 @@
// Remove the name that we run from (ie from a previous execution) and then
// hard link the real filename to it.
if (unlink(binary_.c_str()) != 0 && errno != ENOENT) {
- PLOG(FATAL, "removing %s failed", binary_.c_str());
+ AOS_PLOG(FATAL, "removing %s failed", binary_.c_str());
}
if (link(original_binary_.c_str(), binary_.c_str()) != 0) {
- PLOG(FATAL, "link('%s', '%s') failed",
- original_binary_.c_str(), binary_.c_str());
+ AOS_PLOG(FATAL, "link('%s', '%s') failed", original_binary_.c_str(),
+ binary_.c_str());
}
if (stat(original_binary_.c_str(), &stat_at_start_) == -1) {
- PLOG(FATAL, "stat(%s, %p) failed",
- original_binary_.c_str(), &stat_at_start_);
+ AOS_PLOG(FATAL, "stat(%s, %p) failed", original_binary_.c_str(),
+ &stat_at_start_);
}
stat_at_start_valid_ = true;
@@ -563,13 +565,13 @@
// The const_cast is safe because no code that might care if it gets
// modified can run afterwards.
execv(binary_.c_str(), const_cast<char **>(argv));
- PLOG(FATAL, "execv(%s, %p) failed", binary_.c_str(), argv);
+ AOS_PLOG(FATAL, "execv(%s, %p) failed", binary_.c_str(), argv);
_exit(EXIT_FAILURE);
}
if (pid_ == -1) {
- PLOG(FATAL, "forking to run \"%s\" failed", binary_.c_str());
+ AOS_PLOG(FATAL, "forking to run \"%s\" failed", binary_.c_str());
}
- LOG(DEBUG, "started \"%s\" successfully\n", binary_.c_str());
+ AOS_LOG(DEBUG, "started \"%s\" successfully\n", binary_.c_str());
}
// A history of the times that this process has been restarted.
@@ -672,7 +674,7 @@
siginfo_t infop;
infop.si_pid = 0;
if (waitid(P_ALL, 0, &infop, WEXITED | WSTOPPED | WNOHANG) != 0) {
- PLOG(WARNING, "waitid failed");
+ AOS_PLOG(WARNING, "waitid failed");
continue;
}
// If there are no more child process deaths to process.
@@ -686,38 +688,41 @@
if (child) {
switch (infop.si_code) {
case CLD_EXITED:
- LOG(WARNING, "child %d (%s) exited with status %d\n",
- pid, child->name(), status);
+ AOS_LOG(WARNING, "child %d (%s) exited with status %d\n", pid,
+ child->name(), status);
break;
case CLD_DUMPED:
- LOG(INFO, "child %d actually dumped core. "
- "falling through to killed by signal case\n", pid);
+ AOS_LOG(INFO,
+ "child %d actually dumped core. "
+ "falling through to killed by signal case\n",
+ pid);
case CLD_KILLED:
// If somebody (possibly us) sent it SIGTERM that means that they just
// want it to stop, so it stopping isn't a WARNING.
- LOG((status == SIGTERM) ? DEBUG : WARNING,
- "child %d (%s) was killed by signal %d (%s)\n",
- pid, child->name(), status, aos_strsignal(status));
+ AOS_LOG((status == SIGTERM) ? DEBUG : WARNING,
+ "child %d (%s) was killed by signal %d (%s)\n", pid,
+ child->name(), status, aos_strsignal(status));
break;
case CLD_STOPPED:
- LOG(WARNING, "child %d (%s) was stopped by signal %d "
- "(giving it a SIGCONT(%d))\n",
- pid, child->name(), status, SIGCONT);
+ AOS_LOG(WARNING,
+ "child %d (%s) was stopped by signal %d "
+ "(giving it a SIGCONT(%d))\n",
+ pid, child->name(), status, SIGCONT);
kill(pid, SIGCONT);
continue;
default:
- LOG(WARNING, "something happened to child %d (%s) (killing it)\n",
- pid, child->name());
+ AOS_LOG(WARNING, "something happened to child %d (%s) (killing it)\n",
+ pid, child->name());
kill(pid, SIGKILL);
continue;
}
} else {
- LOG(WARNING, "couldn't find a Child for pid %d\n", pid);
+ AOS_LOG(WARNING, "couldn't find a Child for pid %d\n", pid);
return;
}
if (child == core) {
- LOG(FATAL, "core died\n");
+ AOS_LOG(FATAL, "core died\n");
}
child->ProcessDied();
}
@@ -736,12 +741,12 @@
// fail due to lack of permissions if we do not manually set the UID to admin.
#ifdef AOS_ARCHITECTURE_arm_frc
if (setuid(0) != 0) {
- PLOG(FATAL, "setuid(0) failed");
+ AOS_PLOG(FATAL, "setuid(0) failed");
}
#endif
if (setpgid(0 /*self*/, 0 /*make PGID the same as PID*/) != 0) {
- PLOG(FATAL, "setpgid(0, 0) failed");
+ AOS_PLOG(FATAL, "setpgid(0, 0) failed");
}
// Make sure that we kill all children when we exit.
@@ -765,7 +770,7 @@
// will never use, and the roboRIO doesn't have enough RAM to handle it.
// This is in here instead of starter.sh because starter.sh doesn't run with
// permissions on a roboRIO.
- CHECK(system("echo 0 > /proc/sys/vm/overcommit_memory") == 0);
+ AOS_CHECK(system("echo 0 > /proc/sys/vm/overcommit_memory") == 0);
#endif
libevent_base = EventBaseUniquePtr(event_base_new());
@@ -776,10 +781,10 @@
const int result =
::aos::util::RunCommand(("touch '" + core_touch_file + "'").c_str());
if (result == -1) {
- PLOG(FATAL, "running `touch '%s'` failed\n", core_touch_file.c_str());
+ AOS_PLOG(FATAL, "running `touch '%s'` failed\n", core_touch_file.c_str());
} else if (!WIFEXITED(result) || WEXITSTATUS(result) != 0) {
- LOG(FATAL, "`touch '%s'` gave result %x\n", core_touch_file.c_str(),
- result);
+ AOS_LOG(FATAL, "`touch '%s'` gave result %x\n", core_touch_file.c_str(),
+ result);
}
FileWatch core_touch_file_watch(core_touch_file, Run, NULL);
core = unique_ptr<Child>(
@@ -787,19 +792,19 @@
FILE *pid_file = fopen("/tmp/starter.pid", "w");
if (pid_file == NULL) {
- PLOG(FATAL, "fopen(\"/tmp/starter.pid\", \"w\") failed");
+ AOS_PLOG(FATAL, "fopen(\"/tmp/starter.pid\", \"w\") failed");
} else {
if (fprintf(pid_file, "%d", core->pid()) == -1) {
- PLOG(WARNING, "fprintf(%p, \"%%d\", %d) failed",
- pid_file, core->pid());
+ AOS_PLOG(WARNING, "fprintf(%p, \"%%d\", %d) failed", pid_file,
+ core->pid());
}
fclose(pid_file);
}
- LOG(INFO, "waiting for %s to appear\n", core_touch_file.c_str());
+ AOS_LOG(INFO, "waiting for %s to appear\n", core_touch_file.c_str());
event_base_dispatch(libevent_base.get());
- LOG(FATAL, "event_base_dispatch(%p) returned\n", libevent_base.get());
+ AOS_LOG(FATAL, "event_base_dispatch(%p) returned\n", libevent_base.get());
}
// This is the callback for when core creates the file indicating that it has
@@ -820,7 +825,7 @@
break;
}
if (list_file.rdstate() != 0) {
- LOG(FATAL, "reading input file %s failed\n", child_list_file);
+ AOS_LOG(FATAL, "reading input file %s failed\n", child_list_file);
}
children.push_back(unique_ptr<Child>(new Child(child_name)));
}
diff --git a/aos/stl_mutex/stl_mutex.h b/aos/stl_mutex/stl_mutex.h
index b88ac8e..4e14557 100644
--- a/aos/stl_mutex/stl_mutex.h
+++ b/aos/stl_mutex/stl_mutex.h
@@ -31,7 +31,7 @@
owner_died_ = true;
break;
default:
- LOG(FATAL, "mutex_grab(%p) failed with %d\n", &native_handle_, ret);
+ AOS_LOG(FATAL, "mutex_grab(%p) failed with %d\n", &native_handle_, ret);
}
}
@@ -46,12 +46,13 @@
case 4:
return false;
default:
- LOG(FATAL, "mutex_trylock(%p) failed with %d\n", &native_handle_, ret);
+ AOS_LOG(FATAL, "mutex_trylock(%p) failed with %d\n", &native_handle_,
+ ret);
}
}
void unlock() {
- CHECK(!owner_died_);
+ AOS_CHECK(!owner_died_);
mutex_unlock(&native_handle_);
}
@@ -83,20 +84,20 @@
void lock() {
if (mutex_islocked(mutex_.native_handle())) {
- CHECK(!owner_died());
+ AOS_CHECK(!owner_died());
++recursive_locks_;
} else {
mutex_.lock();
if (mutex_.owner_died()) {
recursive_locks_ = 0;
} else {
- CHECK_EQ(0, recursive_locks_);
+ AOS_CHECK_EQ(0, recursive_locks_);
}
}
}
bool try_lock() {
if (mutex_islocked(mutex_.native_handle())) {
- CHECK(!owner_died());
+ AOS_CHECK(!owner_died());
++recursive_locks_;
return true;
} else {
@@ -104,7 +105,7 @@
if (mutex_.owner_died()) {
recursive_locks_ = 0;
} else {
- CHECK_EQ(0, recursive_locks_);
+ AOS_CHECK_EQ(0, recursive_locks_);
}
return true;
} else {
diff --git a/aos/testing/prevent_exit.cc b/aos/testing/prevent_exit.cc
index 3190698..ed6644b 100644
--- a/aos/testing/prevent_exit.cc
+++ b/aos/testing/prevent_exit.cc
@@ -16,7 +16,7 @@
} // namespace
void PreventExit() {
- CHECK_EQ(atexit(TerminateExitHandler), 0);
+ AOS_CHECK_EQ(atexit(TerminateExitHandler), 0);
}
} // namespace testing
diff --git a/aos/testing/test_logging_test.cc b/aos/testing/test_logging_test.cc
index 9dd6eba..f39c6cf 100644
--- a/aos/testing/test_logging_test.cc
+++ b/aos/testing/test_logging_test.cc
@@ -16,11 +16,11 @@
::std::thread thread([]() {
for (int i = 0; i < 1000; ++i) {
- LOG(INFO, "test from thread\n");
+ AOS_LOG(INFO, "test from thread\n");
}
});
for (int i = 0; i < 1000; ++i) {
- LOG(INFO, "not from thread\n");
+ AOS_LOG(INFO, "not from thread\n");
}
thread.join();
}
diff --git a/aos/testing/test_shm.cc b/aos/testing/test_shm.cc
index f7ddfcb..e9a637a 100644
--- a/aos/testing/test_shm.cc
+++ b/aos/testing/test_shm.cc
@@ -22,7 +22,7 @@
// "shared" memory.
void *memory = mmap(NULL, kCoreSize, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- CHECK_NE(memory, MAP_FAILED);
+ AOS_CHECK_NE(memory, MAP_FAILED);
aos_core_use_address_as_shared_mem(memory, kCoreSize);
@@ -30,7 +30,7 @@
}
TestSharedMemory::~TestSharedMemory() {
- PCHECK(munmap(global_core->mem_struct, kCoreSize));
+ AOS_PCHECK(munmap(global_core->mem_struct, kCoreSize));
global_core = NULL;
}
diff --git a/aos/time/BUILD b/aos/time/BUILD
index 6570490..e08ef7b 100644
--- a/aos/time/BUILD
+++ b/aos/time/BUILD
@@ -12,9 +12,9 @@
deps = [
"//aos:macros",
"//aos/ipc_lib:shared_mem",
- "//aos/logging",
"//aos/mutex",
"//aos/type_traits",
+ "@com_github_google_glog//:glog",
],
)
diff --git a/aos/time/time.cc b/aos/time/time.cc
index 7661daf..9736009 100644
--- a/aos/time/time.cc
+++ b/aos/time/time.cc
@@ -12,8 +12,8 @@
// dependency on it.
#include "aos/ipc_lib/shared_mem.h"
-#include "aos/logging/logging.h"
#include "aos/mutex/mutex.h"
+#include "glog/logging.h"
#else // __linux__
@@ -45,10 +45,9 @@
do {
returnval = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
&end_time_timespec, nullptr);
- if (returnval != EINTR && returnval != 0) {
- PLOG(FATAL, "clock_nanosleep(%jd, TIMER_ABSTIME, %p, nullptr) failed",
- static_cast<uintmax_t>(CLOCK_MONOTONIC), &end_time_timespec);
- }
+ PCHECK(returnval == 0 || returnval == EINTR)
+ << ": clock_nanosleep(" << static_cast<uintmax_t>(CLOCK_MONOTONIC)
+ << ", TIMER_ABSTIME, " << &end_time_timespec << ", nullptr) failed";
} while (returnval != 0);
}
@@ -93,9 +92,8 @@
void SetMockTime(monotonic_clock::time_point now) {
MutexLocker time_mutex_locker(&time_mutex);
- if (__builtin_expect(!mock_time_enabled, 0)) {
- LOG(FATAL, "Tried to set mock time and mock time is not enabled\n");
- }
+ CHECK(mock_time_enabled)
+ << ": Tried to set mock time and mock time is not enabled";
current_mock_time = now;
}
@@ -148,10 +146,10 @@
}
struct timespec current_time;
- if (clock_gettime(CLOCK_MONOTONIC, ¤t_time) != 0) {
- PLOG(FATAL, "clock_gettime(%jd, %p) failed",
- static_cast<uintmax_t>(CLOCK_MONOTONIC), ¤t_time);
- }
+ PCHECK(clock_gettime(CLOCK_MONOTONIC, ¤t_time) == 0)
+ << ": clock_gettime(" << static_cast<uintmax_t>(CLOCK_MONOTONIC) << ", "
+ << ¤t_time << ") failed";
+
const chrono::nanoseconds offset =
(&global_core == nullptr || global_core == nullptr ||
global_core->mem_struct == nullptr)
@@ -191,10 +189,9 @@
#ifdef __linux__
realtime_clock::time_point realtime_clock::now() noexcept {
struct timespec current_time;
- if (clock_gettime(CLOCK_REALTIME, ¤t_time) != 0) {
- PLOG(FATAL, "clock_gettime(%jd, %p) failed",
- static_cast<uintmax_t>(CLOCK_REALTIME), ¤t_time);
- }
+ PCHECK(clock_gettime(CLOCK_REALTIME, ¤t_time) == 0)
+ << "clock_gettime(" << static_cast<uintmax_t>(CLOCK_REALTIME) << ", "
+ << ¤t_time << ") failed";
return time_point(::std::chrono::seconds(current_time.tv_sec) +
::std::chrono::nanoseconds(current_time.tv_nsec));
diff --git a/aos/transaction/transaction.h b/aos/transaction/transaction.h
index f1c5c02..e0266f9 100644
--- a/aos/transaction/transaction.h
+++ b/aos/transaction/transaction.h
@@ -55,7 +55,7 @@
template <class... A>
void AddWork(A &&... a) {
if (stack_index_ >= number_works) {
- LOG(FATAL, "too many works\n");
+ AOS_LOG(FATAL, "too many works\n");
}
stack_.at(stack_index_).Create(::std::forward<A>(a)...);
aos_compiler_memory_barrier();
diff --git a/aos/util/BUILD b/aos/util/BUILD
index be6055d..f18fd82 100644
--- a/aos/util/BUILD
+++ b/aos/util/BUILD
@@ -113,6 +113,7 @@
deps = [
"//aos/logging",
"//aos/time",
+ "@com_github_google_glog//:glog",
],
)
diff --git a/aos/util/file.cc b/aos/util/file.cc
index 9c81b3e..5418aab 100644
--- a/aos/util/file.cc
+++ b/aos/util/file.cc
@@ -14,15 +14,15 @@
::std::string r;
ScopedFD fd(open(::std::string(filename).c_str(), O_RDONLY));
if (fd.get() == -1) {
- PLOG(FATAL, "opening %*s", static_cast<int>(filename.size()),
- filename.data());
+ AOS_PLOG(FATAL, "opening %*s", static_cast<int>(filename.size()),
+ filename.data());
}
while (true) {
char buffer[1024];
const ssize_t result = read(fd.get(), buffer, sizeof(buffer));
if (result < 0) {
- PLOG(FATAL, "reading from %*s", static_cast<int>(filename.size()),
- filename.data());
+ AOS_PLOG(FATAL, "reading from %*s", static_cast<int>(filename.size()),
+ filename.data());
} else if (result == 0) {
break;
}
diff --git a/aos/util/linked_list.h b/aos/util/linked_list.h
index 5a5824e..14f1788 100644
--- a/aos/util/linked_list.h
+++ b/aos/util/linked_list.h
@@ -64,7 +64,7 @@
}
pointer = &(*pointer)->next;
}
- LOG(FATAL, "%p is not in the list\n", t);
+ AOS_LOG(FATAL, "%p is not in the list\n", t);
}
// Calls function for each element of the list.
diff --git a/aos/util/log_interval.h b/aos/util/log_interval.h
index acd32e8..54ebd6d 100644
--- a/aos/util/log_interval.h
+++ b/aos/util/log_interval.h
@@ -66,7 +66,7 @@
const ::std::string &message)
: interval_(interval), level_(level), message_(message) {}
-#define LOG_INTERVAL(simple_log) \
+#define AOS_LOG_INTERVAL(simple_log) \
simple_log.WantToLog(LOG_SOURCENAME ": " STRINGIFY(__LINE__))
void WantToLog(const char *context) {
context_ = context;
@@ -75,7 +75,7 @@
void Print() {
if (interval_.ShouldLog()) {
- CHECK_NOTNULL(context_);
+ AOS_CHECK_NOTNULL(context_);
log_do(level_, "%s: %.*s %d times over %f sec\n", context_,
static_cast<int>(message_.size()), message_.data(),
interval_.Count(),
diff --git a/aos/util/phased_loop.cc b/aos/util/phased_loop.cc
index a349718..7369a93 100644
--- a/aos/util/phased_loop.cc
+++ b/aos/util/phased_loop.cc
@@ -1,8 +1,41 @@
#include "aos/util/phased_loop.h"
+#include "glog/logging.h"
+
namespace aos {
namespace time {
+PhasedLoop::PhasedLoop(const monotonic_clock::duration interval,
+ const monotonic_clock::time_point monotonic_now,
+ const monotonic_clock::duration offset)
+ : interval_(interval), offset_(offset), last_time_(offset) {
+ CHECK(offset >= monotonic_clock::duration(0));
+ CHECK(interval > monotonic_clock::duration(0));
+ CHECK(offset < interval);
+ Reset(monotonic_now);
+}
+
+void PhasedLoop::set_interval_and_offset(
+ const monotonic_clock::duration interval,
+ const monotonic_clock::duration offset) {
+ interval_ = interval;
+ offset_ = offset;
+ CHECK(offset_ >= monotonic_clock::duration(0));
+ CHECK(interval_ > monotonic_clock::duration(0));
+ CHECK(offset_ < interval_);
+}
+
+monotonic_clock::duration PhasedLoop::OffsetFromIntervalAndTime(
+ const monotonic_clock::duration interval,
+ const monotonic_clock::time_point monotonic_trigger) {
+ CHECK(interval > monotonic_clock::duration(0));
+ return monotonic_trigger.time_since_epoch() -
+ (monotonic_trigger.time_since_epoch() / interval) * interval +
+ ((monotonic_trigger.time_since_epoch() >= monotonic_clock::zero())
+ ? monotonic_clock::zero()
+ : interval);
+}
+
int PhasedLoop::Iterate(const monotonic_clock::time_point now) {
const monotonic_clock::time_point next_time =
monotonic_clock::time_point(
@@ -17,8 +50,8 @@
const int result = difference / interval_;
CHECK_EQ(
0, (next_time - offset_).time_since_epoch().count() % interval_.count());
- CHECK_GE(next_time, now);
- CHECK_LE(next_time - now, interval_);
+ CHECK(next_time >= now);
+ CHECK(next_time - now <= interval_);
last_time_ = next_time;
return result;
}
diff --git a/aos/util/phased_loop.h b/aos/util/phased_loop.h
index 7aa51d2..3e1752b 100644
--- a/aos/util/phased_loop.h
+++ b/aos/util/phased_loop.h
@@ -3,8 +3,6 @@
#include "aos/time/time.h"
-#include "aos/logging/logging.h"
-
namespace aos {
namespace time {
@@ -20,35 +18,16 @@
PhasedLoop(
const monotonic_clock::duration interval,
const monotonic_clock::time_point monotonic_now,
- const monotonic_clock::duration offset = monotonic_clock::duration(0))
- : interval_(interval), offset_(offset), last_time_(offset) {
- CHECK_GE(offset, monotonic_clock::duration(0));
- CHECK_GT(interval, monotonic_clock::duration(0));
- CHECK_LT(offset, interval);
- Reset(monotonic_now);
- }
+ const monotonic_clock::duration offset = monotonic_clock::duration(0));
// Updates the offset and interval.
void set_interval_and_offset(const monotonic_clock::duration interval,
- const monotonic_clock::duration offset) {
- interval_ = interval;
- offset_ = offset;
- CHECK_GE(offset_, monotonic_clock::duration(0));
- CHECK_GT(interval_, monotonic_clock::duration(0));
- CHECK_LT(offset_, interval_);
- }
+ const monotonic_clock::duration offset);
// Computes the offset given an interval and a time that we should trigger.
static monotonic_clock::duration OffsetFromIntervalAndTime(
const monotonic_clock::duration interval,
- const monotonic_clock::time_point monotonic_trigger) {
- CHECK_GT(interval, monotonic_clock::duration(0));
- return monotonic_trigger.time_since_epoch() -
- (monotonic_trigger.time_since_epoch() / interval) * interval +
- ((monotonic_trigger.time_since_epoch() >= monotonic_clock::zero())
- ? monotonic_clock::zero()
- : interval);
- }
+ const monotonic_clock::time_point monotonic_trigger);
// Resets the count of skipped iterations.
// Iterate(monotonic_now) will return 1 and set sleep_time() to something
diff --git a/aos/util/phased_loop_test.cc b/aos/util/phased_loop_test.cc
index 4f07bcc..0a0d5db 100644
--- a/aos/util/phased_loop_test.cc
+++ b/aos/util/phased_loop_test.cc
@@ -183,16 +183,16 @@
TEST_F(PhasedLoopDeathTest, InvalidValues) {
EXPECT_DEATH(
PhasedLoop(milliseconds(1), monotonic_clock::epoch(), milliseconds(2)),
- ".*offset<interval.*");
+ ".*offset < interval.*");
EXPECT_DEATH(
PhasedLoop(milliseconds(1), monotonic_clock::epoch(), milliseconds(1)),
- ".*offset<interval.*");
+ ".*offset < interval.*");
EXPECT_DEATH(
PhasedLoop(milliseconds(1), monotonic_clock::epoch(), milliseconds(-1)),
- ".*offset>=monotonic_clock::duration\\(0\\).*");
+ ".*offset >= monotonic_clock::duration\\(0\\).*");
EXPECT_DEATH(
PhasedLoop(milliseconds(0), monotonic_clock::epoch(), milliseconds(0)),
- ".*interval>monotonic_clock::duration\\(0\\).*");
+ ".*interval > monotonic_clock::duration\\(0\\).*");
}
} // namespace testing
diff --git a/aos/util/run_command.cc b/aos/util/run_command.cc
index 2b08cb2..40782da 100644
--- a/aos/util/run_command.cc
+++ b/aos/util/run_command.cc
@@ -21,14 +21,14 @@
sigemptyset(&to_block);
sigaddset(&to_block, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &to_block, &original_blocked_) == -1) {
- PLOG(FATAL, "sigprocmask(SIG_BLOCK, %p, %p) failed",
- &to_block, &original_blocked_);
+ AOS_PLOG(FATAL, "sigprocmask(SIG_BLOCK, %p, %p) failed", &to_block,
+ &original_blocked_);
}
}
~BlockSIGCHLD() {
if (sigprocmask(SIG_SETMASK, &original_blocked_, nullptr) == -1) {
- PLOG(FATAL, "sigprocmask(SIG_SETMASK, %p, nullptr) failed",
- &original_blocked_);
+ AOS_PLOG(FATAL, "sigprocmask(SIG_SETMASK, %p, nullptr) failed",
+ &original_blocked_);
}
}
diff --git a/aos/util/thread.cc b/aos/util/thread.cc
index 6b3ef76..ae18fe9 100644
--- a/aos/util/thread.cc
+++ b/aos/util/thread.cc
@@ -11,24 +11,24 @@
Thread::Thread() : started_(false), joined_(false), should_terminate_(false) {}
Thread::~Thread() {
- CHECK(!(started_ && !joined_));
+ AOS_CHECK(!(started_ && !joined_));
}
void Thread::Start() {
- CHECK(!started_);
+ AOS_CHECK(!started_);
started_ = true;
- CHECK(pthread_create(&thread_, NULL, &Thread::StaticRun, this) == 0);
+ AOS_CHECK(pthread_create(&thread_, NULL, &Thread::StaticRun, this) == 0);
}
void Thread::Join() {
- CHECK(!joined_ && started_);
+ AOS_CHECK(!joined_ && started_);
joined_ = true;
should_terminate_.store(true);
- CHECK(pthread_join(thread_, NULL) == 0);
+ AOS_CHECK(pthread_join(thread_, NULL) == 0);
}
bool Thread::TryJoin() {
- CHECK(!joined_ && started_);
+ AOS_CHECK(!joined_ && started_);
#ifdef AOS_SANITIZER_thread
// ThreadSanitizer misses the tryjoin and then complains about leaking the
// thread. Instead, we'll just check if the thread is still around and then
@@ -39,7 +39,7 @@
if (kill_ret == 0) return false;
// If it died, we'll get ESRCH. Otherwise, something went wrong.
if (kill_ret != ESRCH) {
- PELOG(FATAL, kill_ret, "pthread_kill(thread_, 0) failed");
+ AOS_PELOG(FATAL, kill_ret, "pthread_kill(thread_, 0) failed");
}
Join();
return true;
@@ -51,20 +51,20 @@
} else if (ret == EBUSY) {
return false;
} else {
- PELOG(FATAL, ret, "pthread_tryjoin_np(thread_, nullptr) failed");
+ AOS_PELOG(FATAL, ret, "pthread_tryjoin_np(thread_, nullptr) failed");
}
#endif
}
void Thread::RequestStop() {
- CHECK(!joined_ && started_);
+ AOS_CHECK(!joined_ && started_);
should_terminate_.store(true);
}
void Thread::WaitUntilDone() {
- CHECK(!joined_ && started_);
+ AOS_CHECK(!joined_ && started_);
joined_ = true;
- CHECK(pthread_join(thread_, NULL) == 0);
+ AOS_CHECK(pthread_join(thread_, NULL) == 0);
}
void *Thread::StaticRun(void *self) {
diff --git a/aos/util/trapezoid_profile.cc b/aos/util/trapezoid_profile.cc
index a1e8abb..e74110f 100644
--- a/aos/util/trapezoid_profile.cc
+++ b/aos/util/trapezoid_profile.cc
@@ -108,7 +108,7 @@
acceleration_time_ = (top_velocity - output_(1)) / acceleration_;
}
- CHECK_GT(top_velocity, -maximum_velocity_);
+ AOS_CHECK_GT(top_velocity, -maximum_velocity_);
if (output_(1) > maximum_velocity_) {
constant_time_ = 0;
diff --git a/aos/vision/blob/threshold.cc b/aos/vision/blob/threshold.cc
index 46221b5..047d8db 100644
--- a/aos/vision/blob/threshold.cc
+++ b/aos/vision/blob/threshold.cc
@@ -14,7 +14,7 @@
// it operates in kChunkSize-pixel chunks.
RangeImage FastYuyvYThreshold(ImageFormat fmt, const char *data,
uint8_t value) {
- CHECK_EQ(0, fmt.w % kChunkSize);
+ AOS_CHECK_EQ(0, fmt.w % kChunkSize);
std::vector<std::vector<ImageRange>> result;
result.reserve(fmt.h);
@@ -107,7 +107,7 @@
}
ImageFormat shard_format = input_format_;
- CHECK_EQ(shard_format.h % kThreads, 0);
+ AOS_CHECK_EQ(shard_format.h % kThreads, 0);
shard_format.h /= kThreads;
outputs_[i] = FastYuyvYThreshold(
diff --git a/aos/vision/events/epoll_events.cc b/aos/vision/events/epoll_events.cc
index f6cba76..651579a 100644
--- a/aos/vision/events/epoll_events.cc
+++ b/aos/vision/events/epoll_events.cc
@@ -14,29 +14,29 @@
void EpollEvent::DirectEvent(uint32_t events) {
if ((events & ~(EPOLLIN | EPOLLPRI | EPOLLERR)) != 0) {
- LOG(FATAL, "unexpected epoll events set in %x on %d\n", events, fd());
+ AOS_LOG(FATAL, "unexpected epoll events set in %x on %d\n", events, fd());
}
ReadEvent();
}
void EpollEvent::SetEvents(uint32_t events) {
events_ |= events;
- CHECK(!loop_);
+ AOS_CHECK(!loop_);
}
-EpollLoop::EpollLoop() : epoll_fd_(PCHECK(epoll_create1(0))) {}
+EpollLoop::EpollLoop() : epoll_fd_(AOS_PCHECK(epoll_create1(0))) {}
void EpollLoop::Add(EpollEvent *event) {
event->loop_ = this;
struct epoll_event temp_event;
temp_event.data.ptr = static_cast<void *>(event);
temp_event.events = event->events();
- PCHECK(epoll_ctl(epoll_fd(), EPOLL_CTL_ADD, event->fd(), &temp_event));
+ AOS_PCHECK(epoll_ctl(epoll_fd(), EPOLL_CTL_ADD, event->fd(), &temp_event));
}
void EpollLoop::Delete(EpollEvent *event) {
event->loop_ = nullptr;
- PCHECK(epoll_ctl(epoll_fd(), EPOLL_CTL_DEL, event->fd(), NULL));
+ AOS_PCHECK(epoll_ctl(epoll_fd(), EPOLL_CTL_DEL, event->fd(), NULL));
}
void EpollLoop::Run() {
@@ -45,7 +45,7 @@
static constexpr size_t kNumberOfEvents = 64;
epoll_event events[kNumberOfEvents];
const int number_events =
- PCHECK(epoll_wait(epoll_fd(), events, kNumberOfEvents, timeout));
+ AOS_PCHECK(epoll_wait(epoll_fd(), events, kNumberOfEvents, timeout));
for (int i = 0; i < number_events; i++) {
static_cast<EpollEvent *>(events[i].data.ptr)->DirectEvent(events[i].events);
diff --git a/aos/vision/events/gtk_event.cc b/aos/vision/events/gtk_event.cc
index 4ff9fde..d1f60a1 100644
--- a/aos/vision/events/gtk_event.cc
+++ b/aos/vision/events/gtk_event.cc
@@ -27,8 +27,8 @@
for (int i = 0; i < number_events; i++) {
EpollEvent *event = static_cast<EpollEvent *>(events[i].data.ptr);
if ((events[i].events & ~(EPOLLIN | EPOLLPRI)) != 0) {
- LOG(FATAL, "unexpected epoll events set in %x on %d\n",
- events[i].events, event->fd());
+ AOS_LOG(FATAL, "unexpected epoll events set in %x on %d\n",
+ events[i].events, event->fd());
}
event->ReadEvent();
}
diff --git a/aos/vision/events/tcp_client.cc b/aos/vision/events/tcp_client.cc
index 8e197ec..94fa3d2 100644
--- a/aos/vision/events/tcp_client.cc
+++ b/aos/vision/events/tcp_client.cc
@@ -22,10 +22,10 @@
int MakeSocketNonBlocking(int sfd) {
int flags;
- PCHECK(flags = fcntl(sfd, F_GETFL, 0));
+ AOS_PCHECK(flags = fcntl(sfd, F_GETFL, 0));
flags |= O_NONBLOCK;
- PCHECK(fcntl(sfd, F_SETFL, flags));
+ AOS_PCHECK(fcntl(sfd, F_SETFL, flags));
return 0;
}
@@ -35,7 +35,7 @@
struct sockaddr_in serveraddr;
struct hostent *server;
/* socket: create the socket */
- PCHECK(sockfd = socket(AF_INET, SOCK_STREAM, 0));
+ AOS_PCHECK(sockfd = socket(AF_INET, SOCK_STREAM, 0));
/* gethostbyname: get the server's DNS entry */
server = gethostbyname(hostname.c_str());
@@ -52,9 +52,9 @@
serveraddr.sin_port = htons(portno);
/* connect: create a connection with the server */
- PCHECK(connect(sockfd, (const struct sockaddr *)&serveraddr,
- sizeof(serveraddr)));
- PCHECK(MakeSocketNonBlocking(sockfd));
+ AOS_PCHECK(connect(sockfd, (const struct sockaddr *)&serveraddr,
+ sizeof(serveraddr)));
+ AOS_PCHECK(MakeSocketNonBlocking(sockfd));
return sockfd;
}
diff --git a/aos/vision/events/tcp_server.cc b/aos/vision/events/tcp_server.cc
index 0fd7225..535c6b4 100644
--- a/aos/vision/events/tcp_server.cc
+++ b/aos/vision/events/tcp_server.cc
@@ -23,10 +23,10 @@
int MakeSocketNonBlocking(int sfd) {
int flags;
- PCHECK(flags = fcntl(sfd, F_GETFL, 0));
+ AOS_PCHECK(flags = fcntl(sfd, F_GETFL, 0));
flags |= O_NONBLOCK;
- PCHECK(fcntl(sfd, F_SETFL, flags));
+ AOS_PCHECK(fcntl(sfd, F_SETFL, flags));
return 0;
}
@@ -41,7 +41,7 @@
/*
* socket: create the parent socket
*/
- PCHECK(parentfd = socket(AF_INET, SOCK_STREAM, 0));
+ AOS_PCHECK(parentfd = socket(AF_INET, SOCK_STREAM, 0));
/* setsockopt: Handy debugging trick that lets
* us rerun the server immediately after we kill it;
@@ -49,8 +49,8 @@
* Eliminates "ERROR on binding: Address already in use" error.
*/
optval = 1;
- PCHECK(setsockopt(parentfd, SOL_SOCKET, SO_REUSEADDR, (const void *)&optval,
- sizeof(int)));
+ AOS_PCHECK(setsockopt(parentfd, SOL_SOCKET, SO_REUSEADDR,
+ (const void *)&optval, sizeof(int)));
/*
* build the server's Internet address
@@ -69,11 +69,12 @@
/*
* bind: associate the parent socket with a port
*/
- PCHECK(bind(parentfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)));
+ AOS_PCHECK(
+ bind(parentfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)));
- PCHECK(listen(parentfd, SOMAXCONN));
+ AOS_PCHECK(listen(parentfd, SOMAXCONN));
- LOG(INFO, "connected to port: %d on fd: %d\n", portno, parentfd);
+ AOS_LOG(INFO, "connected to port: %d on fd: %d\n", portno, parentfd);
return parentfd;
}
@@ -94,14 +95,14 @@
connections. */
return;
} else {
- PLOG(WARNING, "accept");
+ AOS_PLOG(WARNING, "accept");
return;
}
}
/* Make the incoming socket non-blocking and add it to the
list of fds to monitor. */
- PCHECK(MakeSocketNonBlocking(infd));
+ AOS_PCHECK(MakeSocketNonBlocking(infd));
loop()->Add(Construct(infd));
}
diff --git a/aos/vision/events/udp.cc b/aos/vision/events/udp.cc
index ed39db9..8734443 100644
--- a/aos/vision/events/udp.cc
+++ b/aos/vision/events/udp.cc
@@ -8,17 +8,17 @@
namespace events {
TXUdpSocket::TXUdpSocket(const std::string &ip_addr, int port)
- : fd_(PCHECK(socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))) {
+ : fd_(AOS_PCHECK(socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))) {
sockaddr_in destination_in;
memset(&destination_in, 0, sizeof(destination_in));
destination_in.sin_family = AF_INET;
destination_in.sin_port = htons(port);
if (inet_aton(ip_addr.c_str(), &destination_in.sin_addr) == 0) {
- LOG(FATAL, "invalid IP address %s\n", ip_addr.c_str());
+ AOS_LOG(FATAL, "invalid IP address %s\n", ip_addr.c_str());
}
- PCHECK(connect(fd_.get(), reinterpret_cast<sockaddr *>(&destination_in),
- sizeof(destination_in)));
+ AOS_PCHECK(connect(fd_.get(), reinterpret_cast<sockaddr *>(&destination_in),
+ sizeof(destination_in)));
}
int TXUdpSocket::Send(const char *data, int size) {
@@ -27,7 +27,7 @@
}
int RXUdpSocket::SocketBindListenOnPort(int port) {
- int fd = PCHECK(socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP));
+ int fd = AOS_PCHECK(socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP));
sockaddr_in bind_address;
memset(&bind_address, 0, sizeof(bind_address));
@@ -35,15 +35,15 @@
bind_address.sin_port = htons(port);
bind_address.sin_addr.s_addr = htonl(INADDR_ANY);
- PCHECK(bind(fd, reinterpret_cast<sockaddr *>(&bind_address),
- sizeof(bind_address)));
+ AOS_PCHECK(bind(fd, reinterpret_cast<sockaddr *>(&bind_address),
+ sizeof(bind_address)));
return fd;
}
RXUdpSocket::RXUdpSocket(int port) : fd_(SocketBindListenOnPort(port)) {}
int RXUdpSocket::Recv(void *data, int size) {
- return PCHECK(recv(fd_.get(), static_cast<char *>(data), size, 0));
+ return AOS_PCHECK(recv(fd_.get(), static_cast<char *>(data), size, 0));
}
} // namespace events
diff --git a/aos/vision/image/image_stream.cc b/aos/vision/image/image_stream.cc
index 1dba674..62f5e81 100644
--- a/aos/vision/image/image_stream.cc
+++ b/aos/vision/image/image_stream.cc
@@ -8,7 +8,7 @@
void ImageStreamEvent::ProcessHelper(
DataRef data, aos::monotonic_clock::time_point timestamp) {
if (data.size() < 300) {
- LOG(INFO, "got bad img of size(%d)\n", static_cast<int>(data.size()));
+ AOS_LOG(INFO, "got bad img of size(%d)\n", static_cast<int>(data.size()));
return;
}
ProcessImage(data, timestamp);
diff --git a/aos/vision/image/jpeg_routines.cc b/aos/vision/image/jpeg_routines.cc
index 237daff..507fb3b 100644
--- a/aos/vision/image/jpeg_routines.cc
+++ b/aos/vision/image/jpeg_routines.cc
@@ -66,7 +66,7 @@
int nsymbols = 0;
for (int len = 1; len <= 16; len++) nsymbols += bits[len];
if (nsymbols < 1 || nsymbols > 256) {
- LOG(FATAL, "%s:%d: Error, bad huffman table", __FILE__, __LINE__);
+ AOS_LOG(FATAL, "%s:%d: Error, bad huffman table", __FILE__, __LINE__);
}
memcpy((*htblptr)->huffval, val, nsymbols * sizeof(uint8_t));
diff --git a/aos/vision/image/reader.cc b/aos/vision/image/reader.cc
index 991339b..7584369 100644
--- a/aos/vision/image/reader.cc
+++ b/aos/vision/image/reader.cc
@@ -42,15 +42,15 @@
: dev_name_(dev_name), process_(std::move(process)), params_(params) {
struct stat st;
if (stat(dev_name.c_str(), &st) == -1) {
- PLOG(FATAL, "Cannot identify '%s'", dev_name.c_str());
+ AOS_PLOG(FATAL, "Cannot identify '%s'", dev_name.c_str());
}
if (!S_ISCHR(st.st_mode)) {
- PLOG(FATAL, "%s is no device\n", dev_name.c_str());
+ AOS_PLOG(FATAL, "%s is no device\n", dev_name.c_str());
}
fd_ = open(dev_name.c_str(), O_RDWR /* required */ | O_NONBLOCK, 0);
if (fd_ == -1) {
- PLOG(FATAL, "Cannot open '%s'", dev_name.c_str());
+ AOS_PLOG(FATAL, "Cannot open '%s'", dev_name.c_str());
}
Init();
@@ -58,17 +58,18 @@
InitMMap();
SetExposure(params.exposure());
- LOG(INFO, "Bat Vision Successfully Initialized.\n");
+ AOS_LOG(INFO, "Bat Vision Successfully Initialized.\n");
}
void Reader::QueueBuffer(v4l2_buffer *buf) {
if (xioctl(fd_, VIDIOC_QBUF, buf) == -1) {
- PLOG(WARNING,
- "ioctl VIDIOC_QBUF(%d, %p)."
- " losing buf #%" PRIu32 "\n",
- fd_, &buf, buf->index);
+ AOS_PLOG(WARNING,
+ "ioctl VIDIOC_QBUF(%d, %p)."
+ " losing buf #%" PRIu32 "\n",
+ fd_, &buf, buf->index);
} else {
- // LOG(DEBUG, "put buf #%" PRIu32 " into driver's queue\n", buf->index);
+ // AOS_LOG(DEBUG, "put buf #%" PRIu32 " into driver's queue\n",
+ // buf->index);
++queued_;
}
}
@@ -81,7 +82,7 @@
if (xioctl(fd_, VIDIOC_DQBUF, &buf) == -1) {
if (errno != EAGAIN) {
- PLOG(ERROR, "ioctl VIDIOC_DQBUF(%d, %p)", fd_, &buf);
+ AOS_PLOG(ERROR, "ioctl VIDIOC_DQBUF(%d, %p)", fd_, &buf);
}
return;
}
@@ -110,15 +111,15 @@
buf.memory = V4L2_MEMORY_MMAP;
buf.index = n;
if (xioctl(fd_, VIDIOC_QUERYBUF, &buf) == -1) {
- PLOG(FATAL, "ioctl VIDIOC_QUERYBUF(%d, %p)", fd_, &buf);
+ AOS_PLOG(FATAL, "ioctl VIDIOC_QUERYBUF(%d, %p)", fd_, &buf);
}
buffers_[n].length = buf.length;
buffers_[n].start = mmap(NULL, buf.length, PROT_READ | PROT_WRITE,
MAP_SHARED, fd_, buf.m.offset);
if (buffers_[n].start == MAP_FAILED) {
- PLOG(FATAL,
- "mmap(NULL, %zd, PROT_READ | PROT_WRITE, MAP_SHARED, %d, %jd)",
- (size_t)buf.length, fd_, static_cast<intmax_t>(buf.m.offset));
+ AOS_PLOG(FATAL,
+ "mmap(NULL, %zd, PROT_READ | PROT_WRITE, MAP_SHARED, %d, %jd)",
+ (size_t)buf.length, fd_, static_cast<intmax_t>(buf.m.offset));
}
}
}
@@ -131,14 +132,14 @@
req.memory = V4L2_MEMORY_MMAP;
if (xioctl(fd_, VIDIOC_REQBUFS, &req) == -1) {
if (EINVAL == errno) {
- LOG(FATAL, "%s does not support memory mapping\n", dev_name_.c_str());
+ AOS_LOG(FATAL, "%s does not support memory mapping\n", dev_name_.c_str());
} else {
- PLOG(FATAL, "ioctl VIDIOC_REQBUFS(%d, %p)\n", fd_, &req);
+ AOS_PLOG(FATAL, "ioctl VIDIOC_REQBUFS(%d, %p)\n", fd_, &req);
}
}
queued_ = kNumBuffers;
if (req.count != kNumBuffers) {
- LOG(FATAL, "Insufficient buffer memory on %s\n", dev_name_.c_str());
+ AOS_LOG(FATAL, "Insufficient buffer memory on %s\n", dev_name_.c_str());
}
}
@@ -150,11 +151,11 @@
int r = xioctl(fd_, VIDIOC_G_CTRL, &getArg);
if (r == 0) {
if (getArg.value == value) {
- LOG(DEBUG, "Camera control %s was already %d\n", name, getArg.value);
+ AOS_LOG(DEBUG, "Camera control %s was already %d\n", name, getArg.value);
return true;
}
} else if (errno == EINVAL) {
- LOG(DEBUG, "Camera control %s is invalid\n", name);
+ AOS_LOG(DEBUG, "Camera control %s is invalid\n", name);
errno = 0;
return false;
}
@@ -165,7 +166,7 @@
return true;
}
- LOG(DEBUG, "Couldn't set camera control %s to %d", name, value);
+ AOS_LOG(DEBUG, "Couldn't set camera control %s to %d", name, value);
errno = 0;
return false;
}
@@ -179,16 +180,16 @@
v4l2_capability cap;
if (xioctl(fd_, VIDIOC_QUERYCAP, &cap) == -1) {
if (EINVAL == errno) {
- LOG(FATAL, "%s is no V4L2 device\n", dev_name_.c_str());
+ AOS_LOG(FATAL, "%s is no V4L2 device\n", dev_name_.c_str());
} else {
- PLOG(FATAL, "ioctl VIDIOC_QUERYCAP(%d, %p)", fd_, &cap);
+ AOS_PLOG(FATAL, "ioctl VIDIOC_QUERYCAP(%d, %p)", fd_, &cap);
}
}
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
- LOG(FATAL, "%s is no video capture device\n", dev_name_.c_str());
+ AOS_LOG(FATAL, "%s is no video capture device\n", dev_name_.c_str());
}
if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
- LOG(FATAL, "%s does not support streaming i/o\n", dev_name_.c_str());
+ AOS_LOG(FATAL, "%s does not support streaming i/o\n", dev_name_.c_str());
}
/* Select video input, video standard and tune here. */
@@ -208,12 +209,12 @@
break;
default:
/* Errors ignored. */
- PLOG(WARNING, "xioctl VIDIOC_S_CROP");
+ AOS_PLOG(WARNING, "xioctl VIDIOC_S_CROP");
break;
}
}
} else {
- PLOG(WARNING, "xioctl VIDIOC_CROPCAP");
+ AOS_PLOG(WARNING, "xioctl VIDIOC_CROPCAP");
}
v4l2_format fmt;
@@ -226,8 +227,8 @@
// fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
// fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
if (xioctl(fd_, VIDIOC_S_FMT, &fmt) == -1) {
- LOG(FATAL, "ioctl VIDIC_S_FMT(%d, %p) failed with %d: %s\n", fd_, &fmt,
- errno, strerror(errno));
+ AOS_LOG(FATAL, "ioctl VIDIC_S_FMT(%d, %p) failed with %d: %s\n", fd_, &fmt,
+ errno, strerror(errno));
}
/* Note VIDIOC_S_FMT may change width and height. */
@@ -239,21 +240,21 @@
if (!SetCameraControl(V4L2_CID_EXPOSURE_AUTO, "V4L2_CID_EXPOSURE_AUTO",
V4L2_EXPOSURE_MANUAL)) {
- LOG(FATAL, "Failed to set exposure\n");
+ AOS_LOG(FATAL, "Failed to set exposure\n");
}
if (!SetCameraControl(V4L2_CID_EXPOSURE_ABSOLUTE,
"V4L2_CID_EXPOSURE_ABSOLUTE", params_.exposure())) {
- LOG(FATAL, "Failed to set exposure\n");
+ AOS_LOG(FATAL, "Failed to set exposure\n");
}
if (!SetCameraControl(V4L2_CID_BRIGHTNESS, "V4L2_CID_BRIGHTNESS",
params_.brightness())) {
- LOG(FATAL, "Failed to set up camera\n");
+ AOS_LOG(FATAL, "Failed to set up camera\n");
}
if (!SetCameraControl(V4L2_CID_GAIN, "V4L2_CID_GAIN", params_.gain())) {
- LOG(FATAL, "Failed to set up camera\n");
+ AOS_LOG(FATAL, "Failed to set up camera\n");
}
// set framerate
@@ -264,18 +265,18 @@
setfps->parm.capture.timeperframe.numerator = 1;
setfps->parm.capture.timeperframe.denominator = params_.fps();
if (xioctl(fd_, VIDIOC_S_PARM, setfps) == -1) {
- PLOG(FATAL, "ioctl VIDIOC_S_PARM(%d, %p)\n", fd_, setfps);
+ AOS_PLOG(FATAL, "ioctl VIDIOC_S_PARM(%d, %p)\n", fd_, setfps);
}
- LOG(INFO, "framerate ended up at %d/%d\n",
- setfps->parm.capture.timeperframe.numerator,
- setfps->parm.capture.timeperframe.denominator);
+ AOS_LOG(INFO, "framerate ended up at %d/%d\n",
+ setfps->parm.capture.timeperframe.numerator,
+ setfps->parm.capture.timeperframe.denominator);
}
aos::vision::ImageFormat Reader::get_format() {
struct v4l2_format fmt;
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (xioctl(fd_, VIDIOC_G_FMT, &fmt) == -1) {
- PLOG(FATAL, "ioctl VIDIC_G_FMT(%d, %p)\n", fd_, &fmt);
+ AOS_PLOG(FATAL, "ioctl VIDIC_G_FMT(%d, %p)\n", fd_, &fmt);
}
return aos::vision::ImageFormat{(int)fmt.fmt.pix.width,
@@ -283,7 +284,7 @@
}
void Reader::Start() {
- LOG(DEBUG, "queueing buffers for the first time\n");
+ AOS_LOG(DEBUG, "queueing buffers for the first time\n");
v4l2_buffer buf;
for (unsigned int i = 0; i < kNumBuffers; ++i) {
CLEAR(buf);
@@ -292,11 +293,11 @@
buf.index = i;
QueueBuffer(&buf);
}
- LOG(DEBUG, "done with first queue\n");
+ AOS_LOG(DEBUG, "done with first queue\n");
v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (xioctl(fd_, VIDIOC_STREAMON, &type) == -1) {
- PLOG(FATAL, "ioctl VIDIOC_STREAMON(%d, %p)\n", fd_, &type);
+ AOS_PLOG(FATAL, "ioctl VIDIOC_STREAMON(%d, %p)\n", fd_, &type);
}
}