설명 없음
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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. /// <summary>
  101. /// Allows you to query the latest performance mode.
  102. /// </summary>
  103. PerformanceMode PerformanceMode { get; }
  104. }
  105. /// <summary>
  106. /// PerformanceMetrics store the current bottleneck, CPU, and GPU levels
  107. /// </summary>
  108. public struct PerformanceMetrics
  109. {
  110. /// <summary>
  111. /// Current CPU performance level.
  112. /// This value updates once per frame when changes are applied to <see cref="IDevicePerformanceControl.CpuLevel"/>.
  113. /// Value in the range [<see cref="Constants.MinCpuPerformanceLevel"/>, <see cref="IDevicePerformanceControl.MaxCpuPerformanceLevel"/>] or <see cref="Constants.UnknownPerformanceLevel"/>.
  114. /// </summary>
  115. /// <value>Current CPU performance level</value>
  116. public int CurrentCpuLevel { get; set; }
  117. /// <summary>
  118. /// Current GPU performance level.
  119. /// This value updates once per frame when changes are applied to <see cref="IDevicePerformanceControl.GpuLevel"/>.
  120. /// Value in the range [<see cref="Constants.MinGpuPerformanceLevel"/>, <see cref="IDevicePerformanceControl.MaxGpuPerformanceLevel"/>] or <see cref="Constants.UnknownPerformanceLevel"/>.
  121. /// </summary>
  122. /// <value>Current GPU performance level</value>
  123. public int CurrentGpuLevel { get; set; }
  124. /// <summary>
  125. /// Current performance bottleneck which describes if the program is CPU, GPU, or `Application.targetFrameRate` bound.
  126. /// </summary>
  127. public PerformanceBottleneck PerformanceBottleneck { get; set; }
  128. /// <summary>
  129. /// CPU boosted.
  130. /// </summary>
  131. /// <value>CPU boosted</value>
  132. public bool CpuPerformanceBoost { get; set; }
  133. /// <summary>
  134. /// GPU boosted.
  135. /// </summary>
  136. /// <value>GPU boosted</value>
  137. public bool GpuPerformanceBoost { get; set; }
  138. /// <summary>
  139. /// Current CPU cluster information information. Updated at application startup.
  140. /// </summary>
  141. /// <value> CPU cluster information</value>
  142. public ClusterInfo ClusterInfo { get; set; }
  143. }
  144. /// <summary>
  145. /// FrameTiming stores timing information about CPU, GPU, and the overall frame time.
  146. /// </summary>
  147. public struct FrameTiming
  148. {
  149. /// <summary>
  150. /// The overall frame time in seconds.
  151. /// Returns `-1.0f` if no timing information is available (for example, in the first frame or directly after resume).
  152. /// </summary>
  153. /// <value>Frame time in seconds</value>
  154. public float CurrentFrameTime { get; set; }
  155. /// <summary>
  156. /// The overall frame time as an average over the past 100 frames (in seconds).
  157. /// Returns -1.0f if no timing information is available (for example, in the first frame or directly after resume).
  158. /// </summary>
  159. /// <value>Frame time in seconds</value>
  160. public float AverageFrameTime { get; set; }
  161. /// <summary>
  162. /// Returns the GPU time of the last completely rendered frame (in seconds).
  163. /// Returns `-1.0f` if no timing information is available.
  164. /// The GPU time only includes the time the GPU spent on rendering a frame (for example, in the first frame or directly after resume).
  165. /// </summary>
  166. /// <value>Frame time in seconds</value>
  167. public float CurrentGpuFrameTime { get; set; }
  168. /// <summary>
  169. /// Returns the overall frame time as an average over the past 100 frames (in seconds).
  170. /// Returns `-1.0f` if no timing information is available.
  171. /// The GPU time only includes the time the GPU spent on rendering a frame (for example, in the first frame or directly after resume).
  172. /// </summary>
  173. /// <value>Frame time value in seconds</value>
  174. public float AverageGpuFrameTime { get; set; }
  175. /// <summary>
  176. /// Returns the main thread CPU time of the last frame (in seconds).
  177. /// The CPU time includes only time the CPU spent executing Unity's main and/or render threads.
  178. /// Returns `-1.0f` if no timing information is available (for example, in the first frame or directly after resume).
  179. /// </summary>
  180. /// <value>Frame time value in seconds</value>
  181. public float CurrentCpuFrameTime { get; set; }
  182. /// <summary>
  183. /// Returns the main thread CPU time as an average over the past 100 frames (in seconds).
  184. /// Returns `-1.0f` if this is not available (for example, in the first frame or directly after resume).
  185. /// The CPU time includes only the time the CPU spent executing Unity's main and/or render threads.
  186. /// </summary>
  187. /// <value>Frame time in seconds</value>
  188. public float AverageCpuFrameTime { get; set; }
  189. }
  190. /// <summary>
  191. /// The performance mode enum describes what is currently the active performance mode of the stystem.
  192. /// </summary>
  193. public enum PerformanceMode
  194. {
  195. /// <summary>
  196. /// Performance mode is unknown.
  197. /// </summary>
  198. Unknown,
  199. /// <summary>
  200. /// Default performance mode.
  201. /// </summary>
  202. Standard,
  203. /// <summary>
  204. /// Performance mode is optimized and may be a mix of accelerating both CPU and GPU.
  205. /// </summary>
  206. Optimize,
  207. /// <summary>
  208. /// Performance mode is accelerates CPU.
  209. /// </summary>
  210. CPU,
  211. /// <summary>
  212. /// Performance mode is accelerates GPU.
  213. /// </summary>
  214. GPU,
  215. /// <summary>
  216. /// Performance is limited as mode is set to preserve battery.
  217. /// </summary>
  218. Battery
  219. }
  220. /// <summary>
  221. /// The performance bottleneck enum describes what is currently limiting the system.
  222. /// </summary>
  223. public enum PerformanceBottleneck
  224. {
  225. /// <summary>
  226. /// Framerate bottleneck is unknown.
  227. /// </summary>
  228. Unknown,
  229. /// <summary>
  230. /// Framerate is limited by CPU processing.
  231. /// </summary>
  232. CPU,
  233. /// <summary>
  234. /// Framerate is limited by GPU processing.
  235. /// </summary>
  236. GPU,
  237. /// <summary>
  238. /// Framerate is limited by `Application.targetFrameRate`.
  239. /// In this case, you should consider lowering the application's performance requirements (see <see cref="IDevicePerformanceControl.AutomaticPerformanceControl"/>).
  240. /// </summary>
  241. TargetFrameRate
  242. }
  243. /// <summary>
  244. /// The cluster info describes the CPU Cluster setup.
  245. /// </summary>
  246. public struct ClusterInfo
  247. {
  248. /// <summary>
  249. /// Number of big cores supported by the CPU.
  250. /// </summary>
  251. public int BigCore { get; set; }
  252. /// <summary>
  253. /// Number of medium cores supported by the CPU.
  254. /// </summary>
  255. public int MediumCore { get; set; }
  256. /// <summary>
  257. /// Number of little cores supported by the CPU.
  258. /// </summary>
  259. public int LittleCore { get; set; }
  260. }
  261. }