Skip to content

Commit 23eedee

Browse files
feat(diagnostics): Add Client Subscriber Stats UI (#82)
1 parent 704f73f commit 23eedee

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

webview-ui/src/diagnostics_panel/App.tsx

+42-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,27 @@ import { useCallback, useState } from 'react';
77
import { StatisticType, YAxisType, createStatResolver } from './StatisticResolver';
88
import MinecraftStatisticLineChart from './controls/MinecraftStatisticLineChart';
99
import MinecraftStatisticStackedLineChart from './controls/MinecraftStatisticStackedLineChart';
10-
import { MultipleStatisticProvider, SimpleStatisticProvider } from './StatisticProvider';
10+
import MinecraftStatisticStackedBarChart from './controls/MinecraftStatisticStackedBarChart';
11+
import { MultipleStatisticProvider, SimpleStatisticProvider, StatisticUpdatedMessage } from './StatisticProvider';
1112

1213
import * as statPrefabs from './StatisticPrefabs';
1314

15+
// Filter out events with a value of zero that haven't been previously subscribed to
16+
function constructSubscribedSignalFilter() {
17+
const nonFilteredValues: string[] = [];
18+
19+
const func = (event: StatisticUpdatedMessage) => {
20+
if (event.values.length === 1 && event.values[0] === 0 && !nonFilteredValues.includes(event.id)) {
21+
return false;
22+
}
23+
24+
nonFilteredValues.push(event.id);
25+
return true;
26+
};
27+
28+
return func;
29+
}
30+
1431
function App() {
1532
// State
1633
const [selectedPlugin, setSelectedPlugin] = useState<string>('no_plugin_selected');
@@ -37,6 +54,7 @@ function App() {
3754
<VSCodePanelTab id="tab-5">Networking - Packets</VSCodePanelTab>
3855
<VSCodePanelTab id="tab-6">Networking - Bandwidth</VSCodePanelTab>
3956
<VSCodePanelTab id="tab-7">Handle Counts</VSCodePanelTab>
57+
<VSCodePanelTab id="tab-8">Subscriber Counts</VSCodePanelTab>
4058
<VSCodePanelView id="view-1" style={{ flexDirection: 'column' }}>
4159
<div style={{ flexDirection: 'row', display: 'flex' }}>
4260
{statPrefabs.entityCount.reactNode}
@@ -166,6 +184,29 @@ function App() {
166184
}}
167185
/>
168186
</VSCodePanelView>
187+
<VSCodePanelView id="view-8">
188+
<StatGroupSelectionBox
189+
labelName="Script Plugin"
190+
defaultDropdownId="no_plugin_selected"
191+
statParentId="fine_grained_subscribers"
192+
onChange={handlePluginSelection}
193+
/>
194+
<MinecraftStatisticStackedBarChart
195+
title="Signal Subscribers"
196+
yLabel="Number of World and System Before and After Event Subscribers Broken Down By Signal"
197+
statisticDataProvider={
198+
new MultipleStatisticProvider({
199+
statisticParentId: new RegExp(`fine_grained_subscribers_${selectedPlugin}`),
200+
valuesFilter: constructSubscribedSignalFilter(),
201+
})
202+
}
203+
statisticResolver={createStatResolver({
204+
type: StatisticType.Absolute,
205+
tickRange: 20 * 15 /* About 15 seconds */,
206+
yAxisType: YAxisType.Absolute,
207+
})}
208+
/>
209+
</VSCodePanelView>
169210
</VSCodePanels>
170211
</main>
171212
);

webview-ui/src/diagnostics_panel/StatisticProvider.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export class SimpleStatisticProvider extends StatisticProvider {
9191
interface MultipleStatisticProviderOptions {
9292
statisticIds?: string[]; // If not included, all stats will be included
9393
statisticParentId: string | RegExp;
94+
valuesFilter?: (event: StatisticUpdatedMessage) => boolean;
9495
}
9596
// Used for things like stacked bar charts
9697
export class MultipleStatisticProvider extends StatisticProvider {
@@ -117,6 +118,10 @@ export class MultipleStatisticProvider extends StatisticProvider {
117118
return;
118119
}
119120

121+
if (this.options.valuesFilter && !this.options.valuesFilter(event)) {
122+
return;
123+
}
124+
120125
this._fireEvent(event);
121126
}
122127
}

webview-ui/src/diagnostics_panel/controls/MinecraftStatisticStackedBarChart.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default function MinecraftStatisticStackedBarChart({
100100
plot.remove();
101101
}
102102
};
103-
}, [data]);
103+
}, [data, statisticDataProvider]);
104104

105105
return <div ref={containerRef} />;
106106
}

0 commit comments

Comments
 (0)