mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Add command to profile entity spawning (#3404)
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#if !FULL_RELEASE
|
||||
using JetBrains.Profiler.Api;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Client.Console.Commands;
|
||||
|
||||
public sealed class ProfileEntitySpawningCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public string Command => "profileEntitySpawning";
|
||||
public string Description => "Profiles entity spawning with n entities";
|
||||
public string Help => $"Usage: {Command} | {Command} <amount> <prototype>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var amount = 1000;
|
||||
string? prototype = null;
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
if (!int.TryParse(args[0], out amount))
|
||||
{
|
||||
shell.WriteError($"First argument is not an integer: {args[0]}");
|
||||
return;
|
||||
}
|
||||
|
||||
prototype = args[1];
|
||||
|
||||
break;
|
||||
default:
|
||||
shell.WriteError(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
|
||||
MeasureProfiler.StartCollectingData();
|
||||
|
||||
for (var i = 0; i < amount; i++)
|
||||
{
|
||||
_entities.SpawnEntity(prototype, MapCoordinates.Nullspace);
|
||||
}
|
||||
|
||||
MeasureProfiler.SaveData();
|
||||
|
||||
shell.WriteLine($"Client: Profiled spawning {amount} entities in {stopwatch.Elapsed.TotalMilliseconds:N3} ms");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -25,6 +25,7 @@
|
||||
<PackageReference Include="SpaceWizards.SharpFont" Version="1.0.1" />
|
||||
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
||||
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.20348-rc2" />
|
||||
<PackageReference Condition="'$(FullRelease)' != 'True'" Include="JetBrains.Profiler.Api" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(EnableClientScripting)' == 'True'">
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="4.0.1" />
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#if !FULL_RELEASE
|
||||
using JetBrains.Profiler.Api;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Server.Console.Commands;
|
||||
|
||||
public sealed class ProfileEntitySpawningCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public string Command => "profileEntitySpawning";
|
||||
public string Description => "Profiles entity spawning with n entities";
|
||||
public string Help => $"Usage: {Command} | {Command} <amount>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var amount = 1000;
|
||||
string? prototype = null;
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
if (!int.TryParse(args[0], out amount))
|
||||
{
|
||||
shell.WriteError($"First argument is not an integer: {args[0]}");
|
||||
return;
|
||||
}
|
||||
|
||||
prototype = args[1];
|
||||
|
||||
break;
|
||||
default:
|
||||
shell.WriteError(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
|
||||
MeasureProfiler.StartCollectingData();
|
||||
|
||||
for (var i = 0; i < amount; i++)
|
||||
{
|
||||
_entities.SpawnEntity(prototype, MapCoordinates.Nullspace);
|
||||
}
|
||||
|
||||
MeasureProfiler.SaveData();
|
||||
|
||||
shell.WriteLine($"Server: Profiled spawning {amount} entities in {stopwatch.Elapsed.TotalMilliseconds:N3} ms");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -20,6 +20,7 @@
|
||||
<PackageReference Include="Serilog.Sinks.Loki" Version="4.0.0-beta3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Primitives" Version="6.0.0" />
|
||||
<PackageReference Include="prometheus-net.DotNetRuntime" Version="4.2.2" />
|
||||
<PackageReference Condition="'$(FullRelease)' != 'True'" Include="JetBrains.Profiler.Api" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lidgren.Network\Lidgren.Network.csproj" />
|
||||
|
||||
Reference in New Issue
Block a user