Add command to dump injector cache list.

To allow me to figure out how big it is.
This commit is contained in:
Pieter-Jan Briers
2022-12-21 00:03:13 +01:00
parent ef0c0d0082
commit a0b067a062
3 changed files with 35 additions and 0 deletions

View File

@@ -529,3 +529,7 @@ cmd-vv-desc = Usage: vv <path|entity ID|guihover>
cmd-vvinvoke-desc = Invoke/Call a path with arguments using VV.
cmd-vvinvoke-desc = Usage: vvinvoke <path> [arguments...]
cmd-dump_dependency_injectors-desc = Dump IoCManager's dependency injector cache.
cmd-dump_dependency_injectors-help = Usage: dump_dependency_injectors
cmd-dump_dependency_injectors-total-count = Total count: { $total }

View File

@@ -0,0 +1,25 @@
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Robust.Shared.Console.Commands;
internal sealed class DumpDependencyInjectors : LocalizedCommands
{
[Dependency] private readonly IDependencyCollection _dependencies = default!;
public override string Command => "dump_dependency_injectors";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var deps = (DependencyCollection)_dependencies;
var types = deps.GetCachedInjectorTypes();
foreach (var type in types)
{
shell.WriteLine(type.FullName ?? "");
}
shell.WriteLine(Loc.GetString("cmd-dump_dependency_injectors-total-count", ("total", types.Length)));
}
}

View File

@@ -83,6 +83,12 @@ namespace Robust.Shared.IoC
: _services.Keys;
}
public Type[] GetCachedInjectorTypes()
{
using var _ = _injectorCacheLock.ReadGuard();
return _injectorCache.Where(kv => kv.Value.Delegate != null).Select(kv => kv.Key).ToArray();
}
/// <inheritdoc />
public bool TryResolveType<T>([NotNullWhen(true)] out T? instance)
{