FrameTime.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. namespace UnityEditor.Performance.ProfileAnalyzer
  3. {
  4. [Serializable]
  5. /// <summary>
  6. /// Metrics related to an individual frame
  7. /// </summary>
  8. internal struct FrameTime : IComparable<FrameTime>
  9. {
  10. /// <summary>Duration in the frame in milliseconds</summary>
  11. public float ms;
  12. /// <summary>Index of which frame this time duration occured on. A zero based frame index</summary>
  13. public int frameIndex;
  14. /// <summary>Number of occurrences</summary>
  15. public int count;
  16. /// <summary>Initialise FrameTime</summary>
  17. /// <param name="index"> The frame index</param>
  18. /// <param name="msTime"> The duration of the frame in milliseconds</param>
  19. /// <param name="_count"> The number of occurrences</param>
  20. public FrameTime(int index, float msTime, int _count)
  21. {
  22. frameIndex = index;
  23. ms = msTime;
  24. count = _count;
  25. }
  26. /// <summary>Initialise from another FrameTime</summary>
  27. /// <param name="t"> The FrameTime to assign</param>
  28. public FrameTime(FrameTime t)
  29. {
  30. frameIndex = t.frameIndex;
  31. ms = t.ms;
  32. count = t.count;
  33. }
  34. /// <summary>Compare the time duration between the frames. Used for sorting in ascending order</summary>
  35. /// <param name="other"> The other FrameTime to compare </param>
  36. /// <returns>-1 if this is smaller, 0 if the same, 1 if this is larger</returns>
  37. public int CompareTo(FrameTime other)
  38. {
  39. if (ms == other.ms)
  40. {
  41. // secondary sort by frame index order
  42. return frameIndex.CompareTo(other.frameIndex);
  43. }
  44. return ms.CompareTo(other.ms);
  45. }
  46. /// <summary>Compare the time duration between two FrameTimes. Used for sorting in ascending order</summary>
  47. /// <param name="a"> The first FrameTime to compare </param>
  48. /// <param name="b"> The second FrameTime to compare </param>
  49. /// <returns>-1 if a is smaller, 0 if the same, 1 if a is larger</returns>
  50. public static int CompareMs(FrameTime a, FrameTime b)
  51. {
  52. if (a.ms == b.ms)
  53. {
  54. // secondary sort by frame index order
  55. return a.frameIndex.CompareTo(b.frameIndex);
  56. }
  57. return a.ms.CompareTo(b.ms);
  58. }
  59. /// <summary>Compare the instance count between two FrameTimes. Used for sorting in ascending order</summary>
  60. /// <param name="a"> The first FrameTime to compare </param>
  61. /// <param name="b"> The second FrameTime to compare </param>
  62. /// <returns>-1 if a is smaller, 0 if the same, 1 if a is larger</returns>
  63. public static int CompareCount(FrameTime a, FrameTime b)
  64. {
  65. if (a.count == b.count)
  66. {
  67. // secondary sort by frame index order
  68. return a.frameIndex.CompareTo(b.frameIndex);
  69. }
  70. return a.count.CompareTo(b.count);
  71. }
  72. /// <summary>Compare the time duration between two FrameTimes. Used for sorting in descending order</summary>
  73. /// <param name="a"> The first FrameTime to compare </param>
  74. /// <param name="b"> The second FrameTime to compare </param>
  75. /// <returns>-1 if a is larger, 0 if the same, 1 if a is smaller</returns>
  76. public static int CompareMsDescending(FrameTime a, FrameTime b)
  77. {
  78. if (a.ms == b.ms)
  79. {
  80. // secondary sort by frame index order
  81. return a.frameIndex.CompareTo(b.frameIndex);
  82. }
  83. return -a.ms.CompareTo(b.ms);
  84. }
  85. /// <summary>Compare the instance count between two FrameTimes. Used for sorting in descending order</summary>
  86. /// <param name="a"> The first FrameTime to compare </param>
  87. /// <param name="b"> The second FrameTime to compare </param>
  88. /// <returns>-1 if a is larger, 0 if the same, 1 if a is smaller</returns>
  89. public static int CompareCountDescending(FrameTime a, FrameTime b)
  90. {
  91. if (a.count == b.count)
  92. {
  93. // secondary sort by frame index order
  94. return a.frameIndex.CompareTo(b.frameIndex);
  95. }
  96. return -a.count.CompareTo(b.count);
  97. }
  98. }
  99. }