A game about forced loneliness, made by TACStudios
1using System; 2using System.Collections.Generic; 3using System.Runtime.Serialization; 4using Unity.PerformanceTesting.Exceptions; 5using UnityEngine.Profiling; 6 7namespace Unity.PerformanceTesting 8{ 9 /// <summary> 10 /// Represents a performance test sample group. 11 /// </summary> 12 [Serializable] 13 public class SampleGroup : IDeserializationCallback 14 { 15 /// <summary> 16 /// Name of the sample group. 17 /// </summary> 18 public string Name; 19 /// <summary> 20 /// Measurement unit. 21 /// </summary> 22 public SampleUnit Unit; 23 /// <summary> 24 /// Whether the measurement is inverted and increase is positive. 25 /// </summary> 26 public bool IncreaseIsBetter; 27 /// <summary> 28 /// List of samples. 29 /// </summary> 30 public List<double> Samples = new List<double>(); 31 /// <summary> 32 /// Minimum value of samples. 33 /// </summary> 34 public double Min; 35 /// <summary> 36 /// Maximum value of samples. 37 /// </summary> 38 public double Max; 39 /// <summary> 40 /// Medina value of samples. 41 /// </summary> 42 public double Median; 43 /// <summary> 44 /// Average value of samples. 45 /// </summary> 46 public double Average; 47 /// <summary> 48 /// Standard deviation of samples. 49 /// </summary> 50 public double StandardDeviation; 51 /// <summary> 52 /// Sum of samples. 53 /// </summary> 54 public double Sum; 55 56 /// <summary> 57 /// Creates a new sample group with given parameters. 58 /// </summary> 59 /// <param name="name">Name of the sample group.</param> 60 /// <param name="unit">Unit of measurement.</param> 61 /// <param name="increaseIsBetter">Whether the measurement is inverted and increase is positive.</param> 62 /// <exception cref="PerformanceTestException">Exception can be thrown if empty or null name is provided.</exception> 63 public SampleGroup(string name, SampleUnit unit = SampleUnit.Millisecond, bool increaseIsBetter = false) 64 { 65 Name = name; 66 Unit = unit; 67 IncreaseIsBetter = increaseIsBetter; 68 69 if (string.IsNullOrEmpty(name)) 70 { 71 throw new PerformanceTestException("Sample group name is empty. Please assign a valid name."); 72 } 73 } 74 75 internal Recorder Recorder; 76 77 /// <summary> 78 /// Gets the profiler recorder object. 79 /// </summary> 80 /// <returns>Profiler recorder.</returns> 81 public Recorder GetRecorder() 82 { 83 return Recorder ?? (Recorder = Recorder.Get(Name)); 84 } 85 86 /// <summary> 87 /// Validates the deserialized object. 88 /// </summary> 89 /// <param name="sender">The object that initiated the deserialization process.</param> 90 public void OnDeserialization(object sender) 91 { 92 if (string.IsNullOrEmpty(Name)) 93 { 94 throw new PerformanceTestException("Sample group name is empty. Please assign a valid name."); 95 } 96 } 97 } 98}