OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/chromium/quic_connection_logger.h" | 5 #include "net/quic/chromium/quic_connection_logger.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/histogram_base.h" | 16 #include "base/metrics/histogram_base.h" |
16 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
17 #include "base/metrics/sparse_histogram.h" | 18 #include "base/metrics/sparse_histogram.h" |
18 #include "base/profiler/scoped_tracker.h" | 19 #include "base/profiler/scoped_tracker.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
21 #include "net/base/ip_address.h" | 22 #include "net/base/ip_address.h" |
22 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
23 #include "net/log/net_log.h" | 24 #include "net/log/net_log.h" |
24 #include "net/log/net_log_capture_mode.h" | 25 #include "net/log/net_log_capture_mode.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 dict->SetInteger("stream_id", frame->stream_id); | 102 dict->SetInteger("stream_id", frame->stream_id); |
102 dict->SetBoolean("fin", frame->fin); | 103 dict->SetBoolean("fin", frame->fin); |
103 dict->SetString("offset", base::Uint64ToString(frame->offset)); | 104 dict->SetString("offset", base::Uint64ToString(frame->offset)); |
104 dict->SetInteger("length", frame->data_length); | 105 dict->SetInteger("length", frame->data_length); |
105 return std::move(dict); | 106 return std::move(dict); |
106 } | 107 } |
107 | 108 |
108 std::unique_ptr<base::Value> NetLogQuicAckFrameCallback( | 109 std::unique_ptr<base::Value> NetLogQuicAckFrameCallback( |
109 const QuicAckFrame* frame, | 110 const QuicAckFrame* frame, |
110 NetLogCaptureMode /* capture_mode */) { | 111 NetLogCaptureMode /* capture_mode */) { |
111 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 112 auto dict = base::MakeUnique<base::DictionaryValue>(); |
112 dict->SetString("largest_observed", | 113 dict->SetString("largest_observed", |
113 base::Uint64ToString(frame->largest_observed)); | 114 base::Uint64ToString(frame->largest_observed)); |
114 dict->SetString("delta_time_largest_observed_us", | 115 dict->SetString("delta_time_largest_observed_us", |
115 base::Int64ToString(frame->ack_delay_time.ToMicroseconds())); | 116 base::Int64ToString(frame->ack_delay_time.ToMicroseconds())); |
116 | 117 |
117 base::ListValue* missing = new base::ListValue(); | 118 auto missing = base::MakeUnique<base::ListValue>(); |
118 dict->Set("missing_packets", missing); | |
119 if (!frame->packets.Empty()) { | 119 if (!frame->packets.Empty()) { |
120 // V34 and above express acked packets, but only print | 120 // V34 and above express acked packets, but only print |
121 // missing packets, because it's typically a shorter list. | 121 // missing packets, because it's typically a shorter list. |
122 for (QuicPacketNumber packet = frame->packets.Min(); | 122 for (QuicPacketNumber packet = frame->packets.Min(); |
123 packet < frame->largest_observed; ++packet) { | 123 packet < frame->largest_observed; ++packet) { |
124 if (!frame->packets.Contains(packet)) { | 124 if (!frame->packets.Contains(packet)) { |
125 missing->AppendString(base::Uint64ToString(packet)); | 125 missing->AppendString(base::Uint64ToString(packet)); |
126 } | 126 } |
127 } | 127 } |
128 } | 128 } |
| 129 dict->Set("missing_packets", std::move(missing)); |
129 | 130 |
130 base::ListValue* received = new base::ListValue(); | 131 auto received = base::MakeUnique<base::ListValue>(); |
131 dict->Set("received_packet_times", received); | |
132 const PacketTimeVector& received_times = frame->received_packet_times; | 132 const PacketTimeVector& received_times = frame->received_packet_times; |
133 for (PacketTimeVector::const_iterator it = received_times.begin(); | 133 for (PacketTimeVector::const_iterator it = received_times.begin(); |
134 it != received_times.end(); ++it) { | 134 it != received_times.end(); ++it) { |
135 std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue()); | 135 auto info = base::MakeUnique<base::DictionaryValue>(); |
136 info->SetInteger("packet_number", static_cast<int>(it->first)); | 136 info->SetInteger("packet_number", static_cast<int>(it->first)); |
137 info->SetString("received", | 137 info->SetString("received", |
138 base::Int64ToString(it->second.ToDebuggingValue())); | 138 base::Int64ToString(it->second.ToDebuggingValue())); |
139 received->Append(std::move(info)); | 139 received->Append(std::move(info)); |
140 } | 140 } |
| 141 dict->Set("received_packet_times", std::move(received)); |
141 | 142 |
142 return std::move(dict); | 143 return std::move(dict); |
143 } | 144 } |
144 | 145 |
145 std::unique_ptr<base::Value> NetLogQuicRstStreamFrameCallback( | 146 std::unique_ptr<base::Value> NetLogQuicRstStreamFrameCallback( |
146 const QuicRstStreamFrame* frame, | 147 const QuicRstStreamFrame* frame, |
147 NetLogCaptureMode /* capture_mode */) { | 148 NetLogCaptureMode /* capture_mode */) { |
148 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 149 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
149 dict->SetInteger("stream_id", frame->stream_id); | 150 dict->SetInteger("stream_id", frame->stream_id); |
150 dict->SetInteger("quic_rst_stream_error", frame->error_code); | 151 dict->SetInteger("quic_rst_stream_error", frame->error_code); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 184 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
184 dict->SetInteger("quic_error", frame->error_code); | 185 dict->SetInteger("quic_error", frame->error_code); |
185 dict->SetInteger("last_good_stream_id", frame->last_good_stream_id); | 186 dict->SetInteger("last_good_stream_id", frame->last_good_stream_id); |
186 dict->SetString("reason_phrase", frame->reason_phrase); | 187 dict->SetString("reason_phrase", frame->reason_phrase); |
187 return std::move(dict); | 188 return std::move(dict); |
188 } | 189 } |
189 | 190 |
190 std::unique_ptr<base::Value> NetLogQuicStopWaitingFrameCallback( | 191 std::unique_ptr<base::Value> NetLogQuicStopWaitingFrameCallback( |
191 const QuicStopWaitingFrame* frame, | 192 const QuicStopWaitingFrame* frame, |
192 NetLogCaptureMode /* capture_mode */) { | 193 NetLogCaptureMode /* capture_mode */) { |
193 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 194 auto dict = base::MakeUnique<base::DictionaryValue>(); |
194 base::DictionaryValue* sent_info = new base::DictionaryValue(); | 195 auto sent_info = base::MakeUnique<base::DictionaryValue>(); |
195 dict->Set("sent_info", sent_info); | |
196 sent_info->SetString("least_unacked", | 196 sent_info->SetString("least_unacked", |
197 base::Uint64ToString(frame->least_unacked)); | 197 base::Uint64ToString(frame->least_unacked)); |
| 198 dict->Set("sent_info", std::move(sent_info)); |
198 return std::move(dict); | 199 return std::move(dict); |
199 } | 200 } |
200 | 201 |
201 std::unique_ptr<base::Value> NetLogQuicVersionNegotiationPacketCallback( | 202 std::unique_ptr<base::Value> NetLogQuicVersionNegotiationPacketCallback( |
202 const QuicVersionNegotiationPacket* packet, | 203 const QuicVersionNegotiationPacket* packet, |
203 NetLogCaptureMode /* capture_mode */) { | 204 NetLogCaptureMode /* capture_mode */) { |
204 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 205 auto dict = base::MakeUnique<base::DictionaryValue>(); |
205 base::ListValue* versions = new base::ListValue(); | 206 auto versions = base::MakeUnique<base::ListValue>(); |
206 dict->Set("versions", versions); | |
207 for (QuicVersionVector::const_iterator it = packet->versions.begin(); | 207 for (QuicVersionVector::const_iterator it = packet->versions.begin(); |
208 it != packet->versions.end(); ++it) { | 208 it != packet->versions.end(); ++it) { |
209 versions->AppendString(QuicVersionToString(*it)); | 209 versions->AppendString(QuicVersionToString(*it)); |
210 } | 210 } |
| 211 dict->Set("versions", std::move(versions)); |
211 return std::move(dict); | 212 return std::move(dict); |
212 } | 213 } |
213 | 214 |
214 std::unique_ptr<base::Value> NetLogQuicPublicResetPacketCallback( | 215 std::unique_ptr<base::Value> NetLogQuicPublicResetPacketCallback( |
215 const IPEndPoint* server_hello_address, | 216 const IPEndPoint* server_hello_address, |
216 const IPEndPoint* public_reset_address, | 217 const IPEndPoint* public_reset_address, |
217 NetLogCaptureMode /* capture_mode */) { | 218 NetLogCaptureMode /* capture_mode */) { |
218 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 219 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
219 dict->SetString("server_hello_address", server_hello_address->ToString()); | 220 dict->SetString("server_hello_address", server_hello_address->ToString()); |
220 dict->SetString("public_reset_address", public_reset_address->ToString()); | 221 dict->SetString("public_reset_address", public_reset_address->ToString()); |
(...skipping 20 matching lines...) Expand all Loading... |
241 return std::move(dict); | 242 return std::move(dict); |
242 } | 243 } |
243 | 244 |
244 std::unique_ptr<base::Value> NetLogQuicCertificateVerifiedCallback( | 245 std::unique_ptr<base::Value> NetLogQuicCertificateVerifiedCallback( |
245 scoped_refptr<X509Certificate> cert, | 246 scoped_refptr<X509Certificate> cert, |
246 NetLogCaptureMode /* capture_mode */) { | 247 NetLogCaptureMode /* capture_mode */) { |
247 // Only the subjects are logged so that we can investigate connection pooling. | 248 // Only the subjects are logged so that we can investigate connection pooling. |
248 // More fields could be logged in the future. | 249 // More fields could be logged in the future. |
249 std::vector<std::string> dns_names; | 250 std::vector<std::string> dns_names; |
250 cert->GetDNSNames(&dns_names); | 251 cert->GetDNSNames(&dns_names); |
251 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 252 auto dict = base::MakeUnique<base::DictionaryValue>(); |
252 base::ListValue* subjects = new base::ListValue(); | 253 auto subjects = base::MakeUnique<base::ListValue>(); |
253 for (std::vector<std::string>::const_iterator it = dns_names.begin(); | 254 for (auto& dns_name : dns_names) { |
254 it != dns_names.end(); it++) { | 255 subjects->GetList().emplace_back(std::move(dns_name)); |
255 subjects->AppendString(*it); | |
256 } | 256 } |
257 dict->Set("subjects", subjects); | 257 dict->Set("subjects", std::move(subjects)); |
258 return std::move(dict); | 258 return std::move(dict); |
259 } | 259 } |
260 | 260 |
261 void UpdatePublicResetAddressMismatchHistogram( | 261 void UpdatePublicResetAddressMismatchHistogram( |
262 const IPEndPoint& server_hello_address, | 262 const IPEndPoint& server_hello_address, |
263 const IPEndPoint& public_reset_address) { | 263 const IPEndPoint& public_reset_address) { |
264 int sample = GetAddressMismatch(server_hello_address, public_reset_address); | 264 int sample = GetAddressMismatch(server_hello_address, public_reset_address); |
265 // We are seemingly talking to an older server that does not support the | 265 // We are seemingly talking to an older server that does not support the |
266 // feature, so we can't report the results in the histogram. | 266 // feature, so we can't report the results in the histogram. |
267 if (sample < 0) { | 267 if (sample < 0) { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 | 706 |
707 string prefix("Net.QuicSession.PacketLossRate_"); | 707 string prefix("Net.QuicSession.PacketLossRate_"); |
708 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 708 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
709 prefix + connection_description_, 1, 1000, 75, | 709 prefix + connection_description_, 1, 1000, 75, |
710 base::HistogramBase::kUmaTargetedHistogramFlag); | 710 base::HistogramBase::kUmaTargetedHistogramFlag); |
711 histogram->Add(static_cast<base::HistogramBase::Sample>( | 711 histogram->Add(static_cast<base::HistogramBase::Sample>( |
712 ReceivedPacketLossRate() * 1000)); | 712 ReceivedPacketLossRate() * 1000)); |
713 } | 713 } |
714 | 714 |
715 } // namespace net | 715 } // namespace net |
OLD | NEW |