|
1 |
| -const timingOffset = performance.timing.navigationStart, |
2 |
| - timingEnd = performance.timing.loadEventEnd, |
3 |
| - totalTime = timingEnd - timingOffset; |
4 |
| -function getLeft(stat) { |
5 |
| - return ((performance.timing[stat] - timingOffset) / totalTime) * 100.0; |
6 |
| -} |
7 |
| -function getCSSWidth(stat, endStat) { |
8 |
| - let width = |
9 |
| - ((performance.timing[endStat] - performance.timing[stat]) / totalTime) * |
10 |
| - 100.0; |
11 |
| - // Calculate relative percent (same as sql panel logic) |
12 |
| - width = (100.0 * width) / (100.0 - getLeft(stat)); |
13 |
| - return width < 1 ? "2px" : width + "%"; |
14 |
| -} |
15 |
| -function addRow(tbody, stat, endStat) { |
16 |
| - const row = document.createElement("tr"); |
17 |
| - if (endStat) { |
18 |
| - // Render a start through end bar |
19 |
| - row.innerHTML = |
20 |
| - "<td>" + |
21 |
| - stat.replace("Start", "") + |
22 |
| - "</td>" + |
23 |
| - '<td><svg class="djDebugLineChart" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 5" preserveAspectRatio="none"><rect y="0" height="5" fill="#ccc" /></svg></td>' + |
24 |
| - "<td>" + |
25 |
| - (performance.timing[stat] - timingOffset) + |
26 |
| - " (+" + |
27 |
| - (performance.timing[endStat] - performance.timing[stat]) + |
28 |
| - ")</td>"; |
29 |
| - row.querySelector("rect").setAttribute( |
30 |
| - "width", |
31 |
| - getCSSWidth(stat, endStat) |
32 |
| - ); |
33 |
| - } else { |
34 |
| - // Render a point in time |
35 |
| - row.innerHTML = |
36 |
| - "<td>" + |
37 |
| - stat + |
38 |
| - "</td>" + |
39 |
| - '<td><svg class="djDebugLineChart" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 5" preserveAspectRatio="none"><rect y="0" height="5" fill="#ccc" /></svg></td>' + |
40 |
| - "<td>" + |
41 |
| - (performance.timing[stat] - timingOffset) + |
42 |
| - "</td>"; |
43 |
| - row.querySelector("rect").setAttribute("width", 2); |
| 1 | +import { $$ } from "./utils.js"; |
| 2 | + |
| 3 | +function insertBrowserTiming() { |
| 4 | + console.log(["inserted"]); |
| 5 | + const timingOffset = performance.timing.navigationStart, |
| 6 | + timingEnd = performance.timing.loadEventEnd, |
| 7 | + totalTime = timingEnd - timingOffset; |
| 8 | + function getLeft(stat) { |
| 9 | + return ((performance.timing[stat] - timingOffset) / totalTime) * 100.0; |
| 10 | + } |
| 11 | + function getCSSWidth(stat, endStat) { |
| 12 | + let width = |
| 13 | + ((performance.timing[endStat] - performance.timing[stat]) / |
| 14 | + totalTime) * |
| 15 | + 100.0; |
| 16 | + // Calculate relative percent (same as sql panel logic) |
| 17 | + width = (100.0 * width) / (100.0 - getLeft(stat)); |
| 18 | + return width < 1 ? "2px" : width + "%"; |
| 19 | + } |
| 20 | + function addRow(tbody, stat, endStat) { |
| 21 | + const row = document.createElement("tr"); |
| 22 | + if (endStat) { |
| 23 | + // Render a start through end bar |
| 24 | + row.innerHTML = |
| 25 | + "<td>" + |
| 26 | + stat.replace("Start", "") + |
| 27 | + "</td>" + |
| 28 | + '<td><svg class="djDebugLineChart" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 5" preserveAspectRatio="none"><rect y="0" height="5" fill="#ccc" /></svg></td>' + |
| 29 | + "<td>" + |
| 30 | + (performance.timing[stat] - timingOffset) + |
| 31 | + " (+" + |
| 32 | + (performance.timing[endStat] - performance.timing[stat]) + |
| 33 | + ")</td>"; |
| 34 | + row.querySelector("rect").setAttribute( |
| 35 | + "width", |
| 36 | + getCSSWidth(stat, endStat) |
| 37 | + ); |
| 38 | + } else { |
| 39 | + // Render a point in time |
| 40 | + row.innerHTML = |
| 41 | + "<td>" + |
| 42 | + stat + |
| 43 | + "</td>" + |
| 44 | + '<td><svg class="djDebugLineChart" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 5" preserveAspectRatio="none"><rect y="0" height="5" fill="#ccc" /></svg></td>' + |
| 45 | + "<td>" + |
| 46 | + (performance.timing[stat] - timingOffset) + |
| 47 | + "</td>"; |
| 48 | + row.querySelector("rect").setAttribute("width", 2); |
| 49 | + } |
| 50 | + row.querySelector("rect").setAttribute("x", getLeft(stat)); |
| 51 | + tbody.appendChild(row); |
| 52 | + } |
| 53 | + |
| 54 | + const browserTiming = document.getElementById("djDebugBrowserTiming"); |
| 55 | + // Determine if the browser timing section has already been rendered. |
| 56 | + if (browserTiming.classList.contains("djdt-hidden")) { |
| 57 | + const tbody = document.getElementById("djDebugBrowserTimingTableBody"); |
| 58 | + // This is a reasonably complete and ordered set of timing periods (2 params) and events (1 param) |
| 59 | + addRow(tbody, "domainLookupStart", "domainLookupEnd"); |
| 60 | + addRow(tbody, "connectStart", "connectEnd"); |
| 61 | + addRow(tbody, "requestStart", "responseEnd"); // There is no requestEnd |
| 62 | + addRow(tbody, "responseStart", "responseEnd"); |
| 63 | + addRow(tbody, "domLoading", "domComplete"); // Spans the events below |
| 64 | + addRow(tbody, "domInteractive"); |
| 65 | + addRow(tbody, "domContentLoadedEventStart", "domContentLoadedEventEnd"); |
| 66 | + addRow(tbody, "loadEventStart", "loadEventEnd"); |
| 67 | + browserTiming.classList.remove("djdt-hidden"); |
44 | 68 | }
|
45 |
| - row.querySelector("rect").setAttribute("x", getLeft(stat)); |
46 |
| - tbody.appendChild(row); |
47 | 69 | }
|
48 | 70 |
|
49 |
| -const tbody = document.getElementById("djDebugBrowserTimingTableBody"); |
50 |
| -// This is a reasonably complete and ordered set of timing periods (2 params) and events (1 param) |
51 |
| -addRow(tbody, "domainLookupStart", "domainLookupEnd"); |
52 |
| -addRow(tbody, "connectStart", "connectEnd"); |
53 |
| -addRow(tbody, "requestStart", "responseEnd"); // There is no requestEnd |
54 |
| -addRow(tbody, "responseStart", "responseEnd"); |
55 |
| -addRow(tbody, "domLoading", "domComplete"); // Spans the events below |
56 |
| -addRow(tbody, "domInteractive"); |
57 |
| -addRow(tbody, "domContentLoadedEventStart", "domContentLoadedEventEnd"); |
58 |
| -addRow(tbody, "loadEventStart", "loadEventEnd"); |
59 |
| -document.getElementById("djDebugBrowserTiming").classList.remove("djdt-hidden"); |
| 71 | +const djDebug = document.getElementById("djDebug"); |
| 72 | +// Insert the browser timing now since it's possible for this |
| 73 | +// script to miss the initial panel load event. |
| 74 | +insertBrowserTiming(); |
| 75 | +$$.onPanelRender(djDebug, "TimerPanel", insertBrowserTiming); |
0 commit comments