alerts.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ALERTS_H_
  11. #define RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ALERTS_H_
  12. #include <stdio.h>
  13. #include <map>
  14. #include <string>
  15. #include <utility>
  16. #include "absl/strings/string_view.h"
  17. #include "logging/rtc_event_log/rtc_event_log_parser.h"
  18. #include "rtc_base/constructor_magic.h"
  19. #include "rtc_tools/rtc_event_log_visualizer/analyzer_common.h"
  20. namespace webrtc {
  21. enum class TriageAlertType {
  22. kUnknown = 0,
  23. kIncomingRtpGap,
  24. kOutgoingRtpGap,
  25. kIncomingRtcpGap,
  26. kOutgoingRtcpGap,
  27. kIncomingSeqNumJump,
  28. kOutgoingSeqNumJump,
  29. kIncomingCaptureTimeJump,
  30. kOutgoingCaptureTimeJump,
  31. kOutgoingHighLoss,
  32. kLast,
  33. };
  34. struct TriageAlert {
  35. TriageAlertType type = TriageAlertType::kUnknown;
  36. int count = 0;
  37. float first_occurrence = -1;
  38. std::string explanation;
  39. };
  40. class TriageHelper {
  41. public:
  42. explicit TriageHelper(const AnalyzerConfig& config) : config_(config) {}
  43. void AnalyzeLog(const ParsedRtcEventLog& parsed_log);
  44. void AnalyzeStreamGaps(const ParsedRtcEventLog& parsed_log,
  45. PacketDirection direction);
  46. void AnalyzeTransmissionGaps(const ParsedRtcEventLog& parsed_log,
  47. PacketDirection direction);
  48. void Print(FILE* file);
  49. private:
  50. AnalyzerConfig config_;
  51. std::map<TriageAlertType, TriageAlert> triage_alerts_;
  52. void Alert(TriageAlertType type,
  53. float time_seconds,
  54. absl::string_view explanation) {
  55. std::map<TriageAlertType, TriageAlert>::iterator it =
  56. triage_alerts_.find(type);
  57. if (it == triage_alerts_.end()) {
  58. TriageAlert alert;
  59. alert.type = type;
  60. alert.first_occurrence = time_seconds;
  61. alert.count = 1;
  62. alert.explanation = std::string(explanation);
  63. triage_alerts_.insert(std::make_pair(type, alert));
  64. } else {
  65. it->second.count += 1;
  66. }
  67. }
  68. RTC_DISALLOW_COPY_AND_ASSIGN(TriageHelper);
  69. };
  70. } // namespace webrtc
  71. #endif // RTC_TOOLS_RTC_EVENT_LOG_VISUALIZER_ALERTS_H_