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

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: Separate Metrics API and impl, and improve documentation Created 4 years, 4 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..0c4133b63223c511e0aa9efd07cd8c2d46950d7e
--- /dev/null
+++ b/components/cronet/android/java/src/org/chromium/net/impl/CronetMetrics.java
@@ -0,0 +1,202 @@
+// 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;
+
+@VisibleForTesting
+public final class CronetMetrics extends RequestFinishedInfo.Metrics {
+ private final long mProxyStartMs;
+ private final long mProxyEndMs;
+ 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;
+
+ @Nullable
+ private final Long mTtfbMs;
+ @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
xunjieli 2016/09/01 22:17:42 Is this going away? Should we add a TODO here so i
mgersh 2016/09/02 19:32:08 Done.
+ */
+ 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
+ mProxyStartMs = 0;
+ mProxyEndMs = 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 proxyStartMs, long proxyEndMs, 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) {
xunjieli 2016/09/01 22:17:42 Might worth doing some assertions in the construct
mgersh 2016/09/02 19:32:08 Yeah, I was worried about that too. Done.
+ mProxyStartMs = proxyStartMs;
+ mProxyEndMs = proxyEndMs;
+ 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
xunjieli 2016/09/01 22:17:42 Why do we not care about these anymore? Could you
mgersh 2016/09/02 19:32:08 Done.
+ mTtfbMs = null;
+ mTotalTimeMs = null;
+ }
+
+ @Nullable
+ public Date getProxyStart() {
+ return toDate(mProxyStartMs);
+ }
+
+ @Nullable
+ public Date getProxyEnd() {
+ return toDate(mProxyEndMs);
+ }
+
+ @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