Refactor ErrorCounter out from timing report code
This is helpful to allow other applications to track error counts in a
similar manner.
Change-Id: Ifc7127578c08757febc6acdc3a79e42ad7b7cce5
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/events/timing_statistics.cc b/aos/events/timing_statistics.cc
index fbc49f4..c89bebd 100644
--- a/aos/events/timing_statistics.cc
+++ b/aos/events/timing_statistics.cc
@@ -28,8 +28,10 @@
sender = new_sender;
if (!sender) {
size.set_statistic(nullptr);
+ error_counter.InvalidateBuffer();
} else {
size.set_statistic(sender->mutable_size());
+ error_counter.set_mutable_vector(sender->mutable_error_counts());
}
}
@@ -40,19 +42,14 @@
size.Reset();
sender->mutate_count(0);
- for (size_t ii = 0; ii < kNumErrors; ++ii) {
- sender->mutable_error_counts()->GetMutableObject(ii)->mutate_count(0);
- }
+ error_counter.ResetCounts();
}
void RawSenderTiming::IncrementError(timing::SendError error) {
if (!sender) {
return;
}
- const size_t index = static_cast<size_t>(error);
- timing::SendErrorCount *counter =
- sender->mutable_error_counts()->GetMutableObject(index);
- counter->mutate_count(counter->count() + 1);
+ error_counter.IncrementError(error);
}
void TimerTiming::set_timing_report(timing::Timer *new_timer) {