blob: d3e41666aa10db789b06053ec7c3b7e90ed5c8a8 [file] [log] [blame]
Bjorn Terelius48b82792020-05-19 10:57:24 +02001/*
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_base/constructor_magic.h"
23#include "rtc_tools/rtc_event_log_visualizer/analyzer_common.h"
24
25namespace webrtc {
26
27enum class TriageAlertType {
28 kUnknown = 0,
29 kIncomingRtpGap,
30 kOutgoingRtpGap,
31 kIncomingRtcpGap,
32 kOutgoingRtcpGap,
33 kIncomingSeqNumJump,
34 kOutgoingSeqNumJump,
35 kIncomingCaptureTimeJump,
36 kOutgoingCaptureTimeJump,
37 kOutgoingHighLoss,
38 kLast,
39};
40
41struct TriageAlert {
42 TriageAlertType type = TriageAlertType::kUnknown;
43 int count = 0;
Bjorn Tereliusb9148192020-05-19 14:30:35 +020044 float first_occurrence = -1;
Bjorn Terelius48b82792020-05-19 10:57:24 +020045 std::string explanation;
46};
47
48class TriageHelper {
49 public:
50 explicit TriageHelper(const AnalyzerConfig& config) : config_(config) {}
51
52 void AnalyzeLog(const ParsedRtcEventLog& parsed_log);
53
54 void AnalyzeStreamGaps(const ParsedRtcEventLog& parsed_log,
55 PacketDirection direction);
56 void AnalyzeTransmissionGaps(const ParsedRtcEventLog& parsed_log,
57 PacketDirection direction);
58 void Print(FILE* file);
59
Bjorn Terelius7634ea72020-10-02 14:53:50 +020060 void ProcessAlerts(std::function<void(int, float, std::string)> f);
61
Bjorn Terelius48b82792020-05-19 10:57:24 +020062 private:
63 AnalyzerConfig config_;
64 std::map<TriageAlertType, TriageAlert> triage_alerts_;
65
66 void Alert(TriageAlertType type,
67 float time_seconds,
68 absl::string_view explanation) {
69 std::map<TriageAlertType, TriageAlert>::iterator it =
70 triage_alerts_.find(type);
71
72 if (it == triage_alerts_.end()) {
73 TriageAlert alert;
74 alert.type = type;
Bjorn Tereliusb9148192020-05-19 14:30:35 +020075 alert.first_occurrence = time_seconds;
Bjorn Terelius48b82792020-05-19 10:57:24 +020076 alert.count = 1;
77 alert.explanation = std::string(explanation);
78 triage_alerts_.insert(std::make_pair(type, alert));
79 } else {
80 it->second.count += 1;
81 }
82 }
83 RTC_DISALLOW_COPY_AND_ASSIGN(TriageHelper);
84};
85
86} // namespace webrtc
87
88#endif // RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ALERTS_H_