A game framework written with osu! in mind.
at master 84 lines 2.4 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using System.Collections.Generic; 6 7namespace osu.Framework.Statistics 8{ 9 internal class FrameStatistics 10 { 11 internal readonly Dictionary<PerformanceCollectionType, double> CollectedTimes = new Dictionary<PerformanceCollectionType, double>(NUM_STATISTICS_COUNTER_TYPES); 12 internal readonly Dictionary<StatisticsCounterType, long> Counts = new Dictionary<StatisticsCounterType, long>(NUM_STATISTICS_COUNTER_TYPES); 13 internal readonly List<int> GarbageCollections = new List<int>(); 14 public double FramesPerSecond { get; set; } 15 16 internal static readonly int NUM_STATISTICS_COUNTER_TYPES = Enum.GetValues(typeof(StatisticsCounterType)).Length; 17 internal static readonly int NUM_PERFORMANCE_COLLECTION_TYPES = Enum.GetValues(typeof(PerformanceCollectionType)).Length; 18 19 internal static readonly long[] COUNTERS = new long[NUM_STATISTICS_COUNTER_TYPES]; 20 21 internal void Clear() 22 { 23 CollectedTimes.Clear(); 24 GarbageCollections.Clear(); 25 Counts.Clear(); 26 FramesPerSecond = 0; 27 } 28 29 internal static void Increment(StatisticsCounterType type) => ++COUNTERS[(int)type]; 30 31 internal static void Add(StatisticsCounterType type, long amount) => COUNTERS[(int)type] += amount; 32 } 33 34 internal enum PerformanceCollectionType 35 { 36 Work = 0, 37 SwapBuffer, 38 WndProc, 39 Debug, 40 Sleep, 41 Scheduler, 42 IPC, 43 GLReset, 44 } 45 46 internal enum StatisticsCounterType 47 { 48 Invalidations = 0, 49 Refreshes, 50 DrawNodeCtor, 51 DrawNodeAppl, 52 ScheduleInvk, 53 InputQueue, 54 PositionalIQ, 55 56 /// <summary> 57 /// See <see cref="osu.Framework.Graphics.Containers.CompositeDrawable.CheckChildrenLife"/>. 58 /// </summary> 59 CCL, 60 61 VBufBinds, 62 VBufOverflow, 63 TextureBinds, 64 FBORedraw, 65 DrawCalls, 66 ShaderBinds, 67 VerticesDraw, 68 VerticesUpl, 69 Pixels, 70 71 TasksRun, 72 Tracks, 73 Samples, 74 SChannels, 75 Components, 76 MixChannels, 77 78 MouseEvents, 79 KeyEvents, 80 JoystickEvents, 81 MidiEvents, 82 TabletEvents, 83 } 84}