Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 /** | |
| 15 * Implementation of {@link RequestFinishedInfo.Metrics}. | |
| 16 */ | |
| 17 @VisibleForTesting | |
| 18 public final class CronetMetrics extends RequestFinishedInfo.Metrics { | |
| 19 private final long mRequestStartMs; | |
| 20 private final long mDnsStartMs; | |
| 21 private final long mDnsEndMs; | |
| 22 private final long mConnectStartMs; | |
| 23 private final long mConnectEndMs; | |
| 24 private final long mSslStartMs; | |
| 25 private final long mSslEndMs; | |
| 26 private final long mSendingStartMs; | |
| 27 private final long mSendingEndMs; | |
| 28 private final long mPushStartMs; | |
| 29 private final long mPushEndMs; | |
| 30 private final long mResponseStartMs; | |
| 31 private final long mResponseEndMs; | |
| 32 private final boolean mSocketReused; | |
| 33 | |
| 34 // TODO(mgersh): Delete after the switch to the new API http://crbug.com/629 194 | |
| 35 @Nullable | |
| 36 private final Long mTtfbMs; | |
| 37 // TODO(mgersh): Delete after the switch to the new API http://crbug.com/629 194 | |
| 38 @Nullable | |
| 39 private final Long mTotalTimeMs; | |
| 40 @Nullable | |
| 41 private final Long mSentBytesCount; | |
| 42 @Nullable | |
| 43 private final Long mReceivedBytesCount; | |
| 44 | |
| 45 @Nullable | |
| 46 private static Date toDate(long timestamp) { | |
| 47 if (timestamp != -1) { | |
| 48 return new Date(timestamp); | |
| 49 } | |
| 50 return null; | |
| 51 } | |
| 52 | |
| 53 private static boolean checkOrder(long start, long end) { | |
| 54 // If end doesn't exist, start can be anything, including also not exist ing | |
| 55 // If end exists, start must also exist and be before end | |
| 56 return (end >= start && start != -1) || end == -1; | |
| 57 } | |
| 58 | |
| 59 /** | |
| 60 * Old-style constructor | |
| 61 * TODO(mgersh): Delete after the switch to the new API http://crbug.com/629 194 | |
| 62 */ | |
| 63 public CronetMetrics(@Nullable Long ttfbMs, @Nullable Long totalTimeMs, | |
| 64 @Nullable Long sentBytesCount, @Nullable Long receivedBytesCount) { | |
| 65 mTtfbMs = ttfbMs; | |
| 66 mTotalTimeMs = totalTimeMs; | |
| 67 mSentBytesCount = sentBytesCount; | |
| 68 mReceivedBytesCount = receivedBytesCount; | |
| 69 | |
| 70 // Everything else is -1 (translates to null) for now | |
| 71 mRequestStartMs = -1; | |
| 72 mDnsStartMs = -1; | |
| 73 mDnsEndMs = -1; | |
| 74 mConnectStartMs = -1; | |
| 75 mConnectEndMs = -1; | |
| 76 mSslStartMs = -1; | |
| 77 mSslEndMs = -1; | |
| 78 mSendingStartMs = -1; | |
| 79 mSendingEndMs = -1; | |
| 80 mPushStartMs = -1; | |
| 81 mPushEndMs = -1; | |
| 82 mResponseStartMs = -1; | |
| 83 mResponseEndMs = -1; | |
| 84 mSocketReused = false; | |
| 85 } | |
| 86 | |
| 87 /** | |
| 88 * New-style constructor | |
| 89 */ | |
| 90 public CronetMetrics(long requestStartMs, long dnsStartMs, long dnsEndMs, lo ng connectStartMs, | |
| 91 long connectEndMs, long sslStartMs, long sslEndMs, long sendingStart Ms, | |
| 92 long sendingEndMs, long pushStartMs, long pushEndMs, long responseSt artMs, | |
| 93 long responseEndMs, boolean socketReused, long sentBytesCount, | |
| 94 long receivedBytesCount) { | |
| 95 // Check that no end times are before corresponding start times, | |
| 96 // or exist when start time doesn't | |
|
xunjieli
2016/09/08 18:45:38
nit: might want to complete the sentence with a pe
mgersh
2016/09/12 20:55:13
Done.
| |
| 97 assert checkOrder(dnsStartMs, dnsEndMs); | |
| 98 assert checkOrder(connectStartMs, connectEndMs); | |
| 99 assert checkOrder(sslStartMs, sslEndMs); | |
| 100 assert checkOrder(sendingStartMs, sendingEndMs); | |
| 101 assert checkOrder(pushStartMs, pushEndMs); | |
| 102 assert checkOrder(responseStartMs, responseEndMs); | |
| 103 // Spot-check some of the other orderings | |
| 104 assert dnsStartMs >= requestStartMs || dnsStartMs == -1; | |
| 105 assert sendingStartMs >= requestStartMs || sendingStartMs == -1; | |
| 106 assert sslStartMs >= connectStartMs || sslStartMs == -1; | |
| 107 assert connectEndMs >= sslEndMs || connectEndMs == -1; | |
| 108 assert sendingStartMs >= connectEndMs || sendingStartMs == -1; | |
| 109 assert responseStartMs >= sendingStartMs || responseStartMs == -1; | |
| 110 mRequestStartMs = requestStartMs; | |
| 111 mDnsStartMs = dnsStartMs; | |
| 112 mDnsEndMs = dnsEndMs; | |
| 113 mConnectStartMs = connectStartMs; | |
| 114 mConnectEndMs = connectEndMs; | |
| 115 mSslStartMs = sslStartMs; | |
| 116 mSslEndMs = sslEndMs; | |
| 117 mSendingStartMs = sendingStartMs; | |
| 118 mSendingEndMs = sendingEndMs; | |
| 119 mPushStartMs = pushStartMs; | |
| 120 mPushEndMs = pushEndMs; | |
| 121 mResponseStartMs = responseStartMs; | |
| 122 mResponseEndMs = responseEndMs; | |
| 123 mSocketReused = socketReused; | |
| 124 mSentBytesCount = sentBytesCount; | |
| 125 mReceivedBytesCount = receivedBytesCount; | |
| 126 | |
| 127 // Don't care about these anymore | |
| 128 mTtfbMs = null; | |
| 129 mTotalTimeMs = null; | |
| 130 } | |
| 131 | |
| 132 @Nullable | |
| 133 public Date getRequestStart() { | |
| 134 return toDate(mRequestStartMs); | |
| 135 } | |
| 136 | |
| 137 @Nullable | |
| 138 public Date getDnsStart() { | |
| 139 return toDate(mDnsStartMs); | |
| 140 } | |
| 141 | |
| 142 @Nullable | |
| 143 public Date getDnsEnd() { | |
| 144 return toDate(mDnsEndMs); | |
| 145 } | |
| 146 | |
| 147 @Nullable | |
| 148 public Date getConnectStart() { | |
| 149 return toDate(mConnectStartMs); | |
| 150 } | |
| 151 | |
| 152 @Nullable | |
| 153 public Date getConnectEnd() { | |
| 154 return toDate(mConnectEndMs); | |
| 155 } | |
| 156 | |
| 157 @Nullable | |
| 158 public Date getSslStart() { | |
| 159 return toDate(mSslStartMs); | |
| 160 } | |
| 161 | |
| 162 @Nullable | |
| 163 public Date getSslEnd() { | |
| 164 return toDate(mSslEndMs); | |
| 165 } | |
| 166 | |
| 167 @Nullable | |
| 168 public Date getSendingStart() { | |
| 169 return toDate(mSendingStartMs); | |
| 170 } | |
| 171 | |
| 172 @Nullable | |
| 173 public Date getSendingEnd() { | |
| 174 return toDate(mSendingEndMs); | |
| 175 } | |
| 176 | |
| 177 @Nullable | |
| 178 public Date getPushStart() { | |
| 179 return toDate(mPushStartMs); | |
| 180 } | |
| 181 | |
| 182 @Nullable | |
| 183 public Date getPushEnd() { | |
| 184 return toDate(mPushEndMs); | |
| 185 } | |
| 186 | |
| 187 @Nullable | |
| 188 public Date getResponseStart() { | |
| 189 return toDate(mResponseStartMs); | |
| 190 } | |
| 191 | |
| 192 @Nullable | |
| 193 public Date getResponseEnd() { | |
| 194 return toDate(mResponseEndMs); | |
| 195 } | |
| 196 | |
| 197 @Nullable | |
| 198 public boolean getSocketReused() { | |
| 199 return mSocketReused; | |
| 200 } | |
| 201 | |
| 202 @Nullable | |
| 203 public Long getTtfbMs() { | |
| 204 return mTtfbMs; | |
| 205 } | |
| 206 | |
| 207 @Nullable | |
| 208 public Long getTotalTimeMs() { | |
| 209 return mTotalTimeMs; | |
| 210 } | |
| 211 | |
| 212 @Nullable | |
| 213 public Long getSentBytesCount() { | |
| 214 return mSentBytesCount; | |
| 215 } | |
| 216 | |
| 217 @Nullable | |
| 218 public Long getReceivedBytesCount() { | |
| 219 return mReceivedBytesCount; | |
| 220 } | |
| 221 } | |
| OLD | NEW |