MCPcopy
hub / github.com/CapSoftware/Cap / PerformanceOverlay

Function PerformanceOverlay

apps/desktop/src/routes/editor/PerformanceOverlay.tsx:30–271  ·  view source on GitHub ↗
(_props: PerformanceOverlayProps)

Source from the content-addressed store, hash-verified

28const MAX_TIMESTAMPS = 120;
29
30export function PerformanceOverlay(_props: PerformanceOverlayProps) {
31 const { performanceMode, latestFrame, editorState } = useEditorContext();
32
33 let frameTimestamps: number[] = [];
34 let lastFrameTime = 0;
35 let frameIntervals: number[] = [];
36 let droppedFrameCount = 0;
37 let totalFrameCount = 0;
38
39 const [stats, setStats] = createSignal<FrameStats>({
40 fps: 0,
41 avgFrameMs: 0,
42 minFrameMs: 0,
43 maxFrameMs: 0,
44 jitter: 0,
45 droppedFrames: 0,
46 totalFrames: 0,
47 });
48
49 const calculateStats = (): FrameStats => {
50 const now = performance.now();
51
52 while (
53 frameTimestamps.length > 0 &&
54 now - frameTimestamps[0] > STATS_WINDOW_MS
55 ) {
56 frameTimestamps.shift();
57 }
58
59 while (frameIntervals.length > MAX_TIMESTAMPS) {
60 frameIntervals.shift();
61 }
62
63 if (frameTimestamps.length < 2) {
64 return {
65 fps: 0,
66 avgFrameMs: 0,
67 minFrameMs: 0,
68 maxFrameMs: 0,
69 jitter: 0,
70 droppedFrames: droppedFrameCount,
71 totalFrames: totalFrameCount,
72 };
73 }
74
75 const windowMs = now - frameTimestamps[0];
76 const fps =
77 windowMs > 0 ? ((frameTimestamps.length - 1) / windowMs) * 1000 : 0;
78
79 let avgFrameMs = 0;
80 let minFrameMs = Number.MAX_VALUE;
81 let maxFrameMs = 0;
82
83 if (frameIntervals.length > 0) {
84 let sum = 0;
85 for (const interval of frameIntervals) {
86 sum += interval;
87 minFrameMs = Math.min(minFrameMs, interval);

Callers

nothing calls this directly

Calls 5

onFunction · 0.85
calculateStatsFunction · 0.85
resetStatsFunction · 0.85
formatFpsFunction · 0.85
formatMsFunction · 0.85

Tested by

no test coverage detected