|
16 | 16 | oldStamp.call(this, target); |
17 | 17 | }; |
18 | 18 |
|
| 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 | + |
19 | 30 | const oldSetTarget = vm.runtime.setEditingTarget; |
20 | 31 | vm.runtime.setEditingTarget = function (editingTarget) { |
21 | 32 | if ( |
|
124 | 135 |
|
125 | 136 | this._maybeSample(t1, smoothedFps, stampsPerFrame); |
126 | 137 | stampsPerFrame = 0; |
| 138 | + this._updateThreadViewer(); |
127 | 139 | }; |
128 | 140 |
|
129 | 141 | if (!this.debuggerWindow) this._createWindow(); |
|
1428 | 1440 | topBlock = B.getMainWorkspace().blockDB_[thread.topBlock]; |
1429 | 1441 | } |
1430 | 1442 |
|
| 1443 | + const executionTimeKey = `thread_${thread.topBlock}_executionTime`; |
| 1444 | + const executionTime = |
| 1445 | + _threadExecutionTimes[executionTimeKey] || 0; |
| 1446 | + const showExecutionTime = executionTime > 0; |
| 1447 | + |
1431 | 1448 | if (!this.performanceMode) { |
1432 | 1449 | const messageDiv = document.createElement("div"); |
1433 | 1450 | Object.assign(messageDiv.style, { |
|
1441 | 1458 | marginLeft: "15px", |
1442 | 1459 | cursor: "pointer", |
1443 | 1460 | }); |
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 | + |
1445 | 1468 | if (!this.packaged) { |
1446 | 1469 | messageDiv.addEventListener("click", () => { |
1447 | 1470 | if (B && B.getMainWorkspace && thread.topBlock) { |
|
1526 | 1549 | container.appendChild(wrapper); |
1527 | 1550 |
|
1528 | 1551 | 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; |
1530 | 1557 | Object.assign(label.style, { |
1531 | 1558 | position: "absolute", |
1532 | 1559 | top: "2px", |
|
1698 | 1725 | marginLeft: "15px", |
1699 | 1726 | cursor: "pointer", |
1700 | 1727 | }); |
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; |
1702 | 1734 |
|
1703 | 1735 | messageDiv.addEventListener("click", () => { |
1704 | 1736 | if (B && B.getMainWorkspace && thread.topBlock) { |
|
0 commit comments