1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 01:23:44 +08:00

Add debug output for skin configuration lookups

We've struggle with debugging these over the years so I think this was
worth a couple of hours of work.

Example of osu! lookups:

```log
[runtime] 2023-09-06 08:38:30 [verbose]: BeatmapSkinProvidingContainer.GetConfig(lookup: SpinnerFrequencyModulate)
[runtime] 2023-09-06 08:38:30 [verbose]: |-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: LegacyBeatmapSkin{ Name: Vickeblanka - Lucky Ending (TV Size) (tears_) [Normal] } } }.GetConfig(lookup: SpinnerFrequencyModulate)
[runtime] 2023-09-06 08:38:30 [verbose]: |-RulesetSkinProvidingContainer.GetConfig(lookup: SpinnerFrequencyModulate)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: LegacySkin{ Name: Test Skin [test-skin] } } }.GetConfig(lookup: SpinnerFrequencyModulate)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-SkinTransformer{ Skin: LegacySkin{ Name: Test Skin [test-skin] } }.GetConfig(lookup: SpinnerFrequencyModulate)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-|-LegacySkin{ Name: Test Skin [test-skin] }.GetConfig(lookup: SpinnerFrequencyModulate) 🟢
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: DefaultLegacySkin{ Name: osu! "classic" (2013) } } }.GetConfig(lookup: SpinnerFrequencyModulate)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-SkinTransformer{ Skin: DefaultLegacySkin{ Name: osu! "classic" (2013) } }.GetConfig(lookup: SpinnerFrequencyModulate)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-|-DefaultLegacySkin{ Name: osu! "classic" (2013) }.GetConfig(lookup: SpinnerFrequencyModulate) 🟢
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: osu.Game.Skinning.ResourceStoreBackedSkin }.GetConfig(lookup: SpinnerFrequencyModulate)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-osu.Game.Skinning.ResourceStoreBackedSkin.GetConfig(lookup: SpinnerFrequencyModulate) 🔴
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: TrianglesSkin{ Name: osu! "triangles" (2017) } }.GetConfig(lookup: SpinnerFrequencyModulate)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-TrianglesSkin{ Name: osu! "triangles" (2017) }.GetConfig(lookup: SpinnerFrequencyModulate) 🔴
[runtime] 2023-09-06 08:38:30 [verbose]:
[runtime] 2023-09-06 08:38:30 [verbose]: BeatmapSkinProvidingContainer.GetConfig(lookup: ScorePrefix)
[runtime] 2023-09-06 08:38:30 [verbose]: |-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: LegacyBeatmapSkin{ Name: Vickeblanka - Lucky Ending (TV Size) (tears_) [Normal] } } }.GetConfig(lookup: ScorePrefix)
[runtime] 2023-09-06 08:38:30 [verbose]: |-RulesetSkinProvidingContainer.GetConfig(lookup: ScorePrefix)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: LegacySkin{ Name: Test Skin [test-skin] } } }.GetConfig(lookup: ScorePrefix)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-SkinTransformer{ Skin: LegacySkin{ Name: Test Skin [test-skin] } }.GetConfig(lookup: ScorePrefix)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-|-LegacySkin{ Name: Test Skin [test-skin] }.GetConfig(lookup: ScorePrefix) 🟢
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: DefaultLegacySkin{ Name: osu! "classic" (2013) } } }.GetConfig(lookup: ScorePrefix)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-SkinTransformer{ Skin: DefaultLegacySkin{ Name: osu! "classic" (2013) } }.GetConfig(lookup: ScorePrefix)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-|-DefaultLegacySkin{ Name: osu! "classic" (2013) }.GetConfig(lookup: ScorePrefix) 🟢
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: osu.Game.Skinning.ResourceStoreBackedSkin }.GetConfig(lookup: ScorePrefix)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-osu.Game.Skinning.ResourceStoreBackedSkin.GetConfig(lookup: ScorePrefix) 🔴
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: TrianglesSkin{ Name: osu! "triangles" (2017) } }.GetConfig(lookup: ScorePrefix)
[runtime] 2023-09-06 08:38:30 [verbose]: |-|-|-TrianglesSkin{ Name: osu! "triangles" (2017) }.GetConfig(lookup: ScorePrefix) 🔴
```

Example of osu!mania lookups:

