LVRS Document Viewer
backend/RenderMonitor.svx
Path: backend/RenderMonitor.svx
RenderMonitor
Location: backend/runtime/renderingmonitor.h / backend/runtime/renderingmonitor.cpp
RenderMonitor provides frame timing metrics (fps, frame time, percentile frame stats, drop counters) for a QQuickWindow.
Purpose
- Observe render cadence via
QQuickWindow::frameSwapped. - Expose runtime frame performance metrics to QML.
- Allow start/stop/reset control independent of window lifecycle.
- Provide P0 baseline metrics (
avg,p95,p99, dropped frames) in a single snapshot schema.
Properties
active: boolfps: doublelastFrameMs: doubleavgFrameMs: doublep95FrameMs: doublep99FrameMs: doubledroppedFrameCount: uint64droppedFrameThresholdMs: doubleframeSampleCapacity: intrecentSampleCount: intframeCount: uint64
Methods
attachWindow(window)start()stop()reset()performanceSnapshot()
Signals
activeChanged()statsChanged()droppedFrameThresholdMsChanged()frameSampleCapacityChanged()
How It Works
attachWindow(window)disconnects existing target and binds to newQQuickWindow.- On every
frameSwapped, monitor computes elapsed milliseconds from previous frame. fpsis derived as1000 / lastFrameMswhen elapsed time is positive.- Maintains rolling frame samples and computes
avg/p95/p99from that window. - Increments
droppedFrameCountwhen frame time exceedsdroppedFrameThresholdMs. - Window destruction auto-detaches target and deactivates monitor.
Snapshot Schema (performanceSnapshot)
Returned map keys:
schema(lvrs.performance.v1)component(RenderMonitor)epochMsactivefpslastFrameMsavgFrameMsp95FrameMsp99FrameMsframeCountdroppedFrameCountdroppedFrameThresholdMsrecentSampleCountframeSampleCapacity
Usage Example
import LVRS 1.0 as LV
Component.onCompleted: {
LV.RenderMonitor.attachWindow(window)
LV.RenderMonitor.start()
}
LV.Label {
text: "FPS: " + LV.RenderMonitor.fps.toFixed(1)
style: body
}
Operational Usage Pattern
Recommended lifecycle:
- attach window after root window creation,
- set
frameSampleCapacityanddroppedFrameThresholdMsfor target scenario, - start monitor when entering performance-sensitive screen,
- reset metrics before measurement run,
- stop monitor when leaving the screen to reduce unnecessary signal churn.
Caveats
fpsreflects frame swap cadence, not end-to-end app latency.- First frame after reset is used to initialize timing baseline.
- Percentile metrics are computed from rolling window, not full process lifetime.
FAQ
Q. Why does FPS read 0 at startup?
A. Metrics are initialized after first frame swap; values remain zero before frame cadence is established.