ProfileDataView.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Collections.Generic;
  3. namespace UnityEditor.Performance.ProfileAnalyzer
  4. {
  5. [Serializable]
  6. internal class ProfileDataView
  7. {
  8. public string path;
  9. public ProfileData data;
  10. public ProfileAnalysis analysisFullNew;
  11. public ProfileAnalysis analysisFull;
  12. public ProfileAnalysis analysisNew;
  13. public ProfileAnalysis analysis;
  14. public List<int> selectedIndices = new List<int> { 0, 0 };
  15. [NonSerialized]
  16. public bool inSyncWithProfilerData;
  17. public ProfileDataView()
  18. {
  19. }
  20. public ProfileDataView(ProfileDataView dataView)
  21. {
  22. path = dataView.path;
  23. data = dataView.data;
  24. analysisFullNew = dataView.analysisFullNew;
  25. analysisFull = dataView.analysisFull;
  26. analysisNew = dataView.analysisNew;
  27. analysis = dataView.analysis;
  28. selectedIndices = new List<int>(dataView.selectedIndices);
  29. inSyncWithProfilerData = dataView.inSyncWithProfilerData;
  30. }
  31. public bool IsDataValid()
  32. {
  33. if (data == null)
  34. return false;
  35. if (data.GetFrameCount() == 0)
  36. return false;
  37. if (data.NeedsMarkerRebuild)
  38. {
  39. if (!ProfileData.Load(data.FilePath, out data))
  40. {
  41. return false;
  42. }
  43. }
  44. return true;
  45. }
  46. public bool HasValidSelection()
  47. {
  48. if (selectedIndices.Count == 2 && selectedIndices[0] == 0 && selectedIndices[1] == 0)
  49. return false;
  50. return true;
  51. }
  52. public bool HasSelection()
  53. {
  54. if (selectedIndices.Count == 0)
  55. return false;
  56. if (selectedIndices.Count == data.GetFrameCount())
  57. return false;
  58. return HasValidSelection();
  59. }
  60. public bool AllSelected()
  61. {
  62. if (selectedIndices.Count != data.GetFrameCount())
  63. return false;
  64. return true;
  65. }
  66. public int GetMaxDepth()
  67. {
  68. return (analysis == null) ? 1 : analysis.GetFrameSummary().maxMarkerDepth;
  69. }
  70. int Clamp(int value, int min, int max)
  71. {
  72. if (value < min)
  73. value = min;
  74. else if (value > max)
  75. value = max;
  76. return value;
  77. }
  78. public int ClampToValidDepthValue(int depthFilter)
  79. {
  80. // ProfileAnalyzer.kDepthAll is special case that we don't test for here
  81. // If we have no depth values then return -1 for all (as clamp expects min<max)
  82. int maxDepth = GetMaxDepth();
  83. if (maxDepth < 1)
  84. return ProfileAnalyzer.kDepthAll;
  85. return Clamp(depthFilter, 1, maxDepth);
  86. }
  87. bool SelectAllFramesContainingMarker(string markerName, ProfileAnalysis inAnalysis)
  88. {
  89. if (inAnalysis == null)
  90. return false;
  91. selectedIndices.Clear();
  92. MarkerData markerData = inAnalysis.GetMarkerByName(markerName);
  93. if (markerData == null)
  94. return true;
  95. foreach (var frameTime in markerData.frames)
  96. {
  97. selectedIndices.Add(frameTime.frameIndex);
  98. }
  99. // Order from lowest to highest so the start/end frame display makes sense
  100. selectedIndices.Sort();
  101. return true;
  102. }
  103. public bool SelectAllFramesContainingMarker(string markerName, bool inSelection)
  104. {
  105. return SelectAllFramesContainingMarker(markerName, inSelection ? analysis : analysisFull);
  106. }
  107. int ClampToRange(int value, int min, int max)
  108. {
  109. if (value < min)
  110. value = min;
  111. if (value > max)
  112. value = max;
  113. return value;
  114. }
  115. public void ClearSelection()
  116. {
  117. selectedIndices.Clear();
  118. }
  119. public void SelectFullRange()
  120. {
  121. selectedIndices.Clear();
  122. if (data == null)
  123. return;
  124. for (int offset = 0; offset < data.GetFrameCount(); offset++)
  125. {
  126. selectedIndices.Add(data.OffsetToDisplayFrame(offset));
  127. }
  128. }
  129. }
  130. }