```log
[runtime] 2023-09-06 08:28:34 [verbose]: |-RulesetSkinProvidingContainer.GetConfig(lookup: [ManiaSkinConfigurationLookup lookup:ColumnWidth col:0])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: LegacySkin{ Name: Test Skin [test-skin] } } }.GetConfig(lookup: [ManiaSkinConfigurationLookup lookup:ColumnWidth col:0])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-|-SkinTransformer{ Skin: LegacySkin{ Name: Test Skin [test-skin] } }.GetConfig(lookup: [LegacyManiaSkinConfigurationLookup lookup:ColumnWidth col:0 totalcols:4])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-|-|-LegacySkin{ Name: Test Skin [test-skin] }.GetConfig(lookup: [LegacyManiaSkinConfigurationLookup lookup:ColumnWidth col:0 totalcols:4]) 🔴
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: DefaultLegacySkin{ Name: osu! "classic" (2013) } } }.GetConfig(lookup: [ManiaSkinConfigurationLookup lookup:ColumnWidth col:0])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-|-SkinTransformer{ Skin: DefaultLegacySkin{ Name: osu! "classic" (2013) } }.GetConfig(lookup: [LegacyManiaSkinConfigurationLookup lookup:ColumnWidth col:0 totalcols:4])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-|-|-DefaultLegacySkin{ Name: osu! "classic" (2013) }.GetConfig(lookup: [LegacyManiaSkinConfigurationLookup lookup:ColumnWidth col:0 totalcols:4]) 🟢
[runtime] 2023-09-06 08:28:34 [verbose]:
[runtime] 2023-09-06 08:28:34 [verbose]: BeatmapSkinProvidingContainer.GetConfig(lookup: [ManiaSkinConfigurationLookup lookup:ColumnSpacing col:0])
[runtime] 2023-09-06 08:28:34 [verbose]: |-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: LegacyBeatmapSkin{ Name: antiPLUR - Runengon (Raveille) [Easy] } } }.GetConfig(lookup: [ManiaSkinConfigurationLookup lookup:ColumnSpacing col:0])
[runtime] 2023-09-06 08:28:34 [verbose]: |-RulesetSkinProvidingContainer.GetConfig(lookup: [ManiaSkinConfigurationLookup lookup:ColumnSpacing col:0])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: LegacySkin{ Name: Test Skin [test-skin] } } }.GetConfig(lookup: [ManiaSkinConfigurationLookup lookup:ColumnSpacing col:0])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-|-SkinTransformer{ Skin: LegacySkin{ Name: Test Skin [test-skin] } }.GetConfig(lookup: [LegacyManiaSkinConfigurationLookup lookup:ColumnSpacing col:0 totalcols:4])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-|-|-LegacySkin{ Name: Test Skin [test-skin] }.GetConfig(lookup: [LegacyManiaSkinConfigurationLookup lookup:ColumnSpacing col:0 totalcols:4]) 🔴
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-SkinProvidingContainer+DisableableSkinSource{ skin: SkinTransformer{ Skin: DefaultLegacySkin{ Name: osu! "classic" (2013) } } }.GetConfig(lookup: [ManiaSkinConfigurationLookup lookup:ColumnSpacing col:0])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-|-SkinTransformer{ Skin: DefaultLegacySkin{ Name: osu! "classic" (2013) } }.GetConfig(lookup: [LegacyManiaSkinConfigurationLookup lookup:ColumnSpacing col:0 totalcols:4])
[runtime] 2023-09-06 08:28:34 [verbose]: |-|-|-|-DefaultLegacySkin{ Name: osu! "classic" (2013) }.GetConfig(lookup: [LegacyManiaSkinConfigurationLookup lookup:ColumnSpacing col:0 totalcols:4]) 🟢
[runtime] 2023-09-06 08:28:34 [verbose]:

```
This commit is contained in:
Dean Herbert 2023-09-06 17:37:17 +09:00
parent eddb879973
commit 6c95b88589
11 changed files with 185 additions and 61 deletions

View File

@ -30,5 +30,7 @@ namespace osu.Game.Rulesets.Mania.Skinning
Lookup = lookup; Lookup = lookup;
ColumnIndex = columnIndex; ColumnIndex = columnIndex;
} }
public override string ToString() => $"[{nameof(ManiaSkinConfigurationLookup)} lookup:{Lookup} col:{ColumnIndex}]";
} }
} }

View File

@ -219,15 +219,20 @@ namespace osu.Game.Skinning
switch (global) switch (global)
{ {
case GlobalSkinColours.ComboColours: case GlobalSkinColours.ComboColours:
{
LogLookupDebug(this, lookup, LookupDebugType.Hit);
return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>?>(Configuration.ComboColours)); return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>?>(Configuration.ComboColours));
} }
}
break; break;
case SkinComboColourLookup comboColour: case SkinComboColourLookup comboColour:
LogLookupDebug(this, lookup, LookupDebugType.Hit);
return SkinUtils.As<TValue>(new Bindable<Color4>(getComboColour(Configuration, comboColour.ColourIndex))); return SkinUtils.As<TValue>(new Bindable<Color4>(getComboColour(Configuration, comboColour.ColourIndex)));
} }
LogLookupDebug(this, lookup, LookupDebugType.Miss);
return null; return null;
} }

