Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 1 | #include "aos/events/timing_statistics.h" |
| 2 | |
| 3 | #include "aos/events/event_loop_generated.h" |
| 4 | #include "glog/logging.h" |
| 5 | |
| 6 | namespace aos { |
| 7 | namespace internal { |
| 8 | |
| 9 | void RawFetcherTiming::set_timing_report(timing::Fetcher *new_fetcher) { |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 10 | fetcher = new_fetcher; |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 11 | if (!new_fetcher) { |
| 12 | latency.set_statistic(nullptr); |
| 13 | } else { |
| 14 | latency.set_statistic(fetcher->mutable_latency()); |
| 15 | } |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | void RawFetcherTiming::ResetTimingReport() { |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 19 | if (!fetcher) { |
| 20 | return; |
| 21 | } |
| 22 | |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 23 | latency.Reset(); |
| 24 | fetcher->mutate_count(0); |
| 25 | } |
| 26 | |
| 27 | void RawSenderTiming::set_timing_report(timing::Sender *new_sender) { |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 28 | sender = new_sender; |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 29 | if (!sender) { |
| 30 | size.set_statistic(nullptr); |
| 31 | } else { |
| 32 | size.set_statistic(sender->mutable_size()); |
| 33 | } |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | void RawSenderTiming::ResetTimingReport() { |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 37 | if (!sender) { |
| 38 | return; |
| 39 | } |
| 40 | |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 41 | size.Reset(); |
| 42 | sender->mutate_count(0); |
James Kuszmaul | 7851433 | 2022-04-06 15:08:34 -0700 | [diff] [blame^] | 43 | for (size_t ii = 0; ii < kNumErrors; ++ii) { |
| 44 | sender->mutable_error_counts()->GetMutableObject(ii)->mutate_count(0); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void 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 Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void TimerTiming::set_timing_report(timing::Timer *new_timer) { |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 59 | timer = new_timer; |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 60 | 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 Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void TimerTiming::ResetTimingReport() { |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 70 | if (!timer) { |
| 71 | return; |
| 72 | } |
| 73 | |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 74 | wakeup_latency.Reset(); |
| 75 | handler_time.Reset(); |
| 76 | timer->mutate_count(0); |
| 77 | } |
| 78 | |
| 79 | } // namespace internal |
| 80 | } // namespace aos |