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

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

Issue 2695783003: NQE: Record the main frame metrics at transaction start (Closed)
Patch Set: Fix comments Created 3 years, 10 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
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/network_quality_estimator.h" 5 #include "net/nqe/network_quality_estimator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 return accuracy_recording_intervals_; 395 return accuracy_recording_intervals_;
396 } 396 }
397 397
398 void NetworkQualityEstimator::NotifyStartTransaction( 398 void NetworkQualityEstimator::NotifyStartTransaction(
399 const URLRequest& request) { 399 const URLRequest& request) {
400 DCHECK(thread_checker_.CalledOnValidThread()); 400 DCHECK(thread_checker_.CalledOnValidThread());
401 401
402 if (!RequestSchemeIsHTTPOrHTTPS(request)) 402 if (!RequestSchemeIsHTTPOrHTTPS(request))
403 return; 403 return;
404 404
405 throughput_analyzer_->NotifyStartTransaction(request);
406 }
407
408 void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) {
409 TRACE_EVENT0(kNetTracingCategory,
410 "NetworkQualityEstimator::NotifyHeadersReceived");
411 DCHECK(thread_checker_.CalledOnValidThread());
412
413 if (!RequestSchemeIsHTTPOrHTTPS(request) ||
414 !RequestProvidesRTTObservation(request)) {
415 return;
416 }
417
418 const base::TimeTicks now = tick_clock_->NowTicks();
419
420 // Update |estimated_quality_at_last_main_frame_| if this is a main frame 405 // Update |estimated_quality_at_last_main_frame_| if this is a main frame
421 // request. 406 // request.
422 // TODO(tbansal): Refactor this to a separate method. 407 // TODO(tbansal): Refactor this to a separate method.
423 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) { 408 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) {
409 base::TimeTicks now = tick_clock_->NowTicks();
424 last_main_frame_request_ = now; 410 last_main_frame_request_ = now;
425 411
426 ComputeEffectiveConnectionType(); 412 ComputeEffectiveConnectionType();
427 effective_connection_type_at_last_main_frame_ = effective_connection_type_; 413 effective_connection_type_at_last_main_frame_ = effective_connection_type_;
428 estimated_quality_at_last_main_frame_ = network_quality_; 414 estimated_quality_at_last_main_frame_ = network_quality_;
429 415
430 RecordMetricsOnMainFrameRequest(); 416 RecordMetricsOnMainFrameRequest();
431 MaybeQueryExternalEstimateProvider(); 417 MaybeQueryExternalEstimateProvider();
432 418
433 // Post the tasks which will run in the future and record the estimation 419 // Post the tasks which will run in the future and record the estimation
434 // accuracy based on the observations received between now and the time of 420 // accuracy based on the observations received between now and the time of
435 // task execution. Posting the task at different intervals makes it 421 // task execution. Posting the task at different intervals makes it
436 // possible to measure the accuracy by comparing the estimate with the 422 // possible to measure the accuracy by comparing the estimate with the
437 // observations received over intervals of varying durations. 423 // observations received over intervals of varying durations.
438 for (const base::TimeDelta& measuring_delay : 424 for (const base::TimeDelta& measuring_delay :
439 GetAccuracyRecordingIntervals()) { 425 GetAccuracyRecordingIntervals()) {
440 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 426 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
441 FROM_HERE, 427 FROM_HERE,
442 base::Bind(&NetworkQualityEstimator::RecordAccuracyAfterMainFrame, 428 base::Bind(&NetworkQualityEstimator::RecordAccuracyAfterMainFrame,
443 weak_ptr_factory_.GetWeakPtr(), measuring_delay), 429 weak_ptr_factory_.GetWeakPtr(), measuring_delay),
444 measuring_delay); 430 measuring_delay);
445 } 431 }
446 } 432 }
433 throughput_analyzer_->NotifyStartTransaction(request);
434 }
435
436 void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) {
437 TRACE_EVENT0(kNetTracingCategory,
438 "NetworkQualityEstimator::NotifyHeadersReceived");
439 DCHECK(thread_checker_.CalledOnValidThread());
440
441 if (!RequestSchemeIsHTTPOrHTTPS(request) ||
442 !RequestProvidesRTTObservation(request)) {
443 return;
444 }
445
446 // Update |estimated_quality_at_last_main_frame_| if this is a main frame
447 // request.
448 // TODO(tbansal): Refactor this to a separate method.
449 if (request.load_flags() & LOAD_MAIN_FRAME_DEPRECATED) {
450 ComputeEffectiveConnectionType();
451 }
447 452
448 LoadTimingInfo load_timing_info; 453 LoadTimingInfo load_timing_info;
449 request.GetLoadTimingInfo(&load_timing_info); 454 request.GetLoadTimingInfo(&load_timing_info);
450 455
451 // If the load timing info is unavailable, it probably means that the request 456 // If the load timing info is unavailable, it probably means that the request
452 // did not go over the network. 457 // did not go over the network.
453 if (load_timing_info.send_start.is_null() || 458 if (load_timing_info.send_start.is_null() ||
454 load_timing_info.receive_headers_end.is_null()) { 459 load_timing_info.receive_headers_end.is_null()) {
455 return; 460 return;
456 } 461 }
457 DCHECK(!request.response_info().was_cached); 462 DCHECK(!request.response_info().was_cached);
458 463
459 // Duration between when the resource was requested and when the response 464 // Duration between when the resource was requested and when the response
460 // headers were received. 465 // headers were received.
461 base::TimeDelta observed_http_rtt = 466 base::TimeDelta observed_http_rtt =
462 load_timing_info.receive_headers_end - load_timing_info.send_start; 467 load_timing_info.receive_headers_end - load_timing_info.send_start;
463 DCHECK_GE(observed_http_rtt, base::TimeDelta()); 468 DCHECK_GE(observed_http_rtt, base::TimeDelta());
464 if (observed_http_rtt < peak_network_quality_.http_rtt() || 469 if (observed_http_rtt < peak_network_quality_.http_rtt() ||
465 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { 470 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) {
466 peak_network_quality_ = nqe::internal::NetworkQuality( 471 peak_network_quality_ = nqe::internal::NetworkQuality(
467 observed_http_rtt, peak_network_quality_.transport_rtt(), 472 observed_http_rtt, peak_network_quality_.transport_rtt(),
468 peak_network_quality_.downstream_throughput_kbps()); 473 peak_network_quality_.downstream_throughput_kbps());
469 } 474 }
470 475
471 RttObservation http_rtt_observation(observed_http_rtt, now, 476 RttObservation http_rtt_observation(
472 signal_strength_dbm_, 477 observed_http_rtt, tick_clock_->NowTicks(), signal_strength_dbm_,
473 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); 478 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP);
474 rtt_observations_.AddObservation(http_rtt_observation); 479 rtt_observations_.AddObservation(http_rtt_observation);
475 NotifyObserversOfRTT(http_rtt_observation); 480 NotifyObserversOfRTT(http_rtt_observation);
476 } 481 }
477 482
478 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( 483 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame(
479 base::TimeDelta measuring_duration) const { 484 base::TimeDelta measuring_duration) const {
480 DCHECK(thread_checker_.CalledOnValidThread()); 485 DCHECK(thread_checker_.CalledOnValidThread());
481 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); 486 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000);
482 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration)); 487 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration));
483 488
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE); 1752 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE);
1748 downstream_throughput_kbps_observations_.AddObservation( 1753 downstream_throughput_kbps_observations_.AddObservation(
1749 throughput_observation); 1754 throughput_observation);
1750 NotifyObserversOfThroughput(throughput_observation); 1755 NotifyObserversOfThroughput(throughput_observation);
1751 } 1756 }
1752 1757
1753 ComputeEffectiveConnectionType(); 1758 ComputeEffectiveConnectionType();
1754 } 1759 }
1755 1760
1756 } // namespace net 1761 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698