mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Add ProfManager.Value guard, write first command argument as a ProfManager value in ExecuteInShell (#6400)
* Add ProfManager.Value guard, write first command argument as a ProfManager value in ExecuteInShell * Make EntitySystemManager use the new Value method
This commit is contained in:
@@ -9,6 +9,7 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Network.Messages;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Profiling;
|
||||
using Robust.Shared.Toolshed;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -22,6 +23,7 @@ namespace Robust.Server.Console
|
||||
[Dependency] private readonly IPlayerManager _players = default!;
|
||||
[Dependency] private readonly ISystemConsoleManager _systemConsole = default!;
|
||||
[Dependency] private readonly ToolshedManager _toolshed = default!;
|
||||
[Dependency] private readonly ProfManager _prof = default!;
|
||||
|
||||
public ServerConsoleHost() : base(isServer: true) {}
|
||||
|
||||
@@ -108,7 +110,8 @@ namespace Robust.Server.Console
|
||||
if (args.Count == 0)
|
||||
return;
|
||||
|
||||
string? cmdName = args[0];
|
||||
var cmdName = args[0];
|
||||
using var _ = _prof.Group(cmdName);
|
||||
|
||||
if (RegisteredCommands.TryGetValue(cmdName, out var conCmd)) // command registered
|
||||
{
|
||||
|
||||
@@ -314,9 +314,10 @@ namespace Robust.Shared.GameObjects
|
||||
try
|
||||
{
|
||||
#endif
|
||||
var sw = ProfSampler.StartNew();
|
||||
updReg.System.Update(frameTime);
|
||||
_profManager.WriteValue(updReg.System.GetType().Name, sw);
|
||||
using (_profManager.Value(updReg.System.GetType().Name))
|
||||
{
|
||||
updReg.System.Update(frameTime);
|
||||
}
|
||||
#if EXCEPTION_TOLERANCE
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -341,9 +342,10 @@ namespace Robust.Shared.GameObjects
|
||||
try
|
||||
{
|
||||
#endif
|
||||
var sw = ProfSampler.StartNew();
|
||||
system.FrameUpdate(frameTime);
|
||||
_profManager.WriteValue(system.GetType().Name, sw);
|
||||
using (_profManager.Value(system.GetType().Name))
|
||||
{
|
||||
system.FrameUpdate(frameTime);
|
||||
}
|
||||
#if EXCEPTION_TOLERANCE
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -132,6 +132,14 @@ public sealed class ProfManager
|
||||
/// <returns>The absolute position of the written log entry.</returns>
|
||||
public long WriteValue(string text, long int64) => WriteValue(text, ProfData.Int64(int64));
|
||||
|
||||
/// <summary>
|
||||
/// Make a guarded value for usage with using blocks.
|
||||
/// </summary>
|
||||
public ValueGuard Value(string text)
|
||||
{
|
||||
return new ValueGuard(this, text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write the start of a new log group.
|
||||
/// </summary>
|
||||
@@ -250,4 +258,23 @@ public sealed class ProfManager
|
||||
_mgr.WriteGroupEnd(_startIndex, _groupName, _sampler);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct ValueGuard : IDisposable
|
||||
{
|
||||
private readonly ProfManager _mgr;
|
||||
private readonly string _text;
|
||||
private readonly ProfSampler _sampler;
|
||||
|
||||
public ValueGuard(ProfManager mgr, string text)
|
||||
{
|
||||
_mgr = mgr;
|
||||
_text = text;
|
||||
_sampler = ProfSampler.StartNew();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_mgr.WriteValue(_text, _sampler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user