1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- 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<long, string[]> Serialize() => new KeyValuePair<long, string[]>(timestamp, new[]
- {
- fps.ToString()
- });
- }
- public class FPSLogger : SensorDataLogger<FPSData>
- {
- public override string Key => "fps";
- private float lastTs = 0f;
- public float checkInterval = 1f;
- private int currentFps = -1;
- private int frameCount = 0;
- public override void Start()
- {
- base.Start();
- lastTs = Time.time;
- }
- private void Update()
- {
- var dif = Time.time - lastTs;
- frameCount++;
- if (dif >= checkInterval)
- {
- currentFps = (int) (frameCount / dif);
- lastTs = Time.time;
- frameCount = 0;
- }
- Log(new FPSData(Helpers.RoundToLong(Time.time * 1000f), currentFps));
- }
- public override IEnumerable<FPSData> ReadLog(IEnumerable<IEnumerable<string>> lines)
- {
- throw new NotImplementedException();
- }
- }
- }
|