Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 1 | #include "aos/events/timing_statistics.h" |
| 2 | |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 3 | #include "glog/logging.h" |
| 4 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame^] | 5 | #include "aos/events/event_loop_generated.h" |
| 6 | |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 7 | namespace aos { |
| 8 | namespace internal { |
| 9 | |
| 10 | void RawFetcherTiming::set_timing_report(timing::Fetcher *new_fetcher) { |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 11 | fetcher = new_fetcher; |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 12 | if (!new_fetcher) { |
| 13 | latency.set_statistic(nullptr); |
| 14 | } else { |
| 15 | latency.set_statistic(fetcher->mutable_latency()); |
| 16 | } |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | void RawFetcherTiming::ResetTimingReport() { |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 20 | if (!fetcher) { |
| 21 | return; |
| 22 | } |
| 23 | |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 24 | latency.Reset(); |
| 25 | fetcher->mutate_count(0); |
| 26 | } |
| 27 | |
| 28 | void RawSenderTiming::set_timing_report(timing::Sender *new_sender) { |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 29 | sender = new_sender; |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 30 | if (!sender) { |
| 31 | size.set_statistic(nullptr); |
James Kuszmaul | cc94ed4 | 2022-08-24 11:36:17 -0700 | [diff] [blame] | 32 | error_counter.InvalidateBuffer(); |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 33 | } else { |
| 34 | size.set_statistic(sender->mutable_size()); |
James Kuszmaul | cc94ed4 | 2022-08-24 11:36:17 -0700 | [diff] [blame] | 35 | error_counter.set_mutable_vector(sender->mutable_error_counts()); |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 36 | } |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void RawSenderTiming::ResetTimingReport() { |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 40 | if (!sender) { |
| 41 | return; |
| 42 | } |
| 43 | |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 44 | size.Reset(); |
| 45 | sender->mutate_count(0); |
James Kuszmaul | cc94ed4 | 2022-08-24 11:36:17 -0700 | [diff] [blame] | 46 | error_counter.ResetCounts(); |
James Kuszmaul | 7851433 | 2022-04-06 15:08:34 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void RawSenderTiming::IncrementError(timing::SendError error) { |
| 50 | if (!sender) { |
| 51 | return; |
| 52 | } |
James Kuszmaul | cc94ed4 | 2022-08-24 11:36:17 -0700 | [diff] [blame] | 53 | error_counter.IncrementError(error); |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void TimerTiming::set_timing_report(timing::Timer *new_timer) { |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 57 | timer = new_timer; |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 58 | if (!timer) { |
| 59 | wakeup_latency.set_statistic(nullptr); |
| 60 | handler_time.set_statistic(nullptr); |
| 61 | } else { |
| 62 | wakeup_latency.set_statistic(timer->mutable_wakeup_latency()); |
| 63 | handler_time.set_statistic(timer->mutable_handler_time()); |
| 64 | } |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void TimerTiming::ResetTimingReport() { |
Brian Silverman | bf88992 | 2021-11-10 12:41:57 -0800 | [diff] [blame] | 68 | if (!timer) { |
| 69 | return; |
| 70 | } |
| 71 | |
Austin Schuh | e410614 | 2019-12-01 18:19:53 -0800 | [diff] [blame] | 72 | wakeup_latency.Reset(); |
| 73 | handler_time.Reset(); |
| 74 | timer->mutate_count(0); |
| 75 | } |
| 76 | |
| 77 | } // namespace internal |
| 78 | } // namespace aos |