View File

@ -72,6 +72,8 @@ namespace osu.Game.Skinning
// If it is decided that we need this due to beatmaps somehow using it, the default (1.0 specified in LegacySkinDecoder.CreateTemplateObject) // If it is decided that we need this due to beatmaps somehow using it, the default (1.0 specified in LegacySkinDecoder.CreateTemplateObject)
// needs to be removed else it will cause incorrect skin behaviours. This is due to the config lookup having no context of which skin // needs to be removed else it will cause incorrect skin behaviours. This is due to the config lookup having no context of which skin
// it should be returning the version for. // it should be returning the version for.
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Miss);
return null; return null;
} }

View File

@ -30,6 +30,8 @@ namespace osu.Game.Skinning
Lookup = lookup; Lookup = lookup;
ColumnIndex = columnIndex; ColumnIndex = columnIndex;
} }
public override string ToString() => $"[{nameof(LegacyManiaSkinConfigurationLookup)} lookup:{Lookup} col:{ColumnIndex} totalcols:{TotalColumns}]";
} }
public enum LegacyManiaSkinConfigurationLookups public enum LegacyManiaSkinConfigurationLookups

View File

@ -83,6 +83,10 @@ namespace osu.Game.Skinning
} }
public override IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup) public override IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
{
bool wasHit = true;
try
{ {
switch (lookup) switch (lookup)
{ {
@ -125,8 +129,14 @@ namespace osu.Game.Skinning
return genericLookup<TLookup, TValue>(lookup); return genericLookup<TLookup, TValue>(lookup);
} }
wasHit = false;
return null; return null;
} }
finally
{
LogLookupDebug(this, lookup, wasHit ? LookupDebugType.Hit : LookupDebugType.Miss);
}
}
private IBindable<TValue>? lookupForMania<TValue>(LegacyManiaSkinConfigurationLookup maniaLookup) private IBindable<TValue>? lookupForMania<TValue>(LegacyManiaSkinConfigurationLookup maniaLookup)
{ {

View File

@ -46,7 +46,10 @@ namespace osu.Game.Skinning
public IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup) public IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
where TLookup : notnull where TLookup : notnull
where TValue : notnull where TValue : notnull
=> null; {
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Miss);
return null;
}
public void Dispose() public void Dispose()
{ {

View File

@ -6,10 +6,13 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
@ -54,6 +57,8 @@ namespace osu.Game.Skinning
private readonly RealmBackedResourceStore<SkinInfo>? realmBackedStorage; private readonly RealmBackedResourceStore<SkinInfo>? realmBackedStorage;
public string Name { get; }
/// <summary> /// <summary>
/// Construct a new skin. /// Construct a new skin.
/// </summary> /// </summary>
@ -63,6 +68,8 @@ namespace osu.Game.Skinning
/// <param name="configurationFilename">An optional filename to read the skin configuration from. If not provided, the configuration will be retrieved from the storage using "skin.ini".</param> /// <param name="configurationFilename">An optional filename to read the skin configuration from. If not provided, the configuration will be retrieved from the storage using "skin.ini".</param>
protected Skin(SkinInfo skin, IStorageResourceProvider? resources, IResourceStore<byte[]>? storage = null, string configurationFilename = @"skin.ini") protected Skin(SkinInfo skin, IStorageResourceProvider? resources, IResourceStore<byte[]>? storage = null, string configurationFilename = @"skin.ini")
{ {
Name = skin.Name;
if (resources != null) if (resources != null)
{ {
SkinInfo = skin.ToLive(resources.RealmAccess); SkinInfo = skin.ToLive(resources.RealmAccess);
@ -239,5 +246,50 @@ namespace osu.Game.Skinning
} }
#endregion #endregion
public override string ToString() => $"{GetType().ReadableName()}{{ Name: {Name} }}";
private static readonly ThreadLocal<int> nested_level = new ThreadLocal<int>(() => 0);
[Conditional("SKIN_LOOKUP_DEBUG")]
internal static void LogLookupDebug(object callingClass, object lookup, LookupDebugType type, [CallerMemberName] string callerMethod = "")
{
string icon = string.Empty;
int level = nested_level.Value;
switch (type)
{
case LookupDebugType.Hit:
icon = "🟢";
break;
case LookupDebugType.Miss:
icon = "🔴";
break;
case LookupDebugType.Enter:
nested_level.Value++;
break;
case LookupDebugType.Exit:
nested_level.Value--;
if (nested_level.Value == 0)
Logger.Log(string.Empty);
return;
}
string lookupString = lookup.ToString() ?? string.Empty;
string callingClassString = callingClass.ToString() ?? string.Empty;
Logger.Log($"{string.Join(null, Enumerable.Repeat("|-", level))}{callingClassString}.{callerMethod}(lookup: {lookupString}) {icon}");
}
internal enum LookupDebugType
{
Hit,
Miss,
Enter,
Exit
}
} }
} }

