ProfileConfig.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 ProfileConfig ServiceCall = new ProfileConfig()
  97. {
  98. Category = "ServiceCall",
  99. };
  100. }
  101. }