Skip to content

Commit afd804f

Browse files
authored
Merge pull request #1672 from canalplus/feat/add-buffer-size-to-debug-v3
[v3] DEBUG_ELEMENT: Add buffer size estimate to debug buffer content graph
2 parents 50d2bd9 + 42dbabd commit afd804f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/core/api/debug/modules/segment_buffer_content.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default function createSegmentBufferGraph(
2222
const bufferGraphWrapper = createElement("div");
2323
const bufferTitle = createMetricTitle(title);
2424
const canvasElt = createGraphCanvas();
25+
const bufferSizeElt = document.createElement("span");
2526
const currentRangeRepInfoElt = createElement("div");
2627
const loadingRangeRepInfoElt = createElement("div");
2728
const bufferGraph = new SegmentBufferGraph(canvasElt);
@@ -31,8 +32,11 @@ export default function createSegmentBufferGraph(
3132
});
3233
bufferGraphWrapper.appendChild(bufferTitle);
3334
bufferGraphWrapper.appendChild(canvasElt);
35+
bufferGraphWrapper.appendChild(bufferSizeElt);
3436
bufferGraphWrapper.appendChild(currentRangeRepInfoElt);
3537
bufferGraphWrapper.appendChild(loadingRangeRepInfoElt);
38+
bufferSizeElt.style.marginLeft = "5px";
39+
bufferSizeElt.style.fontSize = "0.9em";
3640
bufferGraphWrapper.style.padding = "5px 0px";
3741
update();
3842
return bufferGraphWrapper;
@@ -49,10 +53,35 @@ export default function createSegmentBufferGraph(
4953
const inventory = instance.__priv_getSegmentBufferContent(bufferType);
5054
if (inventory === null) {
5155
bufferGraphWrapper.style.display = "none";
56+
bufferSizeElt.innerHTML = "";
5257
currentRangeRepInfoElt.innerHTML = "";
5358
loadingRangeRepInfoElt.innerHTML = "";
5459
} else {
60+
let sizeEstimate: number | undefined;
61+
for (const segment of inventory) {
62+
if (segment.chunkSize === undefined) {
63+
sizeEstimate = undefined;
64+
break;
65+
} else if (sizeEstimate === undefined) {
66+
sizeEstimate = segment.chunkSize;
67+
} else {
68+
sizeEstimate += segment.chunkSize;
69+
}
70+
}
5571
bufferGraphWrapper.style.display = "block";
72+
if (sizeEstimate !== undefined) {
73+
let sizeStr: string;
74+
if (sizeEstimate > 2e6) {
75+
sizeStr = (sizeEstimate / 1e6).toFixed(2) + "MB";
76+
} else if (sizeEstimate > 2e3) {
77+
sizeStr = (sizeEstimate / 1e3).toFixed(2) + "kB";
78+
} else {
79+
sizeStr = sizeEstimate + "B";
80+
}
81+
bufferSizeElt.innerHTML = sizeStr;
82+
} else {
83+
bufferSizeElt.innerHTML = "";
84+
}
5685
const currentTime = instance.getPosition();
5786
const width = Math.min(parentElt.clientWidth - 150, 600);
5887
bufferGraph.update({

0 commit comments

Comments
 (0)