OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2015 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 WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_METRIC_RECORDER_H_ |
| 12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_METRIC_RECORDER_H_ |
| 13 |
| 14 #include <set> |
| 15 #include <string> |
| 16 #include <vector> |
| 17 |
| 18 #include "webrtc/base/common.h" |
| 19 #include "webrtc/modules/remote_bitrate_estimator/test/packet_sender.h" |
| 20 |
| 21 namespace webrtc { |
| 22 namespace testing { |
| 23 namespace bwe { |
| 24 |
| 25 class LinkShare { |
| 26 public: |
| 27 explicit LinkShare(ChokeFilter* choke_filter); |
| 28 |
| 29 void PauseFlow(int flow_id); // Increases available capacity per flow. |
| 30 void ResumeFlow(int flow_id); // Decreases available capacity per flow. |
| 31 |
| 32 uint32_t TotalAvailableKbps(); |
| 33 // If the given flow is paused, its output is zero. |
| 34 uint32_t AvailablePerFlowKbps(int flow_id); |
| 35 |
| 36 private: |
| 37 ChokeFilter* choke_filter_; |
| 38 std::set<int> running_flows_; |
| 39 }; |
| 40 |
| 41 struct PlotInformation { |
| 42 template <typename T> |
| 43 void Update(int64_t now_ms, T new_value) { |
| 44 time_ms = now_ms; |
| 45 value = static_cast<double>(new_value); |
| 46 } |
| 47 std::string prefix; |
| 48 bool plot; |
| 49 int64_t last_plot_ms; |
| 50 int64_t time_ms; |
| 51 double value; |
| 52 int64_t plot_interval_ms; |
| 53 }; |
| 54 |
| 55 class MetricRecorder { |
| 56 public: |
| 57 MetricRecorder(const std::string algorithm_name, |
| 58 int flow_id, |
| 59 PacketSender* packet_sender, |
| 60 LinkShare* link_share); |
| 61 |
| 62 void SetPlotInformation(const std::vector<std::string>& prefixs); |
| 63 |
| 64 void PlotLine(int windows_id, |
| 65 const std::string& prefix, |
| 66 int64_t x, |
| 67 int64_t y); |
| 68 |
| 69 void PlotDynamics(int metric); |
| 70 void PlotAllDynamics(); |
| 71 |
| 72 void UpdateTime(int64_t time_ms); |
| 73 void UpdateThroughput(int64_t bitrate_kbps, size_t payload_size); |
| 74 void UpdateDelay(int64_t delay_ms); |
| 75 void UpdateLoss(float loss_ratio); |
| 76 void UpdateObjective(); |
| 77 |
| 78 void PlotThroughputHistogram(const std::string& title, |
| 79 const std::string& bwe_name, |
| 80 int num_flows, |
| 81 int64_t extra_offset_ms, |
| 82 const std::string optimum_id); |
| 83 |
| 84 void PlotThroughputHistogram(const std::string& title, |
| 85 const std::string& bwe_name, |
| 86 int num_flows, |
| 87 int64_t extra_offset_ms); |
| 88 |
| 89 void PlotDelayHistogram(const std::string& title, |
| 90 const std::string& bwe_name, |
| 91 int num_flows); |
| 92 |
| 93 void PlotLossHistogram(const std::string& title, |
| 94 const std::string& bwe_name, |
| 95 int num_flows, |
| 96 float global_loss_ratio); |
| 97 |
| 98 void PlotObjectiveHistogram(const std::string& title, |
| 99 const std::string& bwe_name, |
| 100 int num_flows); |
| 101 |
| 102 void set_start_computing_metrics_ms(int64_t start_computing_metrics_ms) { |
| 103 start_computing_metrics_ms_ = start_computing_metrics_ms; |
| 104 } |
| 105 |
| 106 void set_plot_available_capacity(bool plot) { |
| 107 plot_information_[kTotalAvailable].plot = plot; |
| 108 } |
| 109 |
| 110 private: |
| 111 uint32_t GetTotalAvailableKbps(); |
| 112 uint32_t GetAvailablePerFlowKbps(); |
| 113 uint32_t GetSendingEstimateKbps(); |
| 114 double ObjectiveFunction(); |
| 115 |
| 116 double Renormalize(double x); |
| 117 bool ShouldRecord(int64_t arrival_time_ms); |
| 118 |
| 119 void PushDelayMs(int64_t delay_ms, int64_t arrival_time_ms); |
| 120 void PushThroughputBytes(size_t throughput_bytes, int64_t arrival_time_ms); |
| 121 |
| 122 enum Metrics { |
| 123 kThroughput = 0, |
| 124 kDelay, |
| 125 kLoss, |
| 126 kObjective, |
| 127 kTotalAvailable, |
| 128 kAvailablePerFlow, |
| 129 kNumMetrics |
| 130 }; |
| 131 |
| 132 std::string algorithm_name_; |
| 133 int flow_id_; |
| 134 PacketSender* packet_sender_; |
| 135 LinkShare* link_share_; |
| 136 |
| 137 int64_t now_ms_; |
| 138 |
| 139 PlotInformation plot_information_[kNumMetrics]; |
| 140 |
| 141 std::vector<int64_t> delays_ms_; |
| 142 std::vector<size_t> throughput_bytes_; |
| 143 // (Receiving rate - available bitrate per flow) * time window. |
| 144 std::vector<int64_t> weighted_estimate_error_; |
| 145 int64_t last_unweighted_estimate_error_; |
| 146 int64_t optimal_throughput_bits_; |
| 147 int64_t last_available_bitrate_per_flow_kbps_; |
| 148 int64_t start_computing_metrics_ms_; |
| 149 bool started_computing_metrics_; |
| 150 }; |
| 151 |
| 152 } // namespace bwe |
| 153 } // namespace testing |
| 154 } // namespace webrtc |
| 155 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_METRIC_RECORDER_H_ |
OLD | NEW |