blob: fbc49f4ff5f18f5c6349ee460976239b1ac51e25 [file] [log] [blame]
Austin Schuhe4106142019-12-01 18:19:53 -08001#include "aos/events/timing_statistics.h"
2
3#include "aos/events/event_loop_generated.h"
4#include "glog/logging.h"
5
6namespace aos {
7namespace internal {
8
9void RawFetcherTiming::set_timing_report(timing::Fetcher *new_fetcher) {
Austin Schuhe4106142019-12-01 18:19:53 -080010 fetcher = new_fetcher;
Brian Silvermanbf889922021-11-10 12:41:57 -080011 if (!new_fetcher) {
12 latency.set_statistic(nullptr);
13 } else {
14 latency.set_statistic(fetcher->mutable_latency());
15 }
Austin Schuhe4106142019-12-01 18:19:53 -080016}
17
18void RawFetcherTiming::ResetTimingReport() {
Brian Silvermanbf889922021-11-10 12:41:57 -080019 if (!fetcher) {
20 return;
21 }
22
Austin Schuhe4106142019-12-01 18:19:53 -080023 latency.Reset();
24 fetcher->mutate_count(0);
25}
26
27void RawSenderTiming::set_timing_report(timing::Sender *new_sender) {
Austin Schuhe4106142019-12-01 18:19:53 -080028 sender = new_sender;
Brian Silvermanbf889922021-11-10 12:41:57 -080029 if (!sender) {
30 size.set_statistic(nullptr);
31 } else {
32 size.set_statistic(sender->mutable_size());
33 }
Austin Schuhe4106142019-12-01 18:19:53 -080034}
35
36void RawSenderTiming::ResetTimingReport() {
Brian Silvermanbf889922021-11-10 12:41:57 -080037 if (!sender) {
38 return;
39 }
40
Austin Schuhe4106142019-12-01 18:19:53 -080041 size.Reset();
42 sender->mutate_count(0);
James Kuszmaul78514332022-04-06 15:08:34 -070043 for (size_t ii = 0; ii < kNumErrors; ++ii) {
44 sender->mutable_error_counts()->GetMutableObject(ii)->mutate_count(0);
45 }
46}
47
48void RawSenderTiming::IncrementError(timing::SendError error) {
49 if (!sender) {
50 return;
51 }
52 const size_t index = static_cast<size_t>(error);
53 timing::SendErrorCount *counter =
54 sender->mutable_error_counts()->GetMutableObject(index);
55 counter->mutate_count(counter->count() + 1);
Austin Schuhe4106142019-12-01 18:19:53 -080056}
57
58void TimerTiming::set_timing_report(timing::Timer *new_timer) {
Austin Schuhe4106142019-12-01 18:19:53 -080059 timer = new_timer;
Brian Silvermanbf889922021-11-10 12:41:57 -080060 if (!timer) {
61 wakeup_latency.set_statistic(nullptr);
62 handler_time.set_statistic(nullptr);
63 } else {
64 wakeup_latency.set_statistic(timer->mutable_wakeup_latency());
65 handler_time.set_statistic(timer->mutable_handler_time());
66 }
Austin Schuhe4106142019-12-01 18:19:53 -080067}
68
69void TimerTiming::ResetTimingReport() {
Brian Silvermanbf889922021-11-10 12:41:57 -080070 if (!timer) {
71 return;
72 }
73
Austin Schuhe4106142019-12-01 18:19:53 -080074 wakeup_latency.Reset();
75 handler_time.Reset();
76 timer->mutate_count(0);
77}
78
79} // namespace internal
80} // namespace aos