View File

@ -261,6 +261,10 @@ namespace osu.Game.Skinning
private T lookupWithFallback<T>(Func<ISkin, T> lookupFunction) private T lookupWithFallback<T>(Func<ISkin, T> lookupFunction)
where T : class where T : class
{ {
try
{
Skin.LogLookupDebug(this, lookupFunction, Skin.LookupDebugType.Enter);
foreach (var source in AllSources) foreach (var source in AllSources)
{ {
if (lookupFunction(source) is T skinSourced) if (lookupFunction(source) is T skinSourced)
@ -269,6 +273,11 @@ namespace osu.Game.Skinning
return null; return null;
} }
finally
{
Skin.LogLookupDebug(this, lookupFunction, Skin.LookupDebugType.Exit);
}
}
#region IResourceStorageProvider #region IResourceStorageProvider

View File

@ -7,6 +7,7 @@ using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
@ -161,6 +162,10 @@ namespace osu.Game.Skinning
where TLookup : notnull where TLookup : notnull
where TValue : notnull where TValue : notnull
{ {
try
{
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Enter);
foreach (var (_, lookupWrapper) in skinSources) foreach (var (_, lookupWrapper) in skinSources)
{ {
IBindable<TValue>? bindable; IBindable<TValue>? bindable;
@ -173,6 +178,11 @@ namespace osu.Game.Skinning
return ParentSource?.GetConfig<TLookup, TValue>(lookup); return ParentSource?.GetConfig<TLookup, TValue>(lookup);
} }
finally
{
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Exit);
}
}
/// <summary> /// <summary>
/// Replace the sources used for lookups in this container. /// Replace the sources used for lookups in this container.
@ -271,6 +281,10 @@ namespace osu.Game.Skinning
where TLookup : notnull where TLookup : notnull
where TValue : notnull where TValue : notnull
{ {
try
{
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Enter);
switch (lookup) switch (lookup)
{ {
case GlobalSkinColours: case GlobalSkinColours:
@ -290,6 +304,13 @@ namespace osu.Game.Skinning
return null; return null;
} }
finally
{
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Exit);
}
}
public override string ToString() => $"{GetType().ReadableName()}{{ skin: {skin} }}";
} }
} }
} }

View File

@ -34,6 +34,19 @@ namespace osu.Game.Skinning
public virtual ISample? GetSample(ISampleInfo sampleInfo) => Skin.GetSample(sampleInfo); public virtual ISample? GetSample(ISampleInfo sampleInfo) => Skin.GetSample(sampleInfo);
public virtual IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup) where TLookup : notnull where TValue : notnull => Skin.GetConfig<TLookup, TValue>(lookup); public virtual IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup) where TLookup : notnull where TValue : notnull
{
try
{
Skinning.Skin.LogLookupDebug(this, lookup, Skinning.Skin.LookupDebugType.Enter);
return Skin.GetConfig<TLookup, TValue>(lookup);
}
finally
{
Skinning.Skin.LogLookupDebug(this, lookup, Skinning.Skin.LookupDebugType.Exit);
}
}
public override string ToString() => $"{nameof(SkinTransformer)}{{ Skin: {Skin} }}";
} }
} }

View File

@ -190,15 +190,20 @@ namespace osu.Game.Skinning
switch (global) switch (global)
{ {
case GlobalSkinColours.ComboColours: case GlobalSkinColours.ComboColours:
{
LogLookupDebug(this, lookup, LookupDebugType.Hit);
return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>?>(Configuration.ComboColours)); return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>?>(Configuration.ComboColours));
} }
}
break; break;
case SkinComboColourLookup comboColour: case SkinComboColourLookup comboColour:
LogLookupDebug(this, lookup, LookupDebugType.Hit);
return SkinUtils.As<TValue>(new Bindable<Color4>(getComboColour(Configuration, comboColour.ColourIndex))); return SkinUtils.As<TValue>(new Bindable<Color4>(getComboColour(Configuration, comboColour.ColourIndex)));
} }
LogLookupDebug(this, lookup, LookupDebugType.Miss);
return null; return null;
} }