converted more stuff to LogInterval
diff --git a/aos/common/common.gyp b/aos/common/common.gyp
index 7259c32..906b5b2 100644
--- a/aos/common/common.gyp
+++ b/aos/common/common.gyp
@@ -183,6 +183,7 @@
'time',
'control_loop_queues',
'<(AOS)/common/logging/logging.gyp:queue_logging',
+ '<(AOS)/common/util/util.gyp:log_interval',
],
'export_dependent_settings': [
'<(AOS)/common/messages/messages.gyp:aos_queues',
@@ -191,6 +192,7 @@
'time',
'control_loop_queues',
'<(AOS)/common/logging/logging.gyp:queue_logging',
+ '<(AOS)/common/util/util.gyp:log_interval',
],
},
{
diff --git a/aos/common/control_loop/ControlLoop-tmpl.h b/aos/common/control_loop/ControlLoop-tmpl.h
index 3173d2c..b5714d5 100644
--- a/aos/common/control_loop/ControlLoop-tmpl.h
+++ b/aos/common/control_loop/ControlLoop-tmpl.h
@@ -11,6 +11,10 @@
// TODO(aschuh): Tests.
template <class T, bool has_position, bool fail_no_position>
+constexpr ::aos::time::Time
+ ControlLoop<T, has_position, fail_no_position>::kStaleLogInterval;
+
+template <class T, bool has_position, bool fail_no_position>
void ControlLoop<T, has_position, fail_no_position>::ZeroOutputs() {
aos::ScopedMessagePtr<OutputType> output =
control_loop_->output.MakeMessage();
@@ -29,7 +33,7 @@
// goals.
const GoalType *goal = control_loop_->goal.get();
if (goal == NULL) {
- LOG(ERROR, "No prior control loop goal.\n");
+ LOG_INTERVAL(no_prior_goal_);
ZeroOutputs();
return;
}
@@ -48,15 +52,15 @@
if (control_loop_->position.get()) {
int msec_age = control_loop_->position.Age().ToMSec();
if (!control_loop_->position.IsNewerThanMS(kPositionTimeoutMs)) {
- LOG(ERROR, "Stale position. %d ms > %d ms. Outputs disabled.\n",
- msec_age, kPositionTimeoutMs);
+ LOG_INTERVAL(very_stale_position_);
ZeroOutputs();
return;
} else {
- LOG(ERROR, "Stale position. %d ms\n", msec_age);
+ LOG(ERROR, "Stale position. %d ms (< %d ms)\n", msec_age,
+ kPositionTimeoutMs);
}
} else {
- LOG(ERROR, "Never had a position.\n");
+ LOG_INTERVAL(no_prior_position_);
if (fail_no_position) {
ZeroOutputs();
return;
@@ -77,10 +81,9 @@
outputs_enabled = true;
} else {
if (aos::robot_state.get()) {
- int msec_age = aos::robot_state.Age().ToMSec();
- LOG(ERROR, "Driver Station packet is too old (%d ms).\n", msec_age);
+ LOG_INTERVAL(driver_station_old_);
} else {
- LOG(ERROR, "No Driver Station packet.\n");
+ LOG_INTERVAL(no_driver_station_);
}
}
diff --git a/aos/common/control_loop/ControlLoop.h b/aos/common/control_loop/ControlLoop.h
index 6af7235..e48d259 100644
--- a/aos/common/control_loop/ControlLoop.h
+++ b/aos/common/control_loop/ControlLoop.h
@@ -7,6 +7,7 @@
#include "aos/common/type_traits.h"
#include "aos/common/queue.h"
#include "aos/common/time.h"
+#include "aos/common/util/log_interval.h"
namespace aos {
namespace control_loops {
@@ -129,6 +130,25 @@
private:
// Pointer to the queue group
T *control_loop_;
+
+ typedef ::aos::util::SimpleLogInterval SimpleLogInterval;
+ static constexpr ::aos::time::Time kStaleLogInterval =
+ ::aos::time::Time::InSeconds(0.1);
+ SimpleLogInterval very_stale_position_ =
+ SimpleLogInterval(kStaleLogInterval, ERROR,
+ "outputs disabled because position is very stale");
+ SimpleLogInterval no_prior_goal_ =
+ SimpleLogInterval(kStaleLogInterval, ERROR,
+ "no prior goal");
+ SimpleLogInterval no_prior_position_ =
+ SimpleLogInterval(kStaleLogInterval, ERROR,
+ "no prior position");
+ SimpleLogInterval no_driver_station_ =
+ SimpleLogInterval(kStaleLogInterval, ERROR,
+ "no driver station packet");
+ SimpleLogInterval driver_station_old_ =
+ SimpleLogInterval(kStaleLogInterval, ERROR,
+ "driver station packet is too old");
};
} // namespace control_loops
diff --git a/aos/common/logging/queue_logging.h b/aos/common/logging/queue_logging.h
index df343df..191d4c7 100644
--- a/aos/common/logging/queue_logging.h
+++ b/aos/common/logging/queue_logging.h
@@ -11,7 +11,6 @@
namespace aos {
namespace logging {
-#if 1
#define LOG_STRUCT(level, message, structure) \
do { \
static const ::std::string kAosLoggingMessage( \
@@ -24,9 +23,6 @@
abort(); \
} \
} while (false)
-#else
-#define LOG_STRUCT(level, message, structure)
-#endif
template <class T>
void DoLogStruct(log_level level, const ::std::string &message,
diff --git a/aos/common/util/log_interval.h b/aos/common/util/log_interval.h
index 1e5c57b..9acbe40 100644
--- a/aos/common/util/log_interval.h
+++ b/aos/common/util/log_interval.h
@@ -46,6 +46,8 @@
return r;
}
+ const ::aos::time::Time &interval() const { return interval_; }
+
private:
int count_;
const ::aos::time::Time interval_;
@@ -65,8 +67,9 @@
void Hit(const char *context) {
interval_.WantToLog();
if (interval_.ShouldLog()) {
- log_do(level_, "%s: %.*s %d times\n", context, message_.size(),
- message_.data(), interval_.Count());
+ log_do(level_, "%s: %.*s %d times over %f sec\n", context,
+ message_.size(), message_.data(), interval_.Count(),
+ interval_.interval().ToSeconds());
}
}