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

Side by Side Diff: net/nqe/event_creator.cc

Issue 2643213003: NQE: Add net log events when there is a significant change in metrics (Closed)
Patch Set: ps Created 3 years, 11 months 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 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/nqe/event_creator.h" 5 #include "net/nqe/event_creator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 20 matching lines...) Expand all
31 dict->SetInteger("http_rtt_ms", http_rtt.InMilliseconds()); 31 dict->SetInteger("http_rtt_ms", http_rtt.InMilliseconds());
32 dict->SetInteger("transport_rtt_ms", transport_rtt.InMilliseconds()); 32 dict->SetInteger("transport_rtt_ms", transport_rtt.InMilliseconds());
33 dict->SetInteger("downstream_throughput_kbps", downstream_throughput_kbps); 33 dict->SetInteger("downstream_throughput_kbps", downstream_throughput_kbps);
34 dict->SetString("effective_connection_type", 34 dict->SetString("effective_connection_type",
35 GetNameForEffectiveConnectionType(effective_connection_type)); 35 GetNameForEffectiveConnectionType(effective_connection_type));
36 return std::move(dict); 36 return std::move(dict);
37 } 37 }
38 38
39 } // namespace 39 } // namespace
40 40
41 void AddEffectiveConnectionTypeChangedEventToNetLog( 41 EventCreator::EventCreator(NetLogWithSource net_log)
42 const NetLogWithSource& net_log, 42 : net_log_(net_log),
43 base::TimeDelta http_rtt, 43 past_effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {}
44 base::TimeDelta transport_rtt, 44
45 int32_t downstream_throughput_kbps, 45 EventCreator::~EventCreator() {
46 EffectiveConnectionType effective_connection_type) { 46 DCHECK(thread_checker_.CalledOnValidThread());
47 net_log.AddEvent( 47 }
48
49 void EventCreator::MaybeAddEffectiveConnectionTypeChangedEventToNetLog(
50 EffectiveConnectionType effective_connection_type,
51 const NetworkQuality& network_quality) {
52 DCHECK(thread_checker_.CalledOnValidThread());
53
54 // Check if any of the network quality metrics changed significantly.
55 bool effective_connection_type_changed =
56 past_effective_connection_type_ != effective_connection_type;
57 bool http_rtt_changed = (past_network_quality_.http_rtt() == InvalidRTT() &&
RyanSturm 2017/01/25 22:56:50 nit: this pattern can be flattened a little bit:
tbansal1 2017/01/26 00:05:45 Thanks, this cleaned up the code a lot. Done.
58 network_quality.http_rtt() != InvalidRTT()) ||
59 (past_network_quality_.http_rtt() != InvalidRTT() &&
60 network_quality.http_rtt() == InvalidRTT());
61 bool transport_rtt_changed =
62 (past_network_quality_.transport_rtt() == InvalidRTT() &&
63 network_quality.transport_rtt() != InvalidRTT()) ||
64 (past_network_quality_.transport_rtt() != InvalidRTT() &&
65 network_quality.transport_rtt() == InvalidRTT());
66 bool kbps_changed =
67 (past_network_quality_.downstream_throughput_kbps() ==
68 INVALID_RTT_THROUGHPUT &&
69 network_quality.downstream_throughput_kbps() !=
70 INVALID_RTT_THROUGHPUT) ||
71 (past_network_quality_.downstream_throughput_kbps() !=
72 INVALID_RTT_THROUGHPUT &&
73 network_quality.downstream_throughput_kbps() == INVALID_RTT_THROUGHPUT);
74
75 if (!effective_connection_type_changed && !http_rtt_changed &&
76 !transport_rtt_changed && !kbps_changed) {
77 // Return since none of the metrics changed significantly.
RyanSturm 2017/01/25 22:56:50 nit: s/significantly/meaningfully/ This might be m
tbansal1 2017/01/26 00:05:45 Done.
78 return;
79 }
80
81 past_effective_connection_type_ = effective_connection_type;
82 past_network_quality_ = network_quality;
83
84 net_log_.AddEvent(
48 NetLogEventType::NETWORK_QUALITY_CHANGED, 85 NetLogEventType::NETWORK_QUALITY_CHANGED,
49 base::Bind(&EffectiveConnectionTypeChangedNetLogCallback, http_rtt, 86 base::Bind(&EffectiveConnectionTypeChangedNetLogCallback,
50 transport_rtt, downstream_throughput_kbps, 87 network_quality.http_rtt(), network_quality.transport_rtt(),
88 network_quality.downstream_throughput_kbps(),
51 effective_connection_type)); 89 effective_connection_type));
52 } 90 }
53 91
54 } // namespace internal 92 } // namespace internal
55 93
56 } // namespace nqe 94 } // namespace nqe
57 95
58 } // namespace net 96 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698