Fix UnitLayer perf counters in prod overlay

This commit is contained in:
scamiv
2026-02-28 00:26:59 +01:00
parent b8caabc293
commit da0acec796
2 changed files with 21 additions and 1 deletions
+8
View File
@@ -483,11 +483,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;
}
@@ -517,12 +521,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);
@@ -144,6 +144,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,
@@ -642,6 +645,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;
@@ -841,6 +845,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;
@@ -957,6 +966,9 @@ export class PerformanceOverlay extends LitElement implements Layer {
layers: this.layerBreakdown.map((layer) => ({ ...layer })),
tickLayers: this.tickLayerBreakdown.map((layer) => ({ ...layer })),
layerCounters: { ...this.layerCounters },
unitLayerCounters: this.unitLayerCounters
? { ...this.unitLayerCounters }
: null,
};
}
@@ -1032,7 +1044,7 @@ export class PerformanceOverlay extends LitElement implements Layer {
const renderLayersToShow = this.layerBreakdown.slice(0, 10);
const tickLayersToShow = this.tickLayerBreakdown.slice(0, 10);
const unitLayerCounters = this.layerCounters.UnitLayer ?? null;
const unitLayerCounters = this.unitLayerCounters;
const maxLayerAvg =
renderLayersToShow.length > 0