Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 { | 42 { |
| 43 this._request = request; | 43 this._request = request; |
| 44 } | 44 } |
| 45 | 45 |
| 46 WebInspector.HAREntry.prototype = { | 46 WebInspector.HAREntry.prototype = { |
| 47 /** | 47 /** |
| 48 * @return {Object} | 48 * @return {Object} |
| 49 */ | 49 */ |
| 50 build: function() | 50 build: function() |
| 51 { | 51 { |
| 52 var entry = { | 52 var timings = this._buildTimings(); |
| 53 var time = Math.max(timings.blocked, 0) + Math.max(timings.dns, 0) + Mat h.max(timings.connect, 0) + Math.max(timings.send, 0) + Math.max(timings.wait, 0 ) + Math.max(timings.receive, 0); | |
|
caseq
2013/08/30 15:12:53
So if we lost some time due to imperfect instrumen
eustas
2013/09/13 15:10:36
Done.
| |
| 54 | |
| 55 var entry = { | |
| 53 startedDateTime: new Date(this._request.startTime * 1000), | 56 startedDateTime: new Date(this._request.startTime * 1000), |
| 54 time: WebInspector.HAREntry._toMilliseconds(this._request.duration), | 57 time: time, |
| 55 request: this._buildRequest(), | 58 request: this._buildRequest(), |
| 56 response: this._buildResponse(), | 59 response: this._buildResponse(), |
| 57 cache: { }, // Not supported yet. | 60 cache: { }, // Not supported yet. |
| 58 timings: this._buildTimings() | 61 timings: timings |
| 59 }; | 62 }; |
| 63 | |
| 60 if (this._request.connectionId) | 64 if (this._request.connectionId) |
| 61 entry.connection = String(this._request.connectionId); | 65 entry.connection = String(this._request.connectionId); |
| 62 var page = WebInspector.networkLog.pageLoadForRequest(this._request); | 66 var page = WebInspector.networkLog.pageLoadForRequest(this._request); |
| 63 if (page) | 67 if (page) |
| 64 entry.pageref = "page_" + page.id; | 68 entry.pageref = "page_" + page.id; |
| 65 return entry; | 69 return entry; |
| 66 }, | 70 }, |
| 67 | 71 |
| 68 /** | 72 /** |
| 69 * @return {Object} | 73 * @return {Object} |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 if (typeof compression === "number") | 122 if (typeof compression === "number") |
| 119 content.compression = compression; | 123 content.compression = compression; |
| 120 return content; | 124 return content; |
| 121 }, | 125 }, |
| 122 | 126 |
| 123 /** | 127 /** |
| 124 * @return {Object} | 128 * @return {Object} |
| 125 */ | 129 */ |
| 126 _buildTimings: function() | 130 _buildTimings: function() |
| 127 { | 131 { |
| 128 var waitForConnection = this._interval("connectStart", "connectEnd"); | 132 // Order of events: request_start = 0, [proxy], [dns], [connect [ssl]], [send], receive_headers_end |
| 129 var blocked = 0; | 133 // HAR 'blocked' time is time before first network activity. |
| 130 var connect = -1; | 134 // The rest time gaps will be classified as '_other'. |
| 131 | 135 |
| 132 if (this._request.connectionReused) | 136 var dns = this._interval("dnsStart", "dnsEnd"); |
| 133 blocked = waitForConnection; | 137 var send = this._interval("sendStart", "sendEnd"); |
| 134 else | 138 var wait = this._interval("sendEnd", "receiveHeadersEnd"); |
| 135 connect = waitForConnection; | 139 var receive = WebInspector.HAREntry._toMilliseconds(this._request.receiv eDuration); |
| 140 var connect = this._request.connectionReused ? -1 : this._interval("conn ectStart", "connectEnd"); | |
| 141 | |
| 142 var blocked = -1; | |
| 143 var timing = this._request.timing; | |
| 144 if (timing) { | |
| 145 var events = ["dnsStart", "connectStart", "sendStart"]; | |
| 146 var times = []; | |
| 147 for (var i = 0; i < events.length; ++i) { | |
| 148 var time = timing[events[i]]; | |
| 149 if (typeof time === "number" && time !== -1) | |
|
caseq
2013/08/30 15:12:53
Note that if (time >= 0) times.push(time) would wo
eustas
2013/09/13 15:10:36
Done.
| |
| 150 times.push(time); | |
| 151 } | |
| 152 if (times.length) | |
| 153 blocked = Math.min.apply(null, times); | |
|
caseq
2013/08/30 15:12:53
So what happened to the old logic of "if connectio
eustas
2013/09/13 15:10:36
It is baked into glue.
| |
| 154 } | |
| 155 | |
| 156 var total = WebInspector.HAREntry._toMilliseconds(this._request.duration ); | |
| 157 var other = total - Math.max(blocked, 0) - Math.max(dns, 0) - Math.max(c onnect, 0) - Math.max(send, 0) - Math.max(wait, 0) - Math.max(receive, 0); | |
| 136 | 158 |
| 137 return { | 159 return { |
| 138 blocked: blocked, | 160 blocked: Math.round(blocked), |
| 139 dns: this._interval("dnsStart", "dnsEnd"), | 161 dns: Math.round(dns), |
| 140 connect: connect, | 162 connect: Math.round(connect), |
| 141 send: this._interval("sendStart", "sendEnd"), | 163 send: Math.round(send), |
| 142 wait: this._interval("sendEnd", "receiveHeadersEnd"), | 164 wait: Math.round(wait), |
| 143 receive: WebInspector.HAREntry._toMilliseconds(this._request.receive Duration), | 165 receive: Math.round(receive), |
| 144 ssl: this._interval("sslStart", "sslEnd") | 166 ssl: Math.round(this._interval("sslStart", "sslEnd")), |
| 167 _other: Math.round(other) | |
| 145 }; | 168 }; |
| 146 }, | 169 }, |
| 147 | 170 |
| 148 /** | 171 /** |
| 149 * @return {Object} | 172 * @return {Object} |
| 150 */ | 173 */ |
| 151 _buildPostData: function() | 174 _buildPostData: function() |
| 152 { | 175 { |
| 153 var res = { | 176 var res = { |
| 154 mimeType: this._request.requestHeaderValue("Content-Type"), | 177 mimeType: this._request.requestHeaderValue("Content-Type"), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 * @param {string} start | 230 * @param {string} start |
| 208 * @param {string} end | 231 * @param {string} end |
| 209 * @return {number} | 232 * @return {number} |
| 210 */ | 233 */ |
| 211 _interval: function(start, end) | 234 _interval: function(start, end) |
| 212 { | 235 { |
| 213 var timing = this._request.timing; | 236 var timing = this._request.timing; |
| 214 if (!timing) | 237 if (!timing) |
| 215 return -1; | 238 return -1; |
| 216 var startTime = timing[start]; | 239 var startTime = timing[start]; |
| 217 return typeof startTime !== "number" || startTime === -1 ? -1 : Math.rou nd(timing[end] - startTime); | 240 return typeof startTime !== "number" || startTime === -1 ? -1 : (timing[ end] - startTime); |
|
caseq
2013/08/30 15:12:53
Please remove redundant parenthesis.
eustas
2013/09/13 15:10:36
Done.
| |
| 218 }, | 241 }, |
| 219 | 242 |
| 220 /** | 243 /** |
| 221 * @return {number} | 244 * @return {number} |
| 222 */ | 245 */ |
| 223 get requestBodySize() | 246 get requestBodySize() |
| 224 { | 247 { |
| 225 return !this._request.requestFormData ? 0 : this._request.requestFormDat a.length; | 248 return !this._request.requestFormData ? 0 : this._request.requestFormDat a.length; |
| 226 }, | 249 }, |
| 227 | 250 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 245 return this._request.resourceSize - this.responseBodySize; | 268 return this._request.resourceSize - this.responseBodySize; |
| 246 } | 269 } |
| 247 } | 270 } |
| 248 | 271 |
| 249 /** | 272 /** |
| 250 * @param {number} time | 273 * @param {number} time |
| 251 * @return {number} | 274 * @return {number} |
| 252 */ | 275 */ |
| 253 WebInspector.HAREntry._toMilliseconds = function(time) | 276 WebInspector.HAREntry._toMilliseconds = function(time) |
| 254 { | 277 { |
| 255 return time === -1 ? -1 : Math.round(time * 1000); | 278 return time === -1 ? -1 : (time * 1000); |
|
caseq
2013/08/30 15:12:53
Ditto.
eustas
2013/09/13 15:10:36
Done.
| |
| 256 } | 279 } |
| 257 | 280 |
| 258 /** | 281 /** |
| 259 * @constructor | 282 * @constructor |
| 260 * @param {Array.<WebInspector.NetworkRequest>} requests | 283 * @param {Array.<WebInspector.NetworkRequest>} requests |
| 261 */ | 284 */ |
| 262 WebInspector.HARLog = function(requests) | 285 WebInspector.HARLog = function(requests) |
| 263 { | 286 { |
| 264 this._requests = requests; | 287 this._requests = requests; |
| 265 } | 288 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 /** | 357 /** |
| 335 * @param {WebInspector.PageLoad} page | 358 * @param {WebInspector.PageLoad} page |
| 336 * @param {number} time | 359 * @param {number} time |
| 337 * @return {number} | 360 * @return {number} |
| 338 */ | 361 */ |
| 339 _pageEventTime: function(page, time) | 362 _pageEventTime: function(page, time) |
| 340 { | 363 { |
| 341 var startTime = page.startTime; | 364 var startTime = page.startTime; |
| 342 if (time === -1 || startTime === -1) | 365 if (time === -1 || startTime === -1) |
| 343 return -1; | 366 return -1; |
| 344 return WebInspector.HAREntry._toMilliseconds(time - startTime); | 367 return Math.round(WebInspector.HAREntry._toMilliseconds(time - startTime )); |
| 345 } | 368 } |
| 346 } | 369 } |
| 347 | 370 |
| 348 /** | 371 /** |
| 349 * @constructor | 372 * @constructor |
| 350 */ | 373 */ |
| 351 WebInspector.HARWriter = function() | 374 WebInspector.HARWriter = function() |
| 352 { | 375 { |
| 353 } | 376 } |
| 354 | 377 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 this._writeProgress.done(); | 444 this._writeProgress.done(); |
| 422 return; | 445 return; |
| 423 } | 446 } |
| 424 const chunkSize = 100000; | 447 const chunkSize = 100000; |
| 425 var text = this._text.substring(this._bytesWritten, this._bytesWritten + chunkSize); | 448 var text = this._text.substring(this._bytesWritten, this._bytesWritten + chunkSize); |
| 426 this._bytesWritten += text.length; | 449 this._bytesWritten += text.length; |
| 427 stream.write(text, this._writeNextChunk.bind(this)); | 450 stream.write(text, this._writeNextChunk.bind(this)); |
| 428 this._writeProgress.setWorked(this._bytesWritten); | 451 this._writeProgress.setWorked(this._bytesWritten); |
| 429 } | 452 } |
| 430 } | 453 } |
| OLD | NEW |