Chromium Code Reviews| Index: content/renderer/p2p/ipc_socket_factory.cc |
| diff --git a/content/renderer/p2p/ipc_socket_factory.cc b/content/renderer/p2p/ipc_socket_factory.cc |
| index 3dead8f5f0150362ddc69da33eee0aa0deff368c..3b2d1436ab07ad8a620978c84adc57903f13a3fa 100644 |
| --- a/content/renderer/p2p/ipc_socket_factory.cc |
| +++ b/content/renderer/p2p/ipc_socket_factory.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/debug/trace_event.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/message_loop/message_loop_proxy.h" |
| +#include "base/metrics/histogram.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/threading/non_thread_safe.h" |
| #include "content/renderer/media/webrtc_logging.h" |
| @@ -114,6 +115,8 @@ class IpcPacketSocket : public rtc::AsyncPacketSocket, |
| IS_ERROR, |
| }; |
| + void IncrementDiscardCounters(uint32 size); |
|
Alexei Svitkine (slow)
2014/10/27 17:45:21
This should have a comment. What is |size|?
guoweis2
2014/10/27 18:07:07
Done.
|
| + |
| // Update trace of send throttling internal state. This should be called |
| // immediately after any changes to |send_bytes_available_| and/or |
| // |in_flight_packet_sizes_|. |
| @@ -161,6 +164,15 @@ class IpcPacketSocket : public rtc::AsyncPacketSocket, |
| int error_; |
| int options_[P2P_SOCKET_OPT_MAX]; |
| + // Track the maximum & current consecutive bytes discarded due to not enough |
| + // send_bytes_available_. |
| + uint32 max_discard_bytes_sequence_; |
| + uint32 cur_discard_bytes_sequence_; |
| + |
| + // Track total count of packet drops and attempt of packet sends. |
| + uint32 packets_discarded_; |
| + uint32 total_packets_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(IpcPacketSocket); |
| }; |
| @@ -195,7 +207,11 @@ IpcPacketSocket::IpcPacketSocket() |
| state_(IS_UNINITIALIZED), |
| send_bytes_available_(kMaximumInFlightBytes), |
| writable_signal_expected_(false), |
| - error_(0) { |
| + error_(0), |
| + max_discard_bytes_sequence_(0), |
| + cur_discard_bytes_sequence_(0), |
| + packets_discarded_(0), |
| + total_packets_(0) { |
| COMPILE_ASSERT(kMaximumInFlightBytes > 0, would_send_at_zero_rate); |
| std::fill_n(options_, static_cast<int> (P2P_SOCKET_OPT_MAX), |
| kDefaultNonSetOptionValue); |
| @@ -206,6 +222,15 @@ IpcPacketSocket::~IpcPacketSocket() { |
| state_ == IS_ERROR) { |
| Close(); |
| } |
| + |
| + UMA_HISTOGRAM_COUNTS_10000("WebRTC.MaxApplicationConsecutiveBytesDiscard", |
| + max_discard_bytes_sequence_); |
| + |
| + if (total_packets_ > 0) { |
| + UMA_HISTOGRAM_PERCENTAGE("WebRTC.PacketDiscardByApplication", |
| + ((static_cast<double>(packets_discarded_)) / |
| + (static_cast<double>(total_packets_)) * 100.0)); |
|
Alexei Svitkine (slow)
2014/10/27 17:45:21
The usual way to do this is:
(packets_discarded_
guoweis2
2014/10/27 18:07:07
Done.
|
| + } |
| } |
| void IpcPacketSocket::TraceSendThrottlingState() const { |
| @@ -215,6 +240,15 @@ void IpcPacketSocket::TraceSendThrottlingState() const { |
| in_flight_packet_sizes_.size()); |
| } |
| +void IpcPacketSocket::IncrementDiscardCounters(uint32 size) { |
| + cur_discard_bytes_sequence_ += size; |
| + packets_discarded_++; |
| + |
| + if (cur_discard_bytes_sequence_ > max_discard_bytes_sequence_) { |
| + max_discard_bytes_sequence_ = cur_discard_bytes_sequence_; |
| + } |
| +} |
| + |
| bool IpcPacketSocket::Init(P2PSocketType type, |
| P2PSocketClientImpl* client, |
| const rtc::SocketAddress& local_address, |
| @@ -316,6 +350,8 @@ int IpcPacketSocket::SendTo(const void *data, size_t data_size, |
| return 0; |
| } |
| + total_packets_++; |
| + |
| if (data_size > send_bytes_available_) { |
| TRACE_EVENT_INSTANT1("p2p", "MaxPendingBytesWouldBlock", |
| TRACE_EVENT_SCOPE_THREAD, |
| @@ -330,7 +366,10 @@ int IpcPacketSocket::SendTo(const void *data, size_t data_size, |
| } |
| error_ = EWOULDBLOCK; |
| + IncrementDiscardCounters(data_size); |
| return -1; |
| + } else { |
| + cur_discard_bytes_sequence_ = 0; |
| } |
| net::IPEndPoint address_chrome; |