Fix UnitLayer perf counters in prod overlay

This commit is contained in:
scamiv
2026-02-28 00:26:59 +01:00
parent 6a52daffbf
commit 3f357a3239
2 changed files with 21 additions and 1 deletions
+8
View File
@@ -485,11 +485,15 @@ export class GameRenderer {
const tickLayerDurations: Record<string, number> = {};
const layerCounters: Record<string, Record<string, number>> = {};
let unitLayerCounters: Record<string, number> | null = null;
for (const layer of this.layers) {
if (!layer.tick) {
const counters = layer.getPerfCounters?.();
if (counters && Object.keys(counters).length > 0) {
if (layer instanceof UnitLayer) {
unitLayerCounters = counters;
}
const label = layer.constructor?.name ?? "UnknownLayer";
layerCounters[label] = counters;
}
@@ -519,12 +523,16 @@ export class GameRenderer {
const counters = layer.getPerfCounters?.();
if (counters && Object.keys(counters).length > 0) {
if (layer instanceof UnitLayer) {
unitLayerCounters = counters;
}
const label = layer.constructor?.name ?? "UnknownLayer";
layerCounters[label] = counters;
}
}
this.performanceOverlay.updateLayerCounters(layerCounters);
this.performanceOverlay.updateUnitLayerCounters(unitLayerCounters);
if (shouldProfileTick) {
this.performanceOverlay.updateTickLayerMetrics(tickLayerDurations);
@@ -133,6 +133,9 @@ export class PerformanceOverlay extends LitElement implements Layer {
@state()
private layerCounters: Record<string, Record<string, number>> = {};
@state()
private unitLayerCounters: Record<string, number> | null = null;
// Smoothed per-layer render-per-tick timings (EMA over recent ticks)
private renderPerTickLayerStats: Map<
string,
@@ -734,6 +737,7 @@ export class PerformanceOverlay extends LitElement implements Layer {
this.renderLastTickLayerTotalMs = 0;
this.renderLastTickLayerDurations = {};
this.layerCounters = {};
this.unitLayerCounters = null;
this.renderPerTickLayerStats.clear();
this.renderLayersExpanded = false;
this.tickLayersExpanded = false;
@@ -909,6 +913,11 @@ export class PerformanceOverlay extends LitElement implements Layer {
this.layerCounters = counters;
}
updateUnitLayerCounters(counters: Record<string, number> | null) {
if (!this.isVisible) return;
this.unitLayerCounters = counters;
}
updateTickMetrics(tickExecutionDuration?: number, tickDelay?: number) {
if (!this.isVisible) return;
@@ -1029,6 +1038,9 @@ export class PerformanceOverlay extends LitElement implements Layer {
this.tickLayerStats,
).map((layer) => ({ ...layer })),
layerCounters: { ...this.layerCounters },
unitLayerCounters: this.unitLayerCounters
? { ...this.unitLayerCounters }
: null,
};
}
@@ -1112,7 +1124,7 @@ export class PerformanceOverlay extends LitElement implements Layer {
const renderLayersToShow = renderLayerBreakdown.slice(0, 10);
const tickLayersToShow = tickLayerBreakdown.slice(0, 10);
const unitLayerCounters = this.layerCounters.UnitLayer ?? null;
const unitLayerCounters = this.unitLayerCounters;
const maxLayerAvg =
renderLayersToShow.length > 0