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.

IPerformanceStatus.cs 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using System;
  2. namespace UnityEngine.AdaptivePerformance
  3. {
  4. /// <summary>
  5. /// Event arguments for performance bottleneck changes. These are used in the <see cref="PerformanceBottleneckChangeHandler"/>.
  6. /// </summary>
  7. public struct PerformanceBottleneckChangeEventArgs
  8. {
  9. /// <summary>
  10. /// The performance bottleneck reported in the event.
  11. /// </summary>
  12. public PerformanceBottleneck PerformanceBottleneck { get; set; }
  13. }
  14. /// <summary>
  15. /// You can subscribe to the bottleneck event delegate which sends the <see cref="PerformanceBottleneckChangeEventArgs"/> when the bottleneck changes.
  16. /// </summary>
  17. /// <param name="bottleneckEventArgs">The <see cref="PerformanceBottleneckChangeEventArgs"/> that describes the performance bottleneck state.</param>
  18. public delegate void PerformanceBottleneckChangeHandler(PerformanceBottleneckChangeEventArgs bottleneckEventArgs);
  19. /// <summary>
  20. /// Event arguments for boost changes. These are used in the <see cref="PerformanceBottleneckChangeHandler"/>.
  21. /// </summary>
  22. public struct PerformanceBoostChangeEventArgs
  23. {
  24. /// <summary>
  25. /// Is the CPU boosted.
  26. /// </summary>
  27. public bool CpuBoost { get; set; }
  28. /// <summary>
  29. /// Is the GPU boosted
  30. /// </summary>
  31. public bool GpuBoost { get; set; }
  32. }
  33. /// <summary>
  34. /// You can subscribe to the boost event delegate which sends the <see cref="PerformanceBoostChangeEventArgs"/> when a boost changes.
  35. /// </summary>
  36. /// <param name="boostEventArgs">The <see cref="PerformanceBoostChangeEventArgs"/> that describes the boost event.</param>
  37. public delegate void PerformanceBoostChangeHandler(PerformanceBoostChangeEventArgs boostEventArgs);
  38. /// <summary>
  39. /// Arguments for the performance level change event. These are used in the <see cref="PerformanceLevelChangeHandler"/>.
  40. /// </summary>
  41. public struct PerformanceLevelChangeEventArgs
  42. {
  43. /// <summary>
  44. /// The new CPU level.
  45. /// </summary>
  46. public int CpuLevel { get; set; }
  47. /// <summary>
  48. /// The difference in CPU levels
  49. /// 0 if the previous or new level equals <see cref="Constants.UnknownPerformanceLevel"/>.
  50. /// </summary>
  51. public int CpuLevelDelta { get; set; }
  52. /// <summary>
  53. /// The new GPU level.
  54. /// </summary>
  55. public int GpuLevel { get; set; }
  56. /// <summary>
  57. /// The difference in GPU levels.
  58. /// 0 if either the previous or the new level equals <see cref="Constants.UnknownPerformanceLevel"/>.
  59. /// </summary>
  60. public int GpuLevelDelta { get; set; }
  61. /// <summary>
  62. /// The current PerformanceControlMode. See <see cref="IDevicePerformanceControl.PerformanceControlMode"/>.
  63. /// </summary>
  64. public PerformanceControlMode PerformanceControlMode { get; set; }
  65. /// <summary>
  66. /// True if the change was caused by manual adjustments to <see cref="IDevicePerformanceControl.CpuLevel"/> or <see cref="IDevicePerformanceControl.GpuLevel"/> during automatic mode, false otherwise.
  67. /// </summary>
  68. public bool ManualOverride { get; set; }
  69. }
  70. /// <summary>
  71. /// You can subscribe to the performance level event delegate which sends the <see cref="PerformanceLevelChangeEventArgs"/> when the performance level changes.
  72. /// </summary>
  73. /// <param name="levelChangeEventArgs">The performance level change event is sent to the delegate via the level change event argument.</param>
  74. public delegate void PerformanceLevelChangeHandler(PerformanceLevelChangeEventArgs levelChangeEventArgs);
  75. /// <summary>
  76. /// You can use the performance status interface to obtain performance metrics, frame timing, and subscribe to bottleneck and performance event changes.
  77. /// </summary>
  78. public interface IPerformanceStatus
  79. {
  80. /// <summary>
  81. /// Allows you to query the latest performance metrics.
  82. /// </summary>
  83. PerformanceMetrics PerformanceMetrics { get; }
  84. /// <summary>
  85. /// Allows you to query the latest frame timing measurements.
  86. /// </summary>
  87. FrameTiming FrameTiming { get; }
  88. /// <summary>
  89. /// Subscribe to performance events and get updates when the bottleneck changes.
  90. /// </summary>
  91. event PerformanceBottleneckChangeHandler PerformanceBottleneckChangeEvent;
  92. /// <summary>
  93. /// Subscribe to events and get updates when the the current CPU or GPU level changes.
  94. /// </summary>
  95. event PerformanceLevelChangeHandler PerformanceLevelChangeEvent;
  96. /// <summary>
  97. /// Subscribe to events and get updates when the the current CPU or GPU is boosted.
  98. /// </summary>
  99. event PerformanceBoostChangeHandler PerformanceBoostChangeEvent;
  100. }
  101. /// <summary>
  102. /// PerformanceMetrics store the current bottleneck, CPU, and GPU levels
  103. /// </summary>
  104. public struct PerformanceMetrics
  105. {
  106. /// <summary>
  107. /// Current CPU performance level.
  108. /// This value updates once per frame when changes are applied to <see cref="IDevicePerformanceControl.CpuLevel"/>.
  109. /// Value in the range [<see cref="Constants.MinCpuPerformanceLevel"/>, <see cref="IDevicePerformanceControl.MaxCpuPerformanceLevel"/>] or <see cref="Constants.UnknownPerformanceLevel"/>.
  110. /// </summary>
  111. /// <value>Current CPU performance level</value>
  112. public int CurrentCpuLevel { get; set; }
  113. /// <summary>
  114. /// Current GPU performance level.
  115. /// This value updates once per frame when changes are applied to <see cref="IDevicePerformanceControl.GpuLevel"/>.
  116. /// Value in the range [<see cref="Constants.MinGpuPerformanceLevel"/>, <see cref="IDevicePerformanceControl.MaxGpuPerformanceLevel"/>] or <see cref="Constants.UnknownPerformanceLevel"/>.
  117. /// </summary>
  118. /// <value>Current GPU performance level</value>
  119. public int CurrentGpuLevel { get; set; }
  120. /// <summary>
  121. /// Current performance bottleneck which describes if the program is CPU, GPU, or `Application.targetFrameRate` bound.
  122. /// </summary>
  123. public PerformanceBottleneck PerformanceBottleneck { get; set; }
  124. /// <summary>
  125. /// CPU boosted.
  126. /// </summary>
  127. /// <value>CPU boosted</value>
  128. public bool CpuPerformanceBoost { get; set; }
  129. /// <summary>
  130. /// GPU boosted.
  131. /// </summary>
  132. /// <value>GPU boosted</value>
  133. public bool GpuPerformanceBoost { get; set; }
  134. /// <summary>
  135. /// Current CPU cluster information information. Updated at application startup.
  136. /// </summary>
  137. /// <value> CPU cluster information</value>
  138. public ClusterInfo ClusterInfo { get; set; }
  139. }
  140. /// <summary>
  141. /// FrameTiming stores timing information about CPU, GPU, and the overall frame time.
  142. /// </summary>
  143. public struct FrameTiming
  144. {
  145. /// <summary>
  146. /// The overall frame time in seconds.
  147. /// Returns `-1.0f` if no timing information is available (for example, in the first frame or directly after resume).
  148. /// </summary>
  149. /// <value>Frame time in seconds</value>
  150. public float CurrentFrameTime { get; set; }
  151. /// <summary>
  152. /// The overall frame time as an average over the past 100 frames (in seconds).
  153. /// Returns -1.0f if no timing information is available (for example, in the first frame or directly after resume).
  154. /// </summary>
  155. /// <value>Frame time in seconds</value>
  156. public float AverageFrameTime { get; set; }
  157. /// <summary>
  158. /// Returns the GPU time of the last completely rendered frame (in seconds).
  159. /// Returns `-1.0f` if no timing information is available.
  160. /// The GPU time only includes the time the GPU spent on rendering a frame (for example, in the first frame or directly after resume).
  161. /// </summary>
  162. /// <value>Frame time in seconds</value>
  163. public float CurrentGpuFrameTime { get; set; }
  164. /// <summary>
  165. /// Returns the overall frame time as an average over the past 100 frames (in seconds).
  166. /// Returns `-1.0f` if no timing information is available.
  167. /// The GPU time only includes the time the GPU spent on rendering a frame (for example, in the first frame or directly after resume).
  168. /// </summary>
  169. /// <value>Frame time value in seconds</value>
  170. public float AverageGpuFrameTime { get; set; }
  171. /// <summary>
  172. /// Returns the main thread CPU time of the last frame (in seconds).
  173. /// The CPU time includes only time the CPU spent executing Unity's main and/or render threads.
  174. /// Returns `-1.0f` if no timing information is available (for example, in the first frame or directly after resume).
  175. /// </summary>
  176. /// <value>Frame time value in seconds</value>
  177. public float CurrentCpuFrameTime { get; set; }
  178. /// <summary>
  179. /// Returns the main thread CPU time as an average over the past 100 frames (in seconds).
  180. /// Returns `-1.0f` if this is not available (for example, in the first frame or directly after resume).
  181. /// The CPU time includes only the time the CPU spent executing Unity's main and/or render threads.
  182. /// </summary>
  183. /// <value>Frame time in seconds</value>
  184. public float AverageCpuFrameTime { get; set; }
  185. }
  186. /// <summary>
  187. /// The performance bottleneck enum describes what is currently limiting the system.
  188. /// </summary>
  189. public enum PerformanceBottleneck
  190. {
  191. /// <summary>
  192. /// Framerate bottleneck is unknown.
  193. /// </summary>
  194. Unknown,
  195. /// <summary>
  196. /// Framerate is limited by CPU processing.
  197. /// </summary>
  198. CPU,
  199. /// <summary>
  200. /// Framerate is limited by GPU processing.
  201. /// </summary>
  202. GPU,
  203. /// <summary>
  204. /// Framerate is limited by `Application.targetFrameRate`.
  205. /// In this case, you should consider lowering the application's performance requirements (see <see cref="IDevicePerformanceControl.AutomaticPerformanceControl"/>).
  206. /// </summary>
  207. TargetFrameRate
  208. }
  209. /// <summary>
  210. /// The cluster info describes the CPU Cluster setup.
  211. /// </summary>
  212. public struct ClusterInfo
  213. {
  214. /// <summary>
  215. /// Number of big cores supported by the CPU.
  216. /// </summary>
  217. public int BigCore { get; set; }
  218. /// <summary>
  219. /// Number of medium cores supported by the CPU.
  220. /// </summary>
  221. public int MediumCore { get; set; }
  222. /// <summary>
  223. /// Number of little cores supported by the CPU.
  224. /// </summary>
  225. public int LittleCore { get; set; }
  226. }
  227. }