OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 /** | 86 /** |
87 * @param {!WebInspector.NetworkRequest} request | 87 * @param {!WebInspector.NetworkRequest} request |
88 * @return {!Element} | 88 * @return {!Element} |
89 */ | 89 */ |
90 WebInspector.RequestTimingView.createTimingTable = function(request) | 90 WebInspector.RequestTimingView.createTimingTable = function(request) |
91 { | 91 { |
92 var tableElement = document.createElementWithClass("table", "network-timing-
table"); | 92 var tableElement = document.createElementWithClass("table", "network-timing-
table"); |
| 93 tableElement.createChild("colgroup").createChild("col", "labels"); |
93 | 94 |
94 /** | 95 /** |
95 * @param {string} title | 96 * @param {string} title |
96 * @param {string} className | 97 * @param {string} className |
97 * @param {number} start | 98 * @param {number} start |
98 * @param {number} end | 99 * @param {number} end |
99 */ | 100 */ |
100 function addRow(title, className, start, end) | 101 function addRow(title, className, start, end) |
101 { | 102 { |
| 103 if ((start === -1) || (start >= end)) |
| 104 return; |
102 var tr = tableElement.createChild("tr"); | 105 var tr = tableElement.createChild("tr"); |
103 tr.createChild("td").createTextChild(title); | 106 tr.createChild("td").createTextChild(title); |
104 var td = tr.createChild("td"); | 107 var row = tr.createChild("td").createChild("div", "network-timing-row"); |
105 td.width = chartWidth + "px"; | |
106 var row = td.createChild("div", "network-timing-row"); | |
107 | 108 |
108 var bar = row.createChild("span", "network-timing-bar " + className); | 109 var bar = row.createChild("span", "network-timing-bar " + className); |
109 bar.style.left = Math.floor(scale * start) + "px"; | 110 bar.style.left = (scale * start) + "%"; |
110 bar.style.right = Math.floor(scale * (total - end)) + "px"; | 111 bar.style.right = (scale * (total - end)) + "%"; |
111 bar.textContent = "\u200B"; // Important for 0-time items to have 0 widt
h. | 112 bar.textContent = "\u200B"; // Important for 0-time items to have 0 widt
h. |
112 | 113 |
113 var label = row.createChild("span", "network-timing-bar-title"); | 114 var label = row.createChild("span", "network-timing-bar-title"); |
114 if (total - end < start) | 115 if (total - end < start) |
115 label.style.right = (scale * (total - end)) + "px"; | 116 label.style.right = (scale * (total - end)) + "%"; |
116 else | 117 else |
117 label.style.left = (scale * start) + "px"; | 118 label.style.left = (scale * start) + "%"; |
118 label.textContent = Number.secondsToString((end - start) / 1000, true); | 119 label.textContent = Number.secondsToString((end - start) / 1000, true); |
119 } | 120 } |
120 | 121 |
121 /** | 122 /** |
122 * @param {!Array.<number>} numbers | 123 * @param {!Array.<number>} numbers |
123 * @return {number|undefined} | 124 * @return {number|undefined} |
124 */ | 125 */ |
125 function firstPositive(numbers) | 126 function firstPositive(numbers) |
126 { | 127 { |
127 for (var i = 0; i < numbers.length; ++i) { | 128 for (var i = 0; i < numbers.length; ++i) { |
128 if (numbers[i] > 0) | 129 if (numbers[i] > 0) |
129 return numbers[i]; | 130 return numbers[i]; |
130 } | 131 } |
131 return undefined; | 132 return undefined; |
132 } | 133 } |
133 | 134 |
134 function createCommunicationTimingTable() | 135 function createCommunicationTimingTable() |
135 { | 136 { |
136 if (blocking > 0) | 137 addRow(WebInspector.UIString("Stalled"), "blocking", 0, blocking || 0); |
137 addRow(WebInspector.UIString("Stalled"), "blocking", 0, blocking); | 138 addRow(WebInspector.UIString("Proxy negotiation"), "proxy", timing.proxy
Start, timing.proxyEnd); |
138 | 139 addRow(WebInspector.UIString("DNS Lookup"), "dns", timing.dnsStart, timi
ng.dnsEnd); |
139 if (timing.proxyStart !== -1) | 140 addRow(WebInspector.UIString("Initial connection"), "connecting", timing
.connectStart, timing.connectEnd); |
140 addRow(WebInspector.UIString("Proxy negotiation"), "proxy", timing.p
roxyStart, timing.proxyEnd); | 141 addRow(WebInspector.UIString("SSL"), "ssl", timing.sslStart, timing.sslE
nd); |
141 | |
142 if (timing.dnsStart !== -1) | |
143 addRow(WebInspector.UIString("DNS Lookup"), "dns", timing.dnsStart,
timing.dnsEnd); | |
144 | |
145 if (timing.connectStart !== -1) | |
146 addRow(WebInspector.UIString("Initial connection"), "connecting", ti
ming.connectStart, timing.connectEnd); | |
147 | |
148 if (timing.sslStart !== -1) | |
149 addRow(WebInspector.UIString("SSL"), "ssl", timing.sslStart, timing.
sslEnd); | |
150 | |
151 addRow(WebInspector.UIString("Request sent"), "sending", timing.sendStar
t, timing.sendEnd); | 142 addRow(WebInspector.UIString("Request sent"), "sending", timing.sendStar
t, timing.sendEnd); |
152 addRow(WebInspector.UIString("Waiting (TTFB)"), "waiting", timing.sendEn
d, timing.receiveHeadersEnd); | 143 addRow(WebInspector.UIString("Waiting (TTFB)"), "waiting", timing.sendEn
d, timing.receiveHeadersEnd); |
153 | |
154 if (request.endTime !== -1) | |
155 addRow(WebInspector.UIString("Content Download"), "receiving", (requ
est.responseReceivedTime - timing.requestTime) * 1000, total); | |
156 } | 144 } |
157 | 145 |
158 function createServiceWorkerTimingTable() | 146 function createServiceWorkerTimingTable() |
159 { | 147 { |
160 addRow(WebInspector.UIString("Stalled"), "blocking", 0, timing.serviceWo
rkerFetchStart); | 148 addRow(WebInspector.UIString("Stalled"), "blocking", 0, timing.serviceWo
rkerFetchStart); |
161 | |
162 addRow(WebInspector.UIString("Request to ServiceWorker"), "serviceworker
", timing.serviceWorkerFetchStart, timing.serviceWorkerFetchEnd); | 149 addRow(WebInspector.UIString("Request to ServiceWorker"), "serviceworker
", timing.serviceWorkerFetchStart, timing.serviceWorkerFetchEnd); |
163 addRow(WebInspector.UIString("ServiceWorker Preparation"), "serviceworke
r", timing.serviceWorkerFetchStart, timing.serviceWorkerFetchReady); | 150 addRow(WebInspector.UIString("ServiceWorker Preparation"), "serviceworke
r", timing.serviceWorkerFetchStart, timing.serviceWorkerFetchReady); |
164 addRow(WebInspector.UIString("Waiting (TTFB)"), "waiting", timing.servic
eWorkerFetchEnd, timing.receiveHeadersEnd); | 151 addRow(WebInspector.UIString("Waiting (TTFB)"), "waiting", timing.servic
eWorkerFetchEnd, timing.receiveHeadersEnd); |
165 | |
166 if (request.endTime !== -1) | |
167 addRow(WebInspector.UIString("Content Download"), "receiving", (requ
est.responseReceivedTime - timing.requestTime) * 1000, total); | |
168 } | 152 } |
169 | 153 |
170 var timing = request.timing; | 154 var timing = request.timing; |
171 var blocking = firstPositive([timing.dnsStart, timing.connectStart, timing.s
endStart]); | 155 var blocking = firstPositive([timing.dnsStart, timing.connectStart, timing.s
endStart]); |
172 var endTime = firstPositive([request.endTime, request.responseReceivedTime,
timing.requestTime]); | 156 var endTime = firstPositive([request.endTime, request.responseReceivedTime,
timing.requestTime]); |
173 var total = (endTime - timing.requestTime) * 1000; | 157 var total = (endTime - timing.requestTime) * 1000; |
174 const chartWidth = 200; | 158 var scale = 100 / total; |
175 var scale = chartWidth / total; | |
176 | 159 |
| 160 addRow(WebInspector.UIString("Total"), "total", 0, total); |
177 if (request.fetchedViaServiceWorker) | 161 if (request.fetchedViaServiceWorker) |
178 createServiceWorkerTimingTable(); | 162 createServiceWorkerTimingTable(); |
179 else | 163 else |
180 createCommunicationTimingTable(); | 164 createCommunicationTimingTable(); |
| 165 if (request.endTime !== -1) |
| 166 addRow(WebInspector.UIString("Content Download"), "receiving", (request.
responseReceivedTime - timing.requestTime) * 1000, total); |
181 | 167 |
182 if (!request.finished) { | 168 if (!request.finished) { |
183 var cell = tableElement.createChild("tr").createChild("td", "caution"); | 169 var cell = tableElement.createChild("tr").createChild("td", "caution"); |
184 cell.colSpan = 2; | 170 cell.colSpan = 2; |
185 cell.createTextChild(WebInspector.UIString("CAUTION: request is not fini
shed yet!")); | 171 cell.createTextChild(WebInspector.UIString("CAUTION: request is not fini
shed yet!")); |
186 } | 172 } |
187 | 173 |
188 return tableElement; | 174 return tableElement; |
189 } | 175 } |
OLD | NEW |