ProfileAnalyzerBaseTest.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using NUnit.Framework;
  2. using UnityEditor.Performance.ProfileAnalyzer;
  3. using UnityEditor;
  4. using UnityEditorInternal;
  5. using System.Collections.Generic;
  6. public class ProfileAnalyzerBaseTest
  7. {
  8. protected struct FrameSetupData
  9. {
  10. internal ProgressBarDisplay progressBar;
  11. internal ProfileAnalyzer analyzer;
  12. internal ProfilerWindowInterface profilerWindowInterface;
  13. internal ProfileData profileData;
  14. internal int depthFilter;
  15. internal List<string> threadFilters;
  16. internal int firstFrame;
  17. internal int lastFrame;
  18. internal FrameSetupData(int minFrame, int maxFrame, int filterDepth, List<string> filterThreads)
  19. {
  20. progressBar = new ProgressBarDisplay();
  21. firstFrame = minFrame;
  22. lastFrame = maxFrame;
  23. analyzer = new ProfileAnalyzer();
  24. profilerWindowInterface = new ProfilerWindowInterface(progressBar);
  25. profileData = profilerWindowInterface.PullFromProfiler(minFrame, maxFrame);
  26. depthFilter = filterDepth;
  27. threadFilters = filterThreads;
  28. }
  29. };
  30. protected FrameSetupData m_SetupData;
  31. [SetUp]
  32. public void SetupTest()
  33. {
  34. ProfilerDriver.ClearAllFrames();
  35. m_SetupData = new FrameSetupData(1, 300, -1, new List<string> { "1:Main Thread" });
  36. }
  37. [TearDown]
  38. public void TearDownTest()
  39. {
  40. }
  41. List<int> SelectRange(int startIndex, int endIndex)
  42. {
  43. List<int> list = new List<int>();
  44. for (int c = startIndex; c <= endIndex; c++)
  45. {
  46. list.Add(c);
  47. }
  48. return list;
  49. }
  50. internal ProfileAnalysis GetAnalysisFromFrameData(ProfileData profileData)
  51. {
  52. return m_SetupData.analyzer.Analyze(profileData,
  53. SelectRange(m_SetupData.firstFrame, m_SetupData.lastFrame),
  54. m_SetupData.threadFilters,
  55. m_SetupData.depthFilter);
  56. }
  57. protected void StartProfiler()
  58. {
  59. #if UNITY_2017_1_OR_NEWER
  60. ProfilerDriver.enabled = true;
  61. #endif
  62. ProfilerDriver.profileEditor = true;
  63. }
  64. protected void StopProfiler()
  65. {
  66. EditorApplication.isPlaying = false;
  67. #if UNITY_2017_1_OR_NEWER
  68. ProfilerDriver.enabled = false;
  69. #endif
  70. ProfilerDriver.profileEditor = false;
  71. }
  72. }