mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
More event sources
This commit is contained in:
@@ -47,10 +47,13 @@ internal sealed partial class MetricsManager
|
||||
// Task.Run this so it gets run on another thread pool thread.
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
MetricsEvents.Log.RequestStart();
|
||||
|
||||
var resp = ctx.Response;
|
||||
var req = ctx.Request;
|
||||
try
|
||||
{
|
||||
MetricsEvents.Log.ScrapeStart();
|
||||
|
||||
var stream = resp.OutputStream;
|
||||
// prometheus-net is a terrible library and have to do all this insanity,
|
||||
@@ -74,6 +77,8 @@ internal sealed partial class MetricsManager
|
||||
}), cancel);
|
||||
|
||||
await stream.DisposeAsync();
|
||||
|
||||
MetricsEvents.Log.ScrapeStop();
|
||||
}
|
||||
catch (ScrapeFailedException e)
|
||||
{
|
||||
@@ -97,6 +102,8 @@ internal sealed partial class MetricsManager
|
||||
finally
|
||||
{
|
||||
resp.Close();
|
||||
|
||||
MetricsEvents.Log.RequestStop();
|
||||
}
|
||||
}, CancellationToken.None);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -9,6 +10,7 @@ using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using EventSource = System.Diagnostics.Tracing.EventSource;
|
||||
|
||||
#nullable enable
|
||||
|
||||
@@ -168,6 +170,24 @@ internal sealed partial class MetricsManager : IMetricsManager, IDisposable
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
[EventSource(Name = "Robust.MetricsManager")]
|
||||
private sealed class MetricsEvents : EventSource
|
||||
{
|
||||
public static MetricsEvents Log { get; } = new();
|
||||
|
||||
[Event(1)]
|
||||
public void ScrapeStart() => WriteEvent(1);
|
||||
|
||||
[Event(2)]
|
||||
public void ScrapeStop() => WriteEvent(2);
|
||||
|
||||
[Event(3)]
|
||||
public void RequestStart() => WriteEvent(3);
|
||||
|
||||
[Event(4)]
|
||||
public void RequestStop() => WriteEvent(4);
|
||||
}
|
||||
}
|
||||
|
||||
internal interface IMetricsManager
|
||||
|
||||
@@ -19,8 +19,7 @@ internal abstract partial class SharedReplayRecordingManager
|
||||
public void WriteBatchStart(int index) => WriteEvent(3, index);
|
||||
|
||||
[Event(4)]
|
||||
public void WriteBatchStop(int index, int uncompressed, int compressed) =>
|
||||
WriteEvent(4, index, uncompressed, compressed);
|
||||
public void WriteBatchStop(int index) => WriteEvent(4, index);
|
||||
|
||||
[Event(5)]
|
||||
public void WriteQueueBlocked() => WriteEvent(5);
|
||||
|
||||
@@ -279,6 +279,8 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
|
||||
poolData,
|
||||
uncompressed.Length);
|
||||
|
||||
RecordingEventSource.Log.WriteBatchStop(batchIndex);
|
||||
|
||||
// Note: these values are ASYNCHRONOUSLY updated from the replay write thread.
|
||||
// This means reading them here won't get the most up-to-date values,
|
||||
// and we'll probably always be off-by-one.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Threading;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Exceptions;
|
||||
@@ -167,6 +168,7 @@ namespace Robust.Shared.Timing
|
||||
// announce we are falling behind
|
||||
if ((_timing.RealTime - _lastKeepUp).TotalSeconds >= 15.0)
|
||||
{
|
||||
GameLoopEventSource.Log.CannotKeepUp();
|
||||
_sawmill.Warning("MainLoop: Cannot keep up!");
|
||||
_lastKeepUp = _timing.RealTime;
|
||||
}
|
||||
@@ -174,6 +176,7 @@ namespace Robust.Shared.Timing
|
||||
|
||||
_timing.StartFrame();
|
||||
realFrameEvent = new FrameEventArgs((float)_timing.RealFrameTime.TotalSeconds);
|
||||
GameLoopEventSource.Log.InputStart();
|
||||
#if EXCEPTION_TOLERANCE
|
||||
try
|
||||
#endif
|
||||
@@ -189,6 +192,8 @@ namespace Robust.Shared.Timing
|
||||
_runtimeLog.LogException(exp, "GameLoop Input");
|
||||
}
|
||||
#endif
|
||||
GameLoopEventSource.Log.InputStop();
|
||||
|
||||
_timing.InSimulation = true;
|
||||
var tickPeriod = _timing.CalcAdjustedTickPeriod();
|
||||
|
||||
@@ -216,6 +221,8 @@ namespace Robust.Shared.Timing
|
||||
try
|
||||
{
|
||||
#endif
|
||||
GameLoopEventSource.Log.TickStart(_timing.CurTick.Value);
|
||||
|
||||
using var tickGroup = _prof.Group("Tick");
|
||||
_prof.WriteValue("Tick", ProfData.Int64(_timing.CurTick.Value));
|
||||
|
||||
@@ -232,6 +239,8 @@ namespace Robust.Shared.Timing
|
||||
{
|
||||
Tick?.Invoke(this, simFrameEvent);
|
||||
}
|
||||
|
||||
GameLoopEventSource.Log.TickStop(_timing.CurTick.Value);
|
||||
#if EXCEPTION_TOLERANCE
|
||||
}
|
||||
catch (Exception exp)
|
||||
@@ -271,6 +280,7 @@ namespace Robust.Shared.Timing
|
||||
|
||||
// update out of the simulation
|
||||
|
||||
GameLoopEventSource.Log.UpdateStart();
|
||||
#if EXCEPTION_TOLERANCE
|
||||
try
|
||||
#endif
|
||||
@@ -285,6 +295,7 @@ namespace Robust.Shared.Timing
|
||||
_runtimeLog.LogException(exp, "GameLoop Update");
|
||||
}
|
||||
#endif
|
||||
GameLoopEventSource.Log.UpdateStop();
|
||||
|
||||
// render the simulation
|
||||
#if EXCEPTION_TOLERANCE
|
||||
@@ -314,6 +325,8 @@ namespace Robust.Shared.Timing
|
||||
_prof.WriteGroupEnd(profFrameGroupStart, "Frame", profFrameSw);
|
||||
_prof.MarkIndex(profFrameStart, ProfIndexType.Frame);
|
||||
|
||||
GameLoopEventSource.Log.SleepStart();
|
||||
|
||||
// Set sleep to 1 if you want to be nice and give the rest of the timeslice up to the os scheduler.
|
||||
// Set sleep to 0 if you want to use 100% cpu, but still cooperate with the scheduler.
|
||||
// do not call sleep if you want to be 'that thread' and hog 100% cpu.
|
||||
@@ -335,6 +348,8 @@ namespace Robust.Shared.Timing
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
GameLoopEventSource.Log.SleepStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -370,4 +385,37 @@ namespace Robust.Shared.Timing
|
||||
/// </summary>
|
||||
Delay = 1,
|
||||
}
|
||||
|
||||
[EventSource(Name = "Robust.GameLoop")]
|
||||
internal sealed class GameLoopEventSource : EventSource
|
||||
{
|
||||
public static GameLoopEventSource Log { get; } = new();
|
||||
|
||||
[Event(1)]
|
||||
public void CannotKeepUp() => WriteEvent(1);
|
||||
|
||||
[Event(2)]
|
||||
public void InputStart() => WriteEvent(2);
|
||||
|
||||
[Event(3)]
|
||||
public void InputStop() => WriteEvent(3);
|
||||
|
||||
[Event(4)]
|
||||
public void TickStart(uint tick) => WriteEvent(4, tick);
|
||||
|
||||
[Event(5)]
|
||||
public void TickStop(uint tick) => WriteEvent(5, tick);
|
||||
|
||||
[Event(6)]
|
||||
public void UpdateStart() => WriteEvent(6);
|
||||
|
||||
[Event(7)]
|
||||
public void UpdateStop() => WriteEvent(7);
|
||||
|
||||
[Event(8)]
|
||||
public void SleepStart() => WriteEvent(8);
|
||||
|
||||
[Event(9)]
|
||||
public void SleepStop() => WriteEvent(9);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user