Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: webrtc/video/send_statistics_proxy.cc

Issue 1478253002: Add histogram stats for send delay for a sent video stream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/video/send_statistics_proxy.h" 11 #include "webrtc/video/send_statistics_proxy.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <cmath> 14 #include <cmath>
15 #include <map> 15 #include <map>
16 16
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
20 #include "webrtc/system_wrappers/include/metrics.h" 20 #include "webrtc/system_wrappers/include/metrics.h"
21 21
22 namespace webrtc { 22 namespace webrtc {
23 namespace { 23 namespace {
24 const float kEncodeTimeWeigthFactor = 0.5f; 24 const float kEncodeTimeWeigthFactor = 0.5f;
25 25
26 // Packet with a larger delay are removed and excluded from the delay stats.
27 // Set to larger than max histogram delay which is 10000.
28 const int64_t kMaxSentPacketDelayMs = 11000;
29 const size_t kMaxSendPacketMapSize = 2000;
30
26 // Used by histograms. Values of entries should not be changed. 31 // Used by histograms. Values of entries should not be changed.
27 enum HistogramCodecType { 32 enum HistogramCodecType {
28 kVideoUnknown = 0, 33 kVideoUnknown = 0,
29 kVideoVp8 = 1, 34 kVideoVp8 = 1,
30 kVideoVp9 = 2, 35 kVideoVp9 = 2,
31 kVideoH264 = 3, 36 kVideoH264 = 3,
32 kVideoMax = 64, 37 kVideoMax = 64,
33 }; 38 };
34 39
35 const char* GetUmaPrefix(VideoEncoderConfig::ContentType content_type) { 40 const char* GetUmaPrefix(VideoEncoderConfig::ContentType content_type) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 147 }
143 int delay_ms = delay_counter_.Avg(kMinRequiredSamples); 148 int delay_ms = delay_counter_.Avg(kMinRequiredSamples);
144 if (delay_ms != -1) 149 if (delay_ms != -1)
145 RTC_HISTOGRAM_COUNTS_100000(uma_prefix_ + "SendSideDelayInMs", delay_ms); 150 RTC_HISTOGRAM_COUNTS_100000(uma_prefix_ + "SendSideDelayInMs", delay_ms);
146 151
147 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples); 152 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples);
148 if (max_delay_ms != -1) { 153 if (max_delay_ms != -1) {
149 RTC_HISTOGRAM_COUNTS_100000(uma_prefix_ + "SendSideDelayMaxInMs", 154 RTC_HISTOGRAM_COUNTS_100000(uma_prefix_ + "SendSideDelayMaxInMs",
150 max_delay_ms); 155 max_delay_ms);
151 } 156 }
157 for (const auto& it : send_delay_counters_) {
158 int send_delay_ms = it.second.Avg(kMinRequiredSamples);
159 if (send_delay_ms != -1)
160 RTC_HISTOGRAM_COUNTS_10000(uma_prefix_ + "SendDelayInMs", send_delay_ms);
161 }
152 } 162 }
153 163
154 void SendStatisticsProxy::SetContentType( 164 void SendStatisticsProxy::SetContentType(
155 VideoEncoderConfig::ContentType content_type) { 165 VideoEncoderConfig::ContentType content_type) {
156 rtc::CritScope lock(&crit_); 166 rtc::CritScope lock(&crit_);
157 if (content_type_ != content_type) { 167 if (content_type_ != content_type) {
158 uma_container_->UpdateHistograms(); 168 uma_container_->UpdateHistograms();
159 uma_container_.reset(new UmaSamplesContainer(GetUmaPrefix(content_type))); 169 uma_container_.reset(new UmaSamplesContainer(GetUmaPrefix(content_type)));
160 content_type_ = content_type; 170 content_type_ = content_type;
161 } 171 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); 386 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
377 if (stats == nullptr) 387 if (stats == nullptr)
378 return; 388 return;
379 stats->avg_delay_ms = avg_delay_ms; 389 stats->avg_delay_ms = avg_delay_ms;
380 stats->max_delay_ms = max_delay_ms; 390 stats->max_delay_ms = max_delay_ms;
381 391
382 uma_container_->delay_counter_.Add(avg_delay_ms); 392 uma_container_->delay_counter_.Add(avg_delay_ms);
383 uma_container_->max_delay_counter_.Add(max_delay_ms); 393 uma_container_->max_delay_counter_.Add(max_delay_ms);
384 } 394 }
385 395
396 void SendStatisticsProxy::OnSendPacket(uint16_t packet_id,
397 int64_t capture_time_ms,
398 uint32_t ssrc) {
399 rtc::CritScope lock(&crit_);
400 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
401 if (stats == nullptr)
402 return;
403
404 int64_t now = clock_->TimeInMilliseconds();
405 RemoveOld(now, &packets_);
406
407 if (packets_.size() > kMaxSendPacketMapSize)
408 return;
409
410 packets_.insert(
411 std::make_pair(packet_id, Packet(ssrc, capture_time_ms, now)));
412 }
413
414 bool SendStatisticsProxy::OnSentPacket(int packet_id) {
415 if (packet_id == -1)
416 return false;
417
418 rtc::CritScope lock(&crit_);
419 auto it = packets_.find(packet_id);
420 if (it == packets_.end())
421 return false;
422
423 // TODO(asapersson): Update delay_counter_ here (capture -> sent).
424 int diff_send = clock_->TimeInMilliseconds() - it->second.send_time_ms_;
425 uma_container_->send_delay_counters_[it->second.ssrc_].Add(diff_send);
426 packets_.erase(it);
427 return true;
428 }
429
430 void SendStatisticsProxy::RemoveOld(int64_t now, PacketMap* packets) {
431 while (!packets->empty()) {
432 auto it = packets->begin();
433 if (now - it->second.capture_time_ms_ < kMaxSentPacketDelayMs) {
stefan-webrtc 2016/01/18 19:48:25 Feel free to remove {}
åsapersson 2016/04/06 14:52:37 Done.
434 break;
435 }
436 packets->erase(it);
437 }
438 }
439
386 void SendStatisticsProxy::SampleCounter::Add(int sample) { 440 void SendStatisticsProxy::SampleCounter::Add(int sample) {
387 sum += sample; 441 sum += sample;
388 ++num_samples; 442 ++num_samples;
389 } 443 }
390 444
391 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { 445 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const {
392 if (num_samples < min_required_samples || num_samples == 0) 446 if (num_samples < min_required_samples || num_samples == 0)
393 return -1; 447 return -1;
394 return (sum + (num_samples / 2)) / num_samples; 448 return (sum + (num_samples / 2)) / num_samples;
395 } 449 }
(...skipping 14 matching lines...) Expand all
410 return Fraction(min_required_samples, 1000.0f); 464 return Fraction(min_required_samples, 1000.0f);
411 } 465 }
412 466
413 int SendStatisticsProxy::BoolSampleCounter::Fraction( 467 int SendStatisticsProxy::BoolSampleCounter::Fraction(
414 int min_required_samples, float multiplier) const { 468 int min_required_samples, float multiplier) const {
415 if (num_samples < min_required_samples || num_samples == 0) 469 if (num_samples < min_required_samples || num_samples == 0)
416 return -1; 470 return -1;
417 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); 471 return static_cast<int>((sum * multiplier / num_samples) + 0.5f);
418 } 472 }
419 } // namespace webrtc 473 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698