xref: /aosp_15_r20/external/webrtc/rtc_tools/rtc_event_log_visualizer/alerts.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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"
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;
43   float first_occurrence = -1;
44   std::string explanation;
45 };
46 
47 class TriageHelper {
48  public:
TriageHelper(const AnalyzerConfig & config)49   explicit TriageHelper(const AnalyzerConfig& config) : config_(config) {}
50 
51   TriageHelper(const TriageHelper&) = delete;
52   TriageHelper& operator=(const TriageHelper&) = delete;
53 
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 
62   void ProcessAlerts(std::function<void(int, float, std::string)> f);
63 
64  private:
65   AnalyzerConfig config_;
66   std::map<TriageAlertType, TriageAlert> triage_alerts_;
67 
Alert(TriageAlertType type,float time_seconds,absl::string_view explanation)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;
77       alert.first_occurrence = time_seconds;
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   }
85 };
86 
87 }  // namespace webrtc
88 
89 #endif  // RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ALERTS_H_
90