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

Unified Diff: components/cronet/android/java/src/org/chromium/net/impl/CronetMetrics.java

Issue 2220023002: Add API for new Cronet metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and add request start (how did I miss that?) 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/java/src/org/chromium/net/impl/CronetMetrics.java
diff --git a/components/cronet/android/java/src/org/chromium/net/impl/CronetMetrics.java b/components/cronet/android/java/src/org/chromium/net/impl/CronetMetrics.java
new file mode 100644
index 0000000000000000000000000000000000000000..5fb76b083b64e09feb8fd986261e9d4753bf86ab
--- /dev/null
+++ b/components/cronet/android/java/src/org/chromium/net/impl/CronetMetrics.java
@@ -0,0 +1,215 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.net.impl;
+
+import android.support.annotation.Nullable;
+
+import org.chromium.base.VisibleForTesting;
+import org.chromium.net.RequestFinishedInfo;
+
+import java.util.Date;
+
+/**
+ * Implementation of RequestFinishedInfo.Metrics
xunjieli 2016/09/05 23:24:17 nit: Add a {@link} and a period at the end of the
mgersh 2016/09/07 22:09:58 Done.
+ */
+@VisibleForTesting
+public final class CronetMetrics extends RequestFinishedInfo.Metrics {
+ private final long mRequestStartMs;
+ private final long mDnsStartMs;
+ private final long mDnsEndMs;
+ private final long mConnectStartMs;
+ private final long mConnectEndMs;
+ private final long mSslStartMs;
+ private final long mSslEndMs;
+ private final long mSendingStartMs;
+ private final long mSendingEndMs;
+ private final long mPushStartMs;
+ private final long mPushEndMs;
+ private final long mResponseStartMs;
+ private final long mResponseEndMs;
+ private final boolean mSocketReused;
+
+ // TODO(mgersh): Delete once we switch to the new API http://crbug.com/629194
mef 2016/09/07 21:10:50 nit: s/once we/after/g
mgersh 2016/09/07 22:09:58 Done, but could you explain why? Is first person d
+ @Nullable
+ private final Long mTtfbMs;
+ // TODO(mgersh): Delete once we switch to the new API http://crbug.com/629194
+ @Nullable
+ private final Long mTotalTimeMs;
+ @Nullable
+ private final Long mSentBytesCount;
+ @Nullable
+ private final Long mReceivedBytesCount;
+
+ @Nullable
+ private static Date toDate(long timestamp) {
+ if (timestamp != 0) {
+ return new Date(timestamp);
+ }
+ return null;
+ }
+
+ /**
+ * Old-style constructor
+ * TODO(mgersh): Delete once we switch to the new API http://crbug.com/629194
+ */
+ public CronetMetrics(@Nullable Long ttfbMs, @Nullable Long totalTimeMs,
+ @Nullable Long sentBytesCount, @Nullable Long receivedBytesCount) {
+ mTtfbMs = ttfbMs;
+ mTotalTimeMs = totalTimeMs;
+ mSentBytesCount = sentBytesCount;
+ mReceivedBytesCount = receivedBytesCount;
+
+ // Everything else is 0 for now
xunjieli 2016/09/05 23:24:17 Should the null case be -1 instead of 0? See my ot
mgersh 2016/09/07 22:09:58 Done.
+ mRequestStartMs = 0;
+ mDnsStartMs = 0;
+ mDnsEndMs = 0;
+ mConnectStartMs = 0;
+ mConnectEndMs = 0;
+ mSslStartMs = 0;
+ mSslEndMs = 0;
+ mSendingStartMs = 0;
+ mSendingEndMs = 0;
+ mPushStartMs = 0;
+ mPushEndMs = 0;
+ mResponseStartMs = 0;
+ mResponseEndMs = 0;
+ mSocketReused = false;
+ }
+
+ /**
+ * New-style constructor
+ */
+ public CronetMetrics(long requestStartMs, long dnsStartMs, long dnsEndMs, long connectStartMs,
+ long connectEndMs, long sslStartMs, long sslEndMs, long sendingStartMs,
+ long sendingEndMs, long pushStartMs, long pushEndMs, long responseStartMs,
+ long responseEndMs, boolean socketReused, long sentBytesCount,
+ long receivedBytesCount) {
+ // Check that no end times are before corresponding start times
+ // Case where end time is 0 is needed in case request fails/errors before end
+ assert dnsEndMs >= dnsStartMs || dnsEndMs == 0;
+ assert connectEndMs >= connectStartMs || connectEndMs == 0;
+ assert sslEndMs >= sslStartMs || sslEndMs == 0;
+ assert sendingEndMs >= sendingStartMs || sendingEndMs == 0;
+ assert pushEndMs >= pushStartMs || pushEndMs == 0;
+ assert responseEndMs >= responseStartMs || responseEndMs == 0;
+ // Spot-check some of the other orderings
+ assert dnsStartMs >= requestStartMs || dnsStartMs == 0;
+ assert sendingStartMs >= requestStartMs || sendingStartMs == 0;
+ assert sslStartMs >= connectStartMs || sslStartMs == 0;
+ assert connectEndMs >= sslEndMs || connectEndMs == 0;
+ assert sendingStartMs >= connectEndMs || sendingStartMs == 0;
+ assert responseStartMs >= sendingStartMs || responseStartMs == 0;
+ mRequestStartMs = requestStartMs;
+ mDnsStartMs = dnsStartMs;
+ mDnsEndMs = dnsEndMs;
+ mConnectStartMs = connectStartMs;
+ mConnectEndMs = connectEndMs;
+ mSslStartMs = sslStartMs;
+ mSslEndMs = sslEndMs;
+ mSendingStartMs = sendingStartMs;
+ mSendingEndMs = sendingEndMs;
+ mPushStartMs = pushStartMs;
+ mPushEndMs = pushEndMs;
+ mResponseStartMs = responseStartMs;
+ mResponseEndMs = responseEndMs;
+ mSocketReused = socketReused;
+ mSentBytesCount = sentBytesCount;
+ mReceivedBytesCount = receivedBytesCount;
+
+ // Don't care about these anymore
+ mTtfbMs = null;
+ mTotalTimeMs = null;
+ }
+
+ @Nullable
+ public Date getRequestStart() {
+ return toDate(mRequestStartMs);
+ }
+
+ @Nullable
+ public Date getDnsStart() {
+ return toDate(mDnsStartMs);
+ }
+
+ @Nullable
+ public Date getDnsEnd() {
+ return toDate(mDnsEndMs);
+ }
+
+ @Nullable
+ public Date getConnectStart() {
+ return toDate(mConnectStartMs);
+ }
+
+ @Nullable
+ public Date getConnectEnd() {
+ return toDate(mConnectEndMs);
+ }
+
+ @Nullable
+ public Date getSslStart() {
+ return toDate(mSslStartMs);
+ }
+
+ @Nullable
+ public Date getSslEnd() {
+ return toDate(mSslEndMs);
+ }
+
+ @Nullable
+ public Date getSendingStart() {
+ return toDate(mSendingStartMs);
+ }
+
+ @Nullable
+ public Date getSendingEnd() {
+ return toDate(mSendingEndMs);
+ }
+
+ @Nullable
+ public Date getPushStart() {
+ return toDate(mPushStartMs);
+ }
+
+ @Nullable
+ public Date getPushEnd() {
+ return toDate(mPushEndMs);
+ }
+
+ @Nullable
+ public Date getResponseStart() {
+ return toDate(mResponseStartMs);
+ }
+
+ @Nullable
+ public Date getResponseEnd() {
+ return toDate(mResponseEndMs);
+ }
+
+ @Nullable
+ public boolean getSocketReused() {
+ return mSocketReused;
+ }
+
+ @Nullable
+ public Long getTtfbMs() {
+ return mTtfbMs;
+ }
+
+ @Nullable
+ public Long getTotalTimeMs() {
+ return mTotalTimeMs;
+ }
+
+ @Nullable
+ public Long getSentBytesCount() {
+ return mSentBytesCount;
+ }
+
+ @Nullable
+ public Long getReceivedBytesCount() {
+ return mReceivedBytesCount;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698