using System.Collections.Generic; using Logging.Base; using Logging.Data; using UnityEngine; namespace Logging { public readonly struct FPSData : ISerializable { private readonly long timestamp; private readonly int fps; public FPSData(long timestamp, int fps) { this.timestamp = timestamp; this.fps = fps; } public KeyValuePair Serialize() => new KeyValuePair(timestamp, new[] { fps.ToString() }); } public class FPSLogger : SensorDataLogger { public override string Key => "fps"; const float FPSMeasurePeriod = 0.5f; private int fpsAccumulator = 0; private float fpsNextPeriod = 0; private int currentFps; public override void Start() { base.Start(); fpsNextPeriod = Time.realtimeSinceStartup + FPSMeasurePeriod; } private void Update() { fpsAccumulator++; if (Time.realtimeSinceStartup > fpsNextPeriod) { currentFps = (int) (fpsAccumulator / FPSMeasurePeriod); fpsAccumulator = 0; fpsNextPeriod += FPSMeasurePeriod; } Debug.Log($"Current FPS = {currentFps}"); Log(new FPSData(Helpers.RoundToLong(Time.time * 1000f), currentFps)); } public override IEnumerable ReadLog(IEnumerable> lines) { throw new System.NotImplementedException(); } } }