Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SampleGroup.cs 3.1KB

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