From ae893f02e4420b360434942b9f197df2619cebe6 Mon Sep 17 00:00:00 2001 From: wcko87 Date: Mon, 8 May 2017 05:57:23 +0800 Subject: [PATCH] Add a tracker for how frequently memory is read (reads per second) --- rabi_splitter_WPF/RabiRibiDisplay.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rabi_splitter_WPF/RabiRibiDisplay.cs b/rabi_splitter_WPF/RabiRibiDisplay.cs index 0ccb907..1494a18 100644 --- a/rabi_splitter_WPF/RabiRibiDisplay.cs +++ b/rabi_splitter_WPF/RabiRibiDisplay.cs @@ -17,6 +17,11 @@ namespace rabi_splitter_WPF private MemorySnapshot prevSnapshot; private MemorySnapshot snapshot; + // Variables used for tracking frequency of memory reads. + private static readonly DateTime UNIX_START = new DateTime(1970, 1, 1); + private double readFps = -1; + long previousFrameMillisecond = -1; + // internal frame counter. private int memoryReadCount; @@ -40,10 +45,25 @@ namespace rabi_splitter_WPF Update(); UpdateDebugArea(process); UpdateEntityData(process); + UpdateFps(); if (snapshot.musicid >= 0) rabiRibiState.lastValidMusicId = snapshot.musicid; prevSnapshot = snapshot; } + + private void UpdateFps() + { + long currentFrameMillisecond = (long)(DateTime.Now - UNIX_START).TotalMilliseconds; + if (previousFrameMillisecond != -1) + { + double newFps = 1000.0 / (currentFrameMillisecond - previousFrameMillisecond); + if (readFps < 0) readFps = newFps; + else readFps = 0.9 * readFps + 0.1 * newFps; + + mainContext.Text19 = $"Reads Per Second:\n{readFps:.0.00}"; + } + previousFrameMillisecond = currentFrameMillisecond; + } private void Update() {