Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/panels/minecraft-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { DiagnosticsTabDescriptor } from '../diagnostics-schema';

const DIAGNOSTICS_TAB_STATES_KEY = 'minecraftDiagnosticsTabStates';
const STAT_MESSAGE_FLUSH_DELAY_MS = 16;
type DiagnosticsTabStates = Record<string, boolean>;

export class MinecraftDiagnosticsPanel {
Expand All @@ -18,6 +19,8 @@
private _disposables: Disposable[] = [];
private _statsTracker: StatsProvider;
private _statsCallback: StatsListener | undefined = undefined;
private _pendingStatMessages: Array<Record<string, unknown>> = [];
private _statFlushTimer: ReturnType<typeof setTimeout> | undefined;
private _eventEmitter: EventEmitter;
private _debuggerRequestHandler: DebuggerRequestHandler;

Expand Down Expand Up @@ -112,7 +115,7 @@
time: stat.tick,
group_full_id: stat.parent_full_id,
};
this._panel.webview.postMessage(message);
this.queueStatMessage(message);
}
},
onSpeedUpdated: (speed: number) => {
Expand Down Expand Up @@ -144,6 +147,25 @@
this._statsTracker.addStatListener(this._statsCallback);
}

private queueStatMessage(message: Record<string, unknown>): void {
this._pendingStatMessages.push(message);

if (this._statFlushTimer === undefined) {
this._statFlushTimer = setTimeout(() => this.flushStatMessages(), STAT_MESSAGE_FLUSH_DELAY_MS);
}
}

private flushStatMessages(): void {
this._statFlushTimer = undefined;
if (this._pendingStatMessages.length === 0) {
return;
}

const events = this._pendingStatMessages;
this._pendingStatMessages = [];
this._panel.webview.postMessage({ type: 'statistic-updated-batch', events });
}

private getDiagnosticsTabStates(): DiagnosticsTabStates {
const states = this._globalState.get<DiagnosticsTabStates>(DIAGNOSTICS_TAB_STATES_KEY, {});
if (states === null || typeof states !== 'object' || Array.isArray(states)) {
Expand Down Expand Up @@ -194,7 +216,7 @@
saveLabel: 'Export',
defaultUri: workspaceFolderUri ? Uri.joinPath(workspaceFolderUri, suggestedFileName) : undefined,
filters: {
'CSV Files': ['csv'],

Check warning on line 219 in src/panels/minecraft-diagnostics.ts

View workflow job for this annotation

GitHub Actions / Build and Test

Object Literal Property name `CSV Files` must match one of the following formats: camelCase, snake_case
},
});

Expand Down Expand Up @@ -251,6 +273,12 @@
this._statsCallback = undefined;
}

if (this._statFlushTimer !== undefined) {
clearTimeout(this._statFlushTimer);
this._statFlushTimer = undefined;
}
this._pendingStatMessages = [];

// Remove the current panel from the active panel list
MinecraftDiagnosticsPanel.activeDiagnosticsPanels = MinecraftDiagnosticsPanel.activeDiagnosticsPanels.filter(
panel => panel !== this,
Expand Down
7 changes: 4 additions & 3 deletions webview-ui/src/diagnostics_panel/StatisticProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import type { StatisticPrefab } from './prefabs/StatisticPrefab';

export interface StatisticUpdatedMessage {
type: 'statistic-updated';
should_aggregate: boolean;
values: number[];
children_string_values: string[][];
Expand All @@ -27,8 +26,10 @@ export class StatisticProvider {
}

private _handleRawEvent(event: MessageEvent) {
if (event.data.type === 'statistic-updated') {
this._handleEvent(event.data as StatisticUpdatedMessage);
if (event.data.type === 'statistic-updated-batch' && Array.isArray(event.data.events)) {

@AlexDenfordSkyboxLabs AlexDenfordSkyboxLabs Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this backwards compatable? I feel like an old MC will fail to work now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event is only used to communicate internally between the minecraft-diagnostics webview and the statistic provider. It did not require any schema change between MC and the Script Debugger.

I did test out the other tabs that rely on StatisticProvider to make sure they still worked fine when connected to both an old and new build.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh my mistake yeah ok that is fine then. Cool thanks for the clarification!

for (const statisticEvent of event.data.events) {
this._handleEvent(statisticEvent as StatisticUpdatedMessage);
}
}
}

Expand Down
50 changes: 28 additions & 22 deletions webview-ui/src/diagnostics_panel/controls/StatGroupSelectionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,35 @@ export function StatGroupSelectionBox({ labelName, statParentId, onChange, helpT

//draws chart
useEffect(() => {
const eventHandler = (e: MessageEvent): void => {
// Object containing type prop and value prop
const msg: MessageEvent = e;

switch (msg.data.type) {
case 'statistic-updated': {
if (msg.data.group !== statParentId) {
return;
const handleStatistic = (statistic: {
group: string;
id: string;
name: string;
}): void => {
if (statistic.group !== statParentId) {
return;
}
// Add it to the list
setGroup(prevState => {
const isNewGroup = !prevState || prevState.findIndex(x => x.id === statistic.id) === -1;
if (isNewGroup) {
// auto select the first group we get if nothing selected
if (!selectedGroupId) {
setSelectedGroupId(statistic.id);
}
// Add it to the list
setGroup(prevState => {
const isNewGroup = !prevState || prevState.findIndex(x => x.id === msg.data.id) === -1;
if (isNewGroup) {
// auto select the first group we get if nothing selected
if (!selectedGroupId) {
setSelectedGroupId(msg.data.id);
}
// add new group to end of list
const newState = [...(prevState ?? []), { id: msg.data.id, name: msg.data.name }];
return newState;
}
return prevState;
});
// add new group to end of list
const newState = [...(prevState ?? []), { id: statistic.id, name: statistic.name }];
return newState;
}
return prevState;
});
};

const eventHandler = (e: MessageEvent): void => {
const message = e.data;
if (message.type === 'statistic-updated-batch' && Array.isArray(message.events)) {
for (const statistic of message.events) {
handleStatistic(statistic);
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions webview-ui/src/diagnostics_panel/prefabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dynamicPropertyTab from './tabs/DynamicProperties';

import serverScriptHandleCountsTab from './tabs/ServerScriptHandleCounts';
import serverScriptSubscriberCountsTab from './tabs/ServerScriptSubscriberCounts';
import serverEntitySystemTab from './tabs/ServerEntitySystems';

import clientTimingTab from './tabs/ClientTiming';
import clientMemoryTab from './tabs/ClientMemory';
Expand All @@ -24,6 +25,7 @@ export default [
serverBandwidthTab,
serverScriptHandleCountsTab,
serverScriptSubscriberCountsTab,
serverEntitySystemTab,
clientTimingTab,
clientMemoryTab,
clientEntitySystemTab,
Expand Down
Loading
Loading