ThreadData.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. namespace UnityEditor.Performance.ProfileAnalyzer
  5. {
  6. [Serializable]
  7. internal class ThreadData
  8. {
  9. public string threadNameWithIndex;
  10. public int threadGroupIndex;
  11. public string threadGroupName;
  12. public int threadsInGroup;
  13. public List<ThreadFrameTime> frames = new List<ThreadFrameTime>();
  14. public float msMedian;
  15. public float msLowerQuartile;
  16. public float msUpperQuartile;
  17. public float msMin;
  18. public float msMax;
  19. public int medianFrameIndex;
  20. public int minFrameIndex;
  21. public int maxFrameIndex;
  22. public ThreadData(string _threadName)
  23. {
  24. threadNameWithIndex = _threadName;
  25. var info = threadNameWithIndex.Split(':');
  26. threadGroupIndex = int.Parse(info[0]);
  27. threadGroupName = info[1];
  28. threadsInGroup = 1;
  29. msMedian = 0.0f;
  30. msLowerQuartile = 0.0f;
  31. msUpperQuartile = 0.0f;
  32. msMin = 0.0f;
  33. msMax = 0.0f;
  34. medianFrameIndex = -1;
  35. minFrameIndex = -1;
  36. maxFrameIndex = -1;
  37. }
  38. struct ThreadFrameTimeFrameComparer : IComparer<ThreadFrameTime>
  39. {
  40. #if UNITY_2017_OR_NEWER
  41. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  42. #else
  43. [MethodImpl(256)]
  44. #endif
  45. public int Compare(ThreadFrameTime x, ThreadFrameTime y)
  46. {
  47. if (x.frameIndex == y.frameIndex)
  48. return 0;
  49. return x.frameIndex > y.frameIndex ? 1 : -1;
  50. }
  51. }
  52. #if UNITY_2017_OR_NEWER
  53. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  54. #else
  55. [MethodImpl(256)]
  56. #endif
  57. public ThreadFrameTime? GetFrame(int frameIndex)
  58. {
  59. var index = frames.BinarySearch(new ThreadFrameTime(frameIndex, 0, 0), new ThreadFrameTimeFrameComparer());
  60. return index >= 0 ? (ThreadFrameTime?)frames[index] : null;
  61. }
  62. }
  63. }