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

Side by Side Diff: Source/devtools/front_end/HAREntry.js

Issue 23308009: [DevTools] Save as HAR: classify time before network activity as "blocked". (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/devtools/front_end/NetworkRequest.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 entry = {
53 startedDateTime: new Date(this._request.startTime * 1000), 53 startedDateTime: new Date(this._request.startTime * 1000),
54 time: WebInspector.HAREntry._toMilliseconds(this._request.duration), 54 time: this._request.timing ? WebInspector.HAREntry._toMilliseconds(t his._request.duration) : 0,
55 request: this._buildRequest(), 55 request: this._buildRequest(),
56 response: this._buildResponse(), 56 response: this._buildResponse(),
57 cache: { }, // Not supported yet. 57 cache: { }, // Not supported yet.
58 timings: this._buildTimings() 58 timings: this._buildTimings()
59 }; 59 };
60
60 if (this._request.connectionId) 61 if (this._request.connectionId)
61 entry.connection = String(this._request.connectionId); 62 entry.connection = String(this._request.connectionId);
62 var page = WebInspector.networkLog.pageLoadForRequest(this._request); 63 var page = WebInspector.networkLog.pageLoadForRequest(this._request);
63 if (page) 64 if (page)
64 entry.pageref = "page_" + page.id; 65 entry.pageref = "page_" + page.id;
65 return entry; 66 return entry;
66 }, 67 },
67 68
68 /** 69 /**
69 * @return {Object} 70 * @return {Object}
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (typeof compression === "number") 119 if (typeof compression === "number")
119 content.compression = compression; 120 content.compression = compression;
120 return content; 121 return content;
121 }, 122 },
122 123
123 /** 124 /**
124 * @return {Object} 125 * @return {Object}
125 */ 126 */
126 _buildTimings: function() 127 _buildTimings: function()
127 { 128 {
128 var waitForConnection = this._interval("connectStart", "connectEnd"); 129 // Order of events: request_start = 0, [proxy], [dns], [connect [ssl]], [send], receive_headers_end
129 var blocked = 0; 130 // HAR 'blocked' time is time before first network activity.
131
132 var timing = this._request.timing;
133 if (!timing)
134 return {blocked: -1, dns: -1, connect: -1, send: 0, wait: 0, receive : 0, ssl: -1};
135
136 function nextEventTime(events) {
caseq 2013/09/13 15:24:07 style: { => next line
eustas 2013/09/16 10:06:22 Done.
137 for (var i = 0; i < events.length; ++i) {
138 if (timing[events[i]] > -1)
caseq 2013/09/13 15:24:07 nit: -1 is a "null" value, so I think it would be
eustas 2013/09/16 10:06:22 Done.
139 return Math.round(timing[events[i]]);
140 }
141 return -1;
142 }
143
144 var blocked = nextEventTime(["dnsStart", "connectStart", "sendStart"]);
145
146 var dns = -1;
147 if (timing["dnsStart"] > -1)
caseq 2013/09/13 15:24:07 Here ad below, why not timing.dnsStart? We should
eustas 2013/09/16 10:06:22 Done.
148 dns = nextEventTime(["connectStart", "sendStart"]) - Math.round(timi ng["dnsStart"]);
149
130 var connect = -1; 150 var connect = -1;
151 if (timing["connectStart"] > -1)
152 connect = Math.round(timing["sendStart"]) - Math.round(timing["conne ctStart"]);
caseq 2013/09/13 15:24:07 On a closer look to the spec, do we really have to
eustas 2013/09/16 10:06:22 Done.
131 153
132 if (this._request.connectionReused) 154 var send = Math.round(timing["sendEnd"]) - Math.round(timing["sendStart" ]);
caseq 2013/09/13 15:24:07 Are we intentionally counting send time from sendS
eustas 2013/09/16 10:06:22 Yes. Last event (block, dns or connect) lasts til
133 blocked = waitForConnection; 155 var wait = Math.round(timing["receiveHeadersEnd"]) - Math.round(timing[" sendEnd"]);
134 else 156 var receive = WebInspector.HAREntry._toMilliseconds(this._request.durati on) - Math.round(timing["receiveHeadersEnd"]);
135 connect = waitForConnection;
136 157
137 return { 158 var ssl = -1;
138 blocked: blocked, 159 if (timing["sslStart"] > -1 && timing["sslEnd"] > -1)
139 dns: this._interval("dnsStart", "dnsEnd"), 160 ssl = Math.round(timing["sslEnd"]) - Math.round(timing["sslStart"]);
140 connect: connect, 161
141 send: this._interval("sendStart", "sendEnd"), 162 return {blocked: blocked, dns: dns, connect: connect, send: send, wait: wait, receive: receive, ssl: ssl};
142 wait: this._interval("sendEnd", "receiveHeadersEnd"),
143 receive: WebInspector.HAREntry._toMilliseconds(this._request.receive Duration),
144 ssl: this._interval("sslStart", "sslEnd")
145 };
146 }, 163 },
147 164
148 /** 165 /**
149 * @return {Object} 166 * @return {Object}
150 */ 167 */
151 _buildPostData: function() 168 _buildPostData: function()
152 { 169 {
153 var res = { 170 var res = {
154 mimeType: this._request.requestHeaderValue("Content-Type"), 171 mimeType: this._request.requestHeaderValue("Content-Type"),
155 text: this._request.requestFormData 172 text: this._request.requestFormData
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 value: cookie.value(), 214 value: cookie.value(),
198 path: cookie.path(), 215 path: cookie.path(),
199 domain: cookie.domain(), 216 domain: cookie.domain(),
200 expires: cookie.expiresDate(new Date(this._request.startTime * 1000) ), 217 expires: cookie.expiresDate(new Date(this._request.startTime * 1000) ),
201 httpOnly: cookie.httpOnly(), 218 httpOnly: cookie.httpOnly(),
202 secure: cookie.secure() 219 secure: cookie.secure()
203 }; 220 };
204 }, 221 },
205 222
206 /** 223 /**
207 * @param {string} start
208 * @param {string} end
209 * @return {number}
210 */
211 _interval: function(start, end)
212 {
213 var timing = this._request.timing;
214 if (!timing)
215 return -1;
216 var startTime = timing[start];
217 return typeof startTime !== "number" || startTime === -1 ? -1 : Math.rou nd(timing[end] - startTime);
218 },
219
220 /**
221 * @return {number} 224 * @return {number}
222 */ 225 */
223 get requestBodySize() 226 get requestBodySize()
224 { 227 {
225 return !this._request.requestFormData ? 0 : this._request.requestFormDat a.length; 228 return !this._request.requestFormData ? 0 : this._request.requestFormDat a.length;
226 }, 229 },
227 230
228 /** 231 /**
229 * @return {number} 232 * @return {number}
230 */ 233 */
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 this._writeProgress.done(); 424 this._writeProgress.done();
422 return; 425 return;
423 } 426 }
424 const chunkSize = 100000; 427 const chunkSize = 100000;
425 var text = this._text.substring(this._bytesWritten, this._bytesWritten + chunkSize); 428 var text = this._text.substring(this._bytesWritten, this._bytesWritten + chunkSize);
426 this._bytesWritten += text.length; 429 this._bytesWritten += text.length;
427 stream.write(text, this._writeNextChunk.bind(this)); 430 stream.write(text, this._writeNextChunk.bind(this));
428 this._writeProgress.setWorked(this._bytesWritten); 431 this._writeProgress.setWorked(this._bytesWritten);
429 } 432 }
430 } 433 }
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/NetworkRequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698