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

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequest.java

Issue 2351793003: Implement timing metrics for UrlRequest (Closed)
Patch Set: add more testing, and other comments Created 4 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 package org.chromium.net.impl; 5 package org.chromium.net.impl;
6 6
7 import android.os.SystemClock; 7 import android.os.SystemClock;
8 import android.support.annotation.Nullable; 8 import android.support.annotation.Nullable;
9 import android.util.Log; 9 import android.util.Log;
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 @GuardedBy("mUrlRequestAdapterLock") 59 @GuardedBy("mUrlRequestAdapterLock")
60 private boolean mStarted = false; 60 private boolean mStarted = false;
61 @GuardedBy("mUrlRequestAdapterLock") 61 @GuardedBy("mUrlRequestAdapterLock")
62 private boolean mWaitingOnRedirect = false; 62 private boolean mWaitingOnRedirect = false;
63 @GuardedBy("mUrlRequestAdapterLock") 63 @GuardedBy("mUrlRequestAdapterLock")
64 private boolean mWaitingOnRead = false; 64 private boolean mWaitingOnRead = false;
65 @GuardedBy("mUrlRequestAdapterLock") 65 @GuardedBy("mUrlRequestAdapterLock")
66 @Nullable 66 @Nullable
67 private final UrlRequestMetricsAccumulator mRequestMetricsAccumulator; 67 private final UrlRequestMetricsAccumulator mRequestMetricsAccumulator;
68 @GuardedBy("mUrlRequestAdapterLock")
69 private RequestFinishedInfo.Metrics mMetrics;
68 70
69 /* 71 /*
70 * Synchronize access to mUrlRequestAdapter, mStarted, mWaitingOnRedirect, 72 * Synchronize access to mUrlRequestAdapter, mStarted, mWaitingOnRedirect,
71 * and mWaitingOnRead. 73 * and mWaitingOnRead.
72 */ 74 */
73 private final Object mUrlRequestAdapterLock = new Object(); 75 private final Object mUrlRequestAdapterLock = new Object();
74 private final CronetUrlRequestContext mRequestContext; 76 private final CronetUrlRequestContext mRequestContext;
75 private final Executor mExecutor; 77 private final Executor mExecutor;
76 78
77 /* 79 /*
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 196 }
195 197
196 @Override 198 @Override
197 public void start() { 199 public void start() {
198 synchronized (mUrlRequestAdapterLock) { 200 synchronized (mUrlRequestAdapterLock) {
199 checkNotStarted(); 201 checkNotStarted();
200 202
201 try { 203 try {
202 mUrlRequestAdapter = 204 mUrlRequestAdapter =
203 nativeCreateRequestAdapter(mRequestContext.getUrlRequest ContextAdapter(), 205 nativeCreateRequestAdapter(mRequestContext.getUrlRequest ContextAdapter(),
204 mInitialUrl, mPriority, mDisableCache, mDisableC onnectionMigration); 206 mInitialUrl, mPriority, mDisableCache, mDisableC onnectionMigration,
207 mRequestContext.hasRequestFinishedListener());
xunjieli 2016/09/20 21:53:33 Can we just use the metricsCollectionEnabled field
mgersh 2016/09/30 23:47:14 I was actually planning on deleting that field, so
xunjieli 2016/10/01 13:43:49 Why do you plan to delete that field? We don't win
mgersh 2016/10/04 21:14:58 Mostly because I prefer not having that informatio
xunjieli 2016/10/04 22:29:23 Acknowledged.
205 mRequestContext.onRequestStarted(); 208 mRequestContext.onRequestStarted();
206 if (mInitialMethod != null) { 209 if (mInitialMethod != null) {
207 if (!nativeSetHttpMethod(mUrlRequestAdapter, mInitialMethod) ) { 210 if (!nativeSetHttpMethod(mUrlRequestAdapter, mInitialMethod) ) {
208 throw new IllegalArgumentException("Invalid http method " + mInitialMethod); 211 throw new IllegalArgumentException("Invalid http method " + mInitialMethod);
209 } 212 }
210 } 213 }
211 214
212 boolean hasContentType = false; 215 boolean hasContentType = false;
213 for (Map.Entry<String, String> header : mRequestHeaders) { 216 for (Map.Entry<String, String> header : mRequestHeaders) {
214 if (header.getKey().equalsIgnoreCase("Content-Type") 217 if (header.getKey().equalsIgnoreCase("Content-Type")
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 private void onStatus(final UrlRequest.StatusListener listener, final int lo adState) { 695 private void onStatus(final UrlRequest.StatusListener listener, final int lo adState) {
693 Runnable task = new Runnable() { 696 Runnable task = new Runnable() {
694 @Override 697 @Override
695 public void run() { 698 public void run() {
696 listener.onStatus(UrlRequest.Status.convertLoadState(loadState)) ; 699 listener.onStatus(UrlRequest.Status.convertLoadState(loadState)) ;
697 } 700 }
698 }; 701 };
699 postTaskToExecutor(task); 702 postTaskToExecutor(task);
700 } 703 }
701 704
705 /**
706 * Called by the native code to report metrics.
707 */
708 @SuppressWarnings("unused")
709 @CalledByNative
710 private void onMetricsCollected(long requestStartMs, long dnsStartMs, long d nsEndMs,
711 long connectStartMs, long connectEndMs, long sslStartMs, long sslEnd Ms,
712 long sendingStartMs, long sendingEndMs, long pushStartMs, long pushE ndMs,
713 long responseStartMs, long responseEndMs, boolean socketReused, long sentBytesCount,
714 long receivedBytesCount) {
715 synchronized (mUrlRequestAdapterLock) {
716 if (mMetrics != null) {
717 throw new IllegalStateException("Metrics collection should only happen once.");
718 }
719 mMetrics = new CronetMetrics(requestStartMs, dnsStartMs, dnsEndMs, c onnectStartMs,
720 connectEndMs, sslStartMs, sslEndMs, sendingStartMs, sendingE ndMs, pushStartMs,
721 pushEndMs, responseStartMs, responseEndMs, socketReused, sen tBytesCount,
722 receivedBytesCount);
723 }
724 }
725
702 RequestFinishedInfo getRequestFinishedInfo() { 726 RequestFinishedInfo getRequestFinishedInfo() {
703 // TODO(mgersh): fill in real values for finishedReason and exception 727 // TODO(mgersh): fill in real values for finishedReason and exception
704 return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, 728 return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, mMetric s,
705 (mRequestMetricsAccumulator != null ? mRequestMetricsAccumulator .getRequestMetrics()
706 : EMPTY_METRICS),
707 RequestFinishedInfo.SUCCEEDED, mResponseInfo, null); 729 RequestFinishedInfo.SUCCEEDED, mResponseInfo, null);
708 } 730 }
709 731
710 private final class UrlRequestMetricsAccumulator { 732 private final class UrlRequestMetricsAccumulator {
711 @Nullable 733 @Nullable
712 private Long mRequestStartTime; 734 private Long mRequestStartTime;
713 @Nullable 735 @Nullable
714 private Long mTtfbMs; 736 private Long mTtfbMs;
715 @Nullable 737 @Nullable
716 private Long mTotalTimeMs; 738 private Long mTotalTimeMs;
(...skipping 27 matching lines...) Expand all
744 /** Enforces prohibition of direct execution. */ 766 /** Enforces prohibition of direct execution. */
745 void checkCallingThread() { 767 void checkCallingThread() {
746 if (!mAllowDirectExecutor && mRequestContext.isNetworkThread(Thread.curr entThread())) { 768 if (!mAllowDirectExecutor && mRequestContext.isNetworkThread(Thread.curr entThread())) {
747 throw new InlineExecutionProhibitedException(); 769 throw new InlineExecutionProhibitedException();
748 } 770 }
749 } 771 }
750 772
751 // Native methods are implemented in cronet_url_request_adapter.cc. 773 // Native methods are implemented in cronet_url_request_adapter.cc.
752 774
753 private native long nativeCreateRequestAdapter(long urlRequestContextAdapter , String url, 775 private native long nativeCreateRequestAdapter(long urlRequestContextAdapter , String url,
754 int priority, boolean disableCache, boolean disableConnectionMigrati on); 776 int priority, boolean disableCache, boolean disableConnectionMigrati on,
777 boolean enableMetrics);
755 778
756 @NativeClassQualifiedName("CronetURLRequestAdapter") 779 @NativeClassQualifiedName("CronetURLRequestAdapter")
757 private native boolean nativeSetHttpMethod(long nativePtr, String method); 780 private native boolean nativeSetHttpMethod(long nativePtr, String method);
758 781
759 @NativeClassQualifiedName("CronetURLRequestAdapter") 782 @NativeClassQualifiedName("CronetURLRequestAdapter")
760 private native boolean nativeAddRequestHeader(long nativePtr, String name, S tring value); 783 private native boolean nativeAddRequestHeader(long nativePtr, String name, S tring value);
761 784
762 @NativeClassQualifiedName("CronetURLRequestAdapter") 785 @NativeClassQualifiedName("CronetURLRequestAdapter")
763 private native void nativeStart(long nativePtr); 786 private native void nativeStart(long nativePtr);
764 787
765 @NativeClassQualifiedName("CronetURLRequestAdapter") 788 @NativeClassQualifiedName("CronetURLRequestAdapter")
766 private native void nativeFollowDeferredRedirect(long nativePtr); 789 private native void nativeFollowDeferredRedirect(long nativePtr);
767 790
768 @NativeClassQualifiedName("CronetURLRequestAdapter") 791 @NativeClassQualifiedName("CronetURLRequestAdapter")
769 private native boolean nativeReadData( 792 private native boolean nativeReadData(
770 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); 793 long nativePtr, ByteBuffer byteBuffer, int position, int capacity);
771 794
772 @NativeClassQualifiedName("CronetURLRequestAdapter") 795 @NativeClassQualifiedName("CronetURLRequestAdapter")
773 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); 796 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled);
774 797
775 @NativeClassQualifiedName("CronetURLRequestAdapter") 798 @NativeClassQualifiedName("CronetURLRequestAdapter")
776 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener); 799 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener);
777 } 800 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698