Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ALERTS_H_ |
| 12 | #define RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ALERTS_H_ |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | |
| 16 | #include <map> |
| 17 | #include <string> |
| 18 | #include <utility> |
| 19 | |
| 20 | #include "absl/strings/string_view.h" |
| 21 | #include "logging/rtc_event_log/rtc_event_log_parser.h" |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 22 | #include "rtc_tools/rtc_event_log_visualizer/analyzer_common.h" |
| 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | enum class TriageAlertType { |
| 27 | kUnknown = 0, |
| 28 | kIncomingRtpGap, |
| 29 | kOutgoingRtpGap, |
| 30 | kIncomingRtcpGap, |
| 31 | kOutgoingRtcpGap, |
| 32 | kIncomingSeqNumJump, |
| 33 | kOutgoingSeqNumJump, |
| 34 | kIncomingCaptureTimeJump, |
| 35 | kOutgoingCaptureTimeJump, |
| 36 | kOutgoingHighLoss, |
| 37 | kLast, |
| 38 | }; |
| 39 | |
| 40 | struct TriageAlert { |
| 41 | TriageAlertType type = TriageAlertType::kUnknown; |
| 42 | int count = 0; |
Bjorn Terelius | b914819 | 2020-05-19 14:30:35 +0200 | [diff] [blame] | 43 | float first_occurrence = -1; |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 44 | std::string explanation; |
| 45 | }; |
| 46 | |
| 47 | class TriageHelper { |
| 48 | public: |
| 49 | explicit TriageHelper(const AnalyzerConfig& config) : config_(config) {} |
| 50 | |
Byoungchan Lee | 5f0eb93 | 2022-01-26 09:36:49 +0900 | [diff] [blame^] | 51 | TriageHelper(const TriageHelper&) = delete; |
| 52 | TriageHelper& operator=(const TriageHelper&) = delete; |
| 53 | |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 54 | void AnalyzeLog(const ParsedRtcEventLog& parsed_log); |
| 55 | |
| 56 | void AnalyzeStreamGaps(const ParsedRtcEventLog& parsed_log, |
| 57 | PacketDirection direction); |
| 58 | void AnalyzeTransmissionGaps(const ParsedRtcEventLog& parsed_log, |
| 59 | PacketDirection direction); |
| 60 | void Print(FILE* file); |
| 61 | |
Bjorn Terelius | 7634ea7 | 2020-10-02 14:53:50 +0200 | [diff] [blame] | 62 | void ProcessAlerts(std::function<void(int, float, std::string)> f); |
| 63 | |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 64 | private: |
| 65 | AnalyzerConfig config_; |
| 66 | std::map<TriageAlertType, TriageAlert> triage_alerts_; |
| 67 | |
| 68 | void Alert(TriageAlertType type, |
| 69 | float time_seconds, |
| 70 | absl::string_view explanation) { |
| 71 | std::map<TriageAlertType, TriageAlert>::iterator it = |
| 72 | triage_alerts_.find(type); |
| 73 | |
| 74 | if (it == triage_alerts_.end()) { |
| 75 | TriageAlert alert; |
| 76 | alert.type = type; |
Bjorn Terelius | b914819 | 2020-05-19 14:30:35 +0200 | [diff] [blame] | 77 | alert.first_occurrence = time_seconds; |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 78 | alert.count = 1; |
| 79 | alert.explanation = std::string(explanation); |
| 80 | triage_alerts_.insert(std::make_pair(type, alert)); |
| 81 | } else { |
| 82 | it->second.count += 1; |
| 83 | } |
| 84 | } |
Bjorn Terelius | 48b8279 | 2020-05-19 10:57:24 +0200 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace webrtc |
| 88 | |
| 89 | #endif // RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ALERTS_H_ |