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

Side by Side 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, 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.net.impl;
6
7 import android.support.annotation.Nullable;
8
9 import org.chromium.base.VisibleForTesting;
10 import org.chromium.net.RequestFinishedInfo;
11
12 import java.util.Date;
13
14 @VisibleForTesting
15 public final class CronetMetrics extends RequestFinishedInfo.Metrics {
16 private final long mProxyStartMs;
17 private final long mProxyEndMs;
18 private final long mDnsStartMs;
19 private final long mDnsEndMs;
20 private final long mConnectStartMs;
21 private final long mConnectEndMs;
22 private final long mSslStartMs;
23 private final long mSslEndMs;
24 private final long mSendingStartMs;
25 private final long mSendingEndMs;
26 private final long mPushStartMs;
27 private final long mPushEndMs;
28 private final long mResponseStartMs;
29 private final long mResponseEndMs;
30 private final boolean mSocketReused;
31
32 @Nullable
33 private final Long mTtfbMs;
34 @Nullable
35 private final Long mTotalTimeMs;
36 @Nullable
37 private final Long mSentBytesCount;
38 @Nullable
39 private final Long mReceivedBytesCount;
40
41 @Nullable
42 private static Date toDate(long timestamp) {
43 if (timestamp != 0) {
44 return new Date(timestamp);
45 }
46 return null;
47 }
48
49 /**
50 * 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.
51 */
52 public CronetMetrics(@Nullable Long ttfbMs, @Nullable Long totalTimeMs,
53 @Nullable Long sentBytesCount, @Nullable Long receivedBytesCount) {
54 mTtfbMs = ttfbMs;
55 mTotalTimeMs = totalTimeMs;
56 mSentBytesCount = sentBytesCount;
57 mReceivedBytesCount = receivedBytesCount;
58
59 // Everything else is 0 for now
60 mProxyStartMs = 0;
61 mProxyEndMs = 0;
62 mDnsStartMs = 0;
63 mDnsEndMs = 0;
64 mConnectStartMs = 0;
65 mConnectEndMs = 0;
66 mSslStartMs = 0;
67 mSslEndMs = 0;
68 mSendingStartMs = 0;
69 mSendingEndMs = 0;
70 mPushStartMs = 0;
71 mPushEndMs = 0;
72 mResponseStartMs = 0;
73 mResponseEndMs = 0;
74 mSocketReused = false;
75 }
76
77 /**
78 * New-style constructor
79 */
80 public CronetMetrics(long proxyStartMs, long proxyEndMs, long dnsStartMs, lo ng dnsEndMs,
81 long connectStartMs, long connectEndMs, long sslStartMs, long sslEnd Ms,
82 long sendingStartMs, long sendingEndMs, long pushStartMs, long pushE ndMs,
83 long responseStartMs, long responseEndMs, boolean socketReused, long sentBytesCount,
84 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.
85 mProxyStartMs = proxyStartMs;
86 mProxyEndMs = proxyEndMs;
87 mDnsStartMs = dnsStartMs;
88 mDnsEndMs = dnsEndMs;
89 mConnectStartMs = connectStartMs;
90 mConnectEndMs = connectEndMs;
91 mSslStartMs = sslStartMs;
92 mSslEndMs = sslEndMs;
93 mSendingStartMs = sendingStartMs;
94 mSendingEndMs = sendingEndMs;
95 mPushStartMs = pushStartMs;
96 mPushEndMs = pushEndMs;
97 mResponseStartMs = responseStartMs;
98 mResponseEndMs = responseEndMs;
99 mSocketReused = socketReused;
100 mSentBytesCount = sentBytesCount;
101 mReceivedBytesCount = receivedBytesCount;
102
103 // 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.
104 mTtfbMs = null;
105 mTotalTimeMs = null;
106 }
107
108 @Nullable
109 public Date getProxyStart() {
110 return toDate(mProxyStartMs);
111 }
112
113 @Nullable
114 public Date getProxyEnd() {
115 return toDate(mProxyEndMs);
116 }
117
118 @Nullable
119 public Date getDnsStart() {
120 return toDate(mDnsStartMs);
121 }
122
123 @Nullable
124 public Date getDnsEnd() {
125 return toDate(mDnsEndMs);
126 }
127
128 @Nullable
129 public Date getConnectStart() {
130 return toDate(mConnectStartMs);
131 }
132
133 @Nullable
134 public Date getConnectEnd() {
135 return toDate(mConnectEndMs);
136 }
137
138 @Nullable
139 public Date getSslStart() {
140 return toDate(mSslStartMs);
141 }
142
143 @Nullable
144 public Date getSslEnd() {
145 return toDate(mSslEndMs);
146 }
147
148 @Nullable
149 public Date getSendingStart() {
150 return toDate(mSendingStartMs);
151 }
152
153 @Nullable
154 public Date getSendingEnd() {
155 return toDate(mSendingEndMs);
156 }
157
158 @Nullable
159 public Date getPushStart() {
160 return toDate(mPushStartMs);
161 }
162
163 @Nullable
164 public Date getPushEnd() {
165 return toDate(mPushEndMs);
166 }
167
168 @Nullable
169 public Date getResponseStart() {
170 return toDate(mResponseStartMs);
171 }
172
173 @Nullable
174 public Date getResponseEnd() {
175 return toDate(mResponseEndMs);
176 }
177
178 @Nullable
179 public boolean getSocketReused() {
180 return mSocketReused;
181 }
182
183 @Nullable
184 public Long getTtfbMs() {
185 return mTtfbMs;
186 }
187
188 @Nullable
189 public Long getTotalTimeMs() {
190 return mTotalTimeMs;
191 }
192
193 @Nullable
194 public Long getSentBytesCount() {
195 return mSentBytesCount;
196 }
197
198 @Nullable
199 public Long getReceivedBytesCount() {
200 return mReceivedBytesCount;
201 }
202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698