ProfileConfig.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using System;
  2. namespace Ryujinx.Profiler
  3. {
  4. public struct ProfileConfig : IEquatable<ProfileConfig>
  5. {
  6. public string Category;
  7. public string SessionGroup;
  8. public string SessionItem;
  9. public int Level;
  10. // Private cached variables
  11. private string _cachedTag;
  12. private string _cachedSession;
  13. private string _cachedSearch;
  14. // Public helpers to get config in more user friendly format,
  15. // Cached because they never change and are called often
  16. public string Search
  17. {
  18. get
  19. {
  20. if (_cachedSearch == null)
  21. {
  22. _cachedSearch = $"{Category}.{SessionGroup}.{SessionItem}";
  23. }
  24. return _cachedSearch;
  25. }
  26. }
  27. public string Tag
  28. {
  29. get
  30. {
  31. if (_cachedTag == null)
  32. _cachedTag = $"{Category}{(Session == "" ? "" : $" ({Session})")}";
  33. return _cachedTag;
  34. }
  35. }
  36. public string Session
  37. {
  38. get
  39. {
  40. if (_cachedSession == null)
  41. {
  42. if (SessionGroup != null && SessionItem != null)
  43. {
  44. _cachedSession = $"{SessionGroup}: {SessionItem}";
  45. }
  46. else if (SessionGroup != null)
  47. {
  48. _cachedSession = $"{SessionGroup}";
  49. }
  50. else if (SessionItem != null)
  51. {
  52. _cachedSession = $"---: {SessionItem}";
  53. }
  54. else
  55. {
  56. _cachedSession = "";
  57. }
  58. }
  59. return _cachedSession;
  60. }
  61. }
  62. /// <summary>
  63. /// The default comparison is far too slow for the number of comparisons needed because it doesn't know what's important to compare
  64. /// </summary>
  65. /// <param name="obj">Object to compare to</param>
  66. /// <returns></returns>
  67. public bool Equals(ProfileConfig cmpObj)
  68. {
  69. // Order here is important.
  70. // Multiple entries with the same item is considerable less likely that multiple items with the same group.
  71. // Likewise for group and category.
  72. return (cmpObj.SessionItem == SessionItem &&
  73. cmpObj.SessionGroup == SessionGroup &&
  74. cmpObj.Category == Category);
  75. }
  76. }
  77. /// <summary>
  78. /// Predefined configs to make profiling easier,
  79. /// nested so you can reference as Profiles.Category.Group.Item where item and group may be optional
  80. /// </summary>
  81. public static class Profiles
  82. {
  83. public static class CPU
  84. {
  85. public static ProfileConfig TranslateTier0 = new ProfileConfig()
  86. {
  87. Category = "CPU",
  88. SessionGroup = "TranslateTier0"
  89. };
  90. public static ProfileConfig TranslateTier1 = new ProfileConfig()
  91. {
  92. Category = "CPU",
  93. SessionGroup = "TranslateTier1"
  94. };
  95. }
  96. public static class Input
  97. {
  98. public static ProfileConfig ControllerInput = new ProfileConfig
  99. {
  100. Category = "Input",
  101. SessionGroup = "ControllerInput"
  102. };
  103. public static ProfileConfig TouchInput = new ProfileConfig
  104. {
  105. Category = "Input",
  106. SessionGroup = "TouchInput"
  107. };
  108. }
  109. public static class GPU
  110. {
  111. public static class Engine2d
  112. {
  113. public static ProfileConfig TextureCopy = new ProfileConfig()
  114. {
  115. Category = "GPU.Engine2D",
  116. SessionGroup = "TextureCopy"
  117. };
  118. }
  119. public static class Engine3d
  120. {
  121. public static ProfileConfig CallMethod = new ProfileConfig()
  122. {
  123. Category = "GPU.Engine3D",
  124. SessionGroup = "CallMethod",
  125. };
  126. public static ProfileConfig VertexEnd = new ProfileConfig()
  127. {
  128. Category = "GPU.Engine3D",
  129. SessionGroup = "VertexEnd"
  130. };
  131. public static ProfileConfig ClearBuffers = new ProfileConfig()
  132. {
  133. Category = "GPU.Engine3D",
  134. SessionGroup = "ClearBuffers"
  135. };
  136. public static ProfileConfig SetFrameBuffer = new ProfileConfig()
  137. {
  138. Category = "GPU.Engine3D",
  139. SessionGroup = "SetFrameBuffer",
  140. };
  141. public static ProfileConfig SetZeta = new ProfileConfig()
  142. {
  143. Category = "GPU.Engine3D",
  144. SessionGroup = "SetZeta"
  145. };
  146. public static ProfileConfig UploadShaders = new ProfileConfig()
  147. {
  148. Category = "GPU.Engine3D",
  149. SessionGroup = "UploadShaders"
  150. };
  151. public static ProfileConfig UploadTextures = new ProfileConfig()
  152. {
  153. Category = "GPU.Engine3D",
  154. SessionGroup = "UploadTextures"
  155. };
  156. public static ProfileConfig UploadTexture = new ProfileConfig()
  157. {
  158. Category = "GPU.Engine3D",
  159. SessionGroup = "UploadTexture"
  160. };
  161. public static ProfileConfig UploadConstBuffers = new ProfileConfig()
  162. {
  163. Category = "GPU.Engine3D",
  164. SessionGroup = "UploadConstBuffers"
  165. };
  166. public static ProfileConfig UploadVertexArrays = new ProfileConfig()
  167. {
  168. Category = "GPU.Engine3D",
  169. SessionGroup = "UploadVertexArrays"
  170. };
  171. public static ProfileConfig ConfigureState = new ProfileConfig()
  172. {
  173. Category = "GPU.Engine3D",
  174. SessionGroup = "ConfigureState"
  175. };
  176. }
  177. public static class EngineM2mf
  178. {
  179. public static ProfileConfig CallMethod = new ProfileConfig()
  180. {
  181. Category = "GPU.EngineM2mf",
  182. SessionGroup = "CallMethod",
  183. };
  184. public static ProfileConfig Execute = new ProfileConfig()
  185. {
  186. Category = "GPU.EngineM2mf",
  187. SessionGroup = "Execute",
  188. };
  189. }
  190. public static class EngineP2mf
  191. {
  192. public static ProfileConfig CallMethod = new ProfileConfig()
  193. {
  194. Category = "GPU.EngineP2mf",
  195. SessionGroup = "CallMethod",
  196. };
  197. public static ProfileConfig Execute = new ProfileConfig()
  198. {
  199. Category = "GPU.EngineP2mf",
  200. SessionGroup = "Execute",
  201. };
  202. public static ProfileConfig PushData = new ProfileConfig()
  203. {
  204. Category = "GPU.EngineP2mf",
  205. SessionGroup = "PushData",
  206. };
  207. }
  208. public static class Shader
  209. {
  210. public static ProfileConfig Decompile = new ProfileConfig()
  211. {
  212. Category = "GPU.Shader",
  213. SessionGroup = "Decompile",
  214. };
  215. }
  216. }
  217. public static ProfileConfig ServiceCall = new ProfileConfig()
  218. {
  219. Category = "ServiceCall",
  220. };
  221. }
  222. }