blob: 9e559e6af438423351c73ccffcf633e859945815 [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;
44 float first_occurence = -1;
45 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
60 private:
61 AnalyzerConfig config_;
62 std::map<TriageAlertType, TriageAlert> triage_alerts_;
63
64 void Alert(TriageAlertType type,
65 float time_seconds,
66 absl::string_view explanation) {
67 std::map<TriageAlertType, TriageAlert>::iterator it =
68 triage_alerts_.find(type);
69
70 if (it == triage_alerts_.end()) {
71 TriageAlert alert;
72 alert.type = type;
73 alert.first_occurence = time_seconds;
74 alert.count = 1;
75 alert.explanation = std::string(explanation);
76 triage_alerts_.insert(std::make_pair(type, alert));
77 } else {
78 it->second.count += 1;
79 }
80 }
81 RTC_DISALLOW_COPY_AND_ASSIGN(TriageHelper);
82};
83
84} // namespace webrtc
85
86#endif // RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ALERTS_H_