Skip to content

Commit 2082371

Browse files
authored
Implement thread execution time tracking
Added execution time tracking for threads in the debugger.
1 parent 0faba0a commit 2082371

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

static/extensions/TheShovel/shoveldebugger.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
oldStamp.call(this, target);
1717
};
1818

19+
const oldStepThread = vm.runtime.sequencer.stepThread;
20+
let _threadExecutionTimes = {};
21+
vm.runtime.sequencer.stepThread = function (e) {
22+
const startTime = performance.now();
23+
oldStepThread.call(this, e);
24+
const endTime = performance.now();
25+
const executionTime = endTime - startTime;
26+
const variableName = `thread_${e.topBlock}_executionTime`;
27+
_threadExecutionTimes[variableName] = executionTime;
28+
};
29+
1930
const oldSetTarget = vm.runtime.setEditingTarget;
2031
vm.runtime.setEditingTarget = function (editingTarget) {
2132
if (
@@ -124,6 +135,7 @@
124135

125136
this._maybeSample(t1, smoothedFps, stampsPerFrame);
126137
stampsPerFrame = 0;
138+
this._updateThreadViewer();
127139
};
128140

129141
if (!this.debuggerWindow) this._createWindow();
@@ -1428,6 +1440,11 @@
14281440
topBlock = B.getMainWorkspace().blockDB_[thread.topBlock];
14291441
}
14301442

1443+
const executionTimeKey = `thread_${thread.topBlock}_executionTime`;
1444+
const executionTime =
1445+
_threadExecutionTimes[executionTimeKey] || 0;
1446+
const showExecutionTime = executionTime > 0;
1447+
14311448
if (!this.performanceMode) {
14321449
const messageDiv = document.createElement("div");
14331450
Object.assign(messageDiv.style, {
@@ -1441,7 +1458,13 @@
14411458
marginLeft: "15px",
14421459
cursor: "pointer",
14431460
});
1444-
messageDiv.textContent = `Thread ${index + 1}`;
1461+
1462+
let labelText = `Thread ${index + 1}`;
1463+
if (showExecutionTime) {
1464+
labelText += ` (${executionTime.toFixed(2)}ms)`;
1465+
}
1466+
messageDiv.textContent = labelText;
1467+
14451468
if (!this.packaged) {
14461469
messageDiv.addEventListener("click", () => {
14471470
if (B && B.getMainWorkspace && thread.topBlock) {
@@ -1526,7 +1549,11 @@
15261549
container.appendChild(wrapper);
15271550

15281551
const label = document.createElement("div");
1529-
label.textContent = `Thread ${index + 1}`;
1552+
let labelText = `Thread ${index + 1}`;
1553+
if (showExecutionTime) {
1554+
labelText += ` (${executionTime.toFixed(2)}ms)`;
1555+
}
1556+
label.textContent = labelText;
15301557
Object.assign(label.style, {
15311558
position: "absolute",
15321559
top: "2px",
@@ -1698,7 +1725,12 @@
16981725
marginLeft: "15px",
16991726
cursor: "pointer",
17001727
});
1701-
messageDiv.textContent = `Thread ${index + 1}`;
1728+
1729+
let labelText = `Thread ${index + 1}`;
1730+
if (showExecutionTime) {
1731+
labelText += ` (${executionTime.toFixed(2)}ms)`;
1732+
}
1733+
messageDiv.textContent = labelText;
17021734

17031735
messageDiv.addEventListener("click", () => {
17041736
if (B && B.getMainWorkspace && thread.topBlock) {

0 commit comments

Comments
 (0)