Introducing Framecounter for measuring FPS#799
Draft
jfboeve wants to merge 4 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new FPS “frame counter” utility and extends the fpsUpdate event payload to include bucketed frame-time counts, configurable via a new fpsBoundaries runtime setting.
Changes:
- Introduces
src/core/lib/fps.tsto track FPS and bucket frame delta times. - Wires Stage FPS tracking to the new frame counter and adds runtime update hooks for interval/boundaries.
- Extends shared
FpsUpdatePayloadto includeframeCountand plumbsfpsBoundariesthrough renderer settings.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| src/main-api/Renderer.ts | Adds fpsBoundaries setting and propagates runtime updates to Stage. |
| src/core/Stage.ts | Replaces legacy FPS aggregation with the new frame-counter-based approach and adds update methods. |
| src/core/lib/fps.ts | New FPS/frame bucketing utility used by Stage. |
| src/common/CommonTypes.ts | Extends FpsUpdatePayload with frameCount typing. |
Comment on lines
+208
to
+212
| // Set initial frame buckets and FPS update interval for FPS tracking | ||
| if (options.fpsBoundaries) { | ||
| setFrameBuckets(options.fpsBoundaries); | ||
| } | ||
| setFpsInterval(options.fpsUpdateInterval); |
Comment on lines
+558
to
+560
| let frameCounter = this.currentFrameCounter; | ||
| const eleapsed = this.elapsedTime; | ||
| if (frameCounter !== null && frameCounter.end < eleapsed) { |
Comment on lines
+557
to
561
| if (fpsUpdateInterval > 0) { | ||
| let frameCounter = this.currentFrameCounter; | ||
| const eleapsed = this.elapsedTime; | ||
| if (frameCounter !== null && frameCounter.end < eleapsed) { | ||
| this.queueFrameEvent('fpsUpdate', { |
Comment on lines
+90
to
+99
| export function createFrameCounter(frameTime: number): FrameCounter { | ||
| const counter = Object.create(frameCounter) as FrameCounter; | ||
| counter.boundaries = boundaries; | ||
| counter.start = frameTime; | ||
| counter.end = frameTime + fpsInterval; | ||
| //fill frames with 0 for each bucket | ||
| for (let i = 0; i < boundaries.length; i++) { | ||
| const bucket = boundaries[i] as number; | ||
| counter.count[bucket] = 0; | ||
| } |
Comment on lines
+65
to
+75
| increment(frameDelta: number) { | ||
| this.total++; | ||
| for (let i = 0; i < boundaries.length; i++) { | ||
| const bucket = boundaries[i] as number; | ||
| if (frameDelta <= bucket) { | ||
| this.count[bucket]!++; | ||
| return; | ||
| } | ||
| } | ||
| this.count['overflow']!++; | ||
| }, |
Comment on lines
+56
to
+80
| let boundaries = [20, 40, 60, 80, 100]; | ||
| let fpsInterval = 1000; // 1 second | ||
|
|
||
| const frameCounter: FrameCounter = { | ||
| start: 0, | ||
| end: 0, | ||
| total: 0, | ||
| boundaries: [], | ||
| count: {}, | ||
| increment(frameDelta: number) { | ||
| this.total++; | ||
| for (let i = 0; i < boundaries.length; i++) { | ||
| const bucket = boundaries[i] as number; | ||
| if (frameDelta <= bucket) { | ||
| this.count[bucket]!++; | ||
| return; | ||
| } | ||
| } | ||
| this.count['overflow']!++; | ||
| }, | ||
| get averageFps() { | ||
| //calculate fps based on frame count and elapsed time | ||
| return (this.total / (this.end - this.start)) * 1000; | ||
| }, | ||
| }; |
Comment on lines
139
to
143
| export interface FpsUpdatePayload { | ||
| fps: number; | ||
| contextSpyData: Record<string, number> | null; | ||
| frameCount: FrameCount; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.