No Description
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.

Metadata.cs 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using Unity.PerformanceTesting.Data;
  3. using Unity.PerformanceTesting.Runtime;
  4. using UnityEngine;
  5. #if USE_CUSTOM_METADATA
  6. using com.unity.test.metadatamanager;
  7. #endif
  8. namespace Unity.PerformanceTesting
  9. {
  10. /// <summary>
  11. /// Helper class to retrieve metadata information about player settings and hardware.
  12. /// </summary>
  13. public static class Metadata
  14. {
  15. /// <summary>
  16. /// Gets hardware information.
  17. /// </summary>
  18. /// <returns>Hardware information.</returns>
  19. public static Hardware GetHardware()
  20. {
  21. return new Hardware
  22. {
  23. OperatingSystem = SystemInfo.operatingSystem,
  24. DeviceModel = SystemInfo.deviceModel,
  25. DeviceName = SystemInfo.deviceName,
  26. ProcessorType = SystemInfo.processorType,
  27. ProcessorCount = SystemInfo.processorCount,
  28. GraphicsDeviceName = SystemInfo.graphicsDeviceName,
  29. SystemMemorySizeMB = SystemInfo.systemMemorySize
  30. };
  31. }
  32. /// <summary>
  33. /// Sets player settings.
  34. /// </summary>
  35. /// <param name="run">Run used to set settings.</param>
  36. public static void SetPlayerSettings(Run run)
  37. {
  38. run.Player.Vsync = QualitySettings.vSyncCount;
  39. run.Player.AntiAliasing = QualitySettings.antiAliasing;
  40. run.Player.ColorSpace = QualitySettings.activeColorSpace.ToString();
  41. run.Player.AnisotropicFiltering = QualitySettings.anisotropicFiltering.ToString();
  42. run.Player.BlendWeights = QualitySettings.skinWeights.ToString();
  43. #if UNITY_2022_2_OR_NEWER
  44. run.Player.ScreenRefreshRate = (int)Math.Round(Screen.currentResolution.refreshRateRatio.value); // casting to int and rounding to ensure backwards compatibility with older package versions
  45. #else
  46. run.Player.ScreenRefreshRate = Screen.currentResolution.refreshRate;
  47. #endif
  48. run.Player.ScreenWidth = Screen.currentResolution.width;
  49. run.Player.ScreenHeight = Screen.currentResolution.height;
  50. run.Player.Fullscreen = Screen.fullScreen;
  51. run.Player.Batchmode = Application.isBatchMode;
  52. run.Player.Development = Application.isEditor || Debug.isDebugBuild;
  53. run.Player.Platform = Application.platform.ToString();
  54. run.Player.GraphicsApi = SystemInfo.graphicsDeviceType.ToString();
  55. }
  56. /// <summary>
  57. /// Loads run from resources.
  58. /// </summary>
  59. /// <returns></returns>
  60. public static Run GetFromResources()
  61. {
  62. var run = ResourcesLoader.Load<Run>(Utils.TestRunInfo, Utils.PlayerPrefKeyRunJSON);
  63. SetRuntimeSettings(run);
  64. return run;
  65. }
  66. /// <summary>
  67. /// Sets runtime player settings on a run.
  68. /// </summary>
  69. /// <param name="run">Run used to set settings.</param>
  70. public static void SetRuntimeSettings(Run run)
  71. {
  72. run.Hardware = GetHardware();
  73. SetPlayerSettings(run);
  74. run.TestSuite = Application.isPlaying ? "Playmode" : "Editmode";
  75. #if USE_CUSTOM_METADATA
  76. SetCustomMetadata(run);
  77. #endif
  78. }
  79. #if USE_CUSTOM_METADATA
  80. private static void SetCustomMetadata(Run run)
  81. {
  82. var customMetadataManager = new CustomMetadataManager(run.Dependencies);
  83. // This field is historically not used so we can safely store additional string delimited
  84. // metadata here, then parse the metadata values out on the SQL side to give us access
  85. // to additional metadata that would normally require a schema change, or a property back field
  86. run.Player.AndroidTargetSdkVersion = customMetadataManager.GetCustomMetadata();
  87. }
  88. #endif
  89. }
  90. }