ProfileConfig.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 GPU
  97. {
  98. public static class Engine2d
  99. {
  100. public static ProfileConfig TextureCopy = new ProfileConfig()
  101. {
  102. Category = "GPU.Engine2D",
  103. SessionGroup = "TextureCopy"
  104. };
  105. }
  106. public static class Engine3d
  107. {
  108. public static ProfileConfig CallMethod = new ProfileConfig()
  109. {
  110. Category = "GPU.Engine3D",
  111. SessionGroup = "CallMethod",
  112. };
  113. public static ProfileConfig VertexEnd = new ProfileConfig()
  114. {
  115. Category = "GPU.Engine3D",
  116. SessionGroup = "VertexEnd"
  117. };
  118. public static ProfileConfig ClearBuffers = new ProfileConfig()
  119. {
  120. Category = "GPU.Engine3D",
  121. SessionGroup = "ClearBuffers"
  122. };
  123. public static ProfileConfig SetFrameBuffer = new ProfileConfig()
  124. {
  125. Category = "GPU.Engine3D",
  126. SessionGroup = "SetFrameBuffer",
  127. };
  128. public static ProfileConfig SetZeta = new ProfileConfig()
  129. {
  130. Category = "GPU.Engine3D",
  131. SessionGroup = "SetZeta"
  132. };
  133. public static ProfileConfig UploadShaders = new ProfileConfig()
  134. {
  135. Category = "GPU.Engine3D",
  136. SessionGroup = "UploadShaders"
  137. };
  138. public static ProfileConfig UploadTextures = new ProfileConfig()
  139. {
  140. Category = "GPU.Engine3D",
  141. SessionGroup = "UploadTextures"
  142. };
  143. public static ProfileConfig UploadTexture = new ProfileConfig()
  144. {
  145. Category = "GPU.Engine3D",
  146. SessionGroup = "UploadTexture"
  147. };
  148. public static ProfileConfig UploadConstBuffers = new ProfileConfig()
  149. {
  150. Category = "GPU.Engine3D",
  151. SessionGroup = "UploadConstBuffers"
  152. };
  153. public static ProfileConfig UploadVertexArrays = new ProfileConfig()
  154. {
  155. Category = "GPU.Engine3D",
  156. SessionGroup = "UploadVertexArrays"
  157. };
  158. public static ProfileConfig ConfigureState = new ProfileConfig()
  159. {
  160. Category = "GPU.Engine3D",
  161. SessionGroup = "ConfigureState"
  162. };
  163. }
  164. public static class EngineM2mf
  165. {
  166. public static ProfileConfig CallMethod = new ProfileConfig()
  167. {
  168. Category = "GPU.EngineM2mf",
  169. SessionGroup = "CallMethod",
  170. };
  171. public static ProfileConfig Execute = new ProfileConfig()
  172. {
  173. Category = "GPU.EngineM2mf",
  174. SessionGroup = "Execute",
  175. };
  176. }
  177. public static class EngineP2mf
  178. {
  179. public static ProfileConfig CallMethod = new ProfileConfig()
  180. {
  181. Category = "GPU.EngineP2mf",
  182. SessionGroup = "CallMethod",
  183. };
  184. public static ProfileConfig Execute = new ProfileConfig()
  185. {
  186. Category = "GPU.EngineP2mf",
  187. SessionGroup = "Execute",
  188. };
  189. public static ProfileConfig PushData = new ProfileConfig()
  190. {
  191. Category = "GPU.EngineP2mf",
  192. SessionGroup = "PushData",
  193. };
  194. }
  195. public static class Shader
  196. {
  197. public static ProfileConfig Decompile = new ProfileConfig()
  198. {
  199. Category = "GPU.Shader",
  200. SessionGroup = "Decompile",
  201. };
  202. }
  203. }
  204. public static ProfileConfig ServiceCall = new ProfileConfig()
  205. {
  206. Category = "ServiceCall",
  207. };
  208. }
  209. }