diff --git a/src/DotRecast.Detour.Crowd/DtCrowd.cs b/src/DotRecast.Detour.Crowd/DtCrowd.cs index ac3d6b4..764e8ff 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowd.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowd.cs @@ -444,7 +444,7 @@ namespace DotRecast.Detour.Crowd private void CheckPathValidity(IList agents, float dt) { - using var timer = _telemetry.ScopedTimer("checkPathValidity"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.CheckPathValidity); foreach (DtCrowdAgent ag in agents) { @@ -553,7 +553,7 @@ namespace DotRecast.Detour.Crowd private void UpdateMoveRequest(IList agents, float dt) { - using var timer = _telemetry.ScopedTimer("updateMoveRequest"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.UpdateMoveRequest); RcSortedQueue queue = new RcSortedQueue((a1, a2) => a2.targetReplanTime.CompareTo(a1.targetReplanTime)); @@ -666,7 +666,7 @@ namespace DotRecast.Detour.Crowd } // Update requests. - using (var timer2 = _telemetry.ScopedTimer("pathQueueUpdate")) + using (var timer2 = _telemetry.ScopedTimer(DtCrowdTimerLabel.PathQueueUpdate)) { _pathQ.Update(_navMesh); } @@ -807,7 +807,7 @@ namespace DotRecast.Detour.Crowd private void UpdateTopologyOptimization(IList agents, float dt) { - using var timer = _telemetry.ScopedTimer("updateTopologyOptimization"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.UpdateTopologyOptimization); RcSortedQueue queue = new RcSortedQueue((a1, a2) => a2.topologyOptTime.CompareTo(a1.topologyOptTime)); @@ -846,7 +846,7 @@ namespace DotRecast.Detour.Crowd private void BuildProximityGrid(IList agents) { - using var timer = _telemetry.ScopedTimer("buildProximityGrid"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildProximityGrid); _grid = new DtProximityGrid(_config.maxAgentRadius * 3); @@ -860,7 +860,7 @@ namespace DotRecast.Detour.Crowd private void BuildNeighbours(IList agents) { - using var timer = _telemetry.ScopedTimer("buildNeighbours"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildNeighbours); foreach (DtCrowdAgent ag in agents) { @@ -921,7 +921,7 @@ namespace DotRecast.Detour.Crowd private void FindCorners(IList agents, DtCrowdAgentDebugInfo debug) { - using var timer = _telemetry.ScopedTimer("findCorners"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.FindCorners); DtCrowdAgent debugAgent = debug != null ? debug.agent : null; foreach (DtCrowdAgent ag in agents) @@ -969,7 +969,7 @@ namespace DotRecast.Detour.Crowd private void TriggerOffMeshConnections(IList agents) { - using var timer = _telemetry.ScopedTimer("triggerOffMeshConnections"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.TriggerOffMeshConnections); foreach (DtCrowdAgent ag in agents) { @@ -1017,7 +1017,7 @@ namespace DotRecast.Detour.Crowd private void CalculateSteering(IList agents) { - using var timer = _telemetry.ScopedTimer("calculateSteering"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.CalculateSteering); foreach (DtCrowdAgent ag in agents) { @@ -1114,7 +1114,7 @@ namespace DotRecast.Detour.Crowd private void PlanVelocity(DtCrowdAgentDebugInfo debug, IList agents) { - using var timer = _telemetry.ScopedTimer("planVelocity"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.PlanVelocity); DtCrowdAgent debugAgent = debug != null ? debug.agent : null; foreach (DtCrowdAgent ag in agents) @@ -1184,7 +1184,7 @@ namespace DotRecast.Detour.Crowd private void Integrate(float dt, IList agents) { - using var timer = _telemetry.ScopedTimer("integrate"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.Integrate); foreach (DtCrowdAgent ag in agents) { @@ -1199,7 +1199,7 @@ namespace DotRecast.Detour.Crowd private void HandleCollisions(IList agents) { - using var timer = _telemetry.ScopedTimer("handleCollisions"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.HandleCollisions); for (int iter = 0; iter < 4; ++iter) { @@ -1275,7 +1275,7 @@ namespace DotRecast.Detour.Crowd private void MoveAgents(IList agents) { - using var timer = _telemetry.ScopedTimer("moveAgents"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.MoveAgents); foreach (DtCrowdAgent ag in agents) { @@ -1301,7 +1301,7 @@ namespace DotRecast.Detour.Crowd private void UpdateOffMeshConnections(IList agents, float dt) { - using var timer = _telemetry.ScopedTimer("updateOffMeshConnections"); + using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.UpdateOffMeshConnections); foreach (DtCrowdAgent ag in agents) { diff --git a/src/DotRecast.Detour.Crowd/DtCrowdTelemetry.cs b/src/DotRecast.Detour.Crowd/DtCrowdTelemetry.cs index 53271f3..0b0c59d 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowdTelemetry.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowdTelemetry.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Reflection.Emit; using DotRecast.Core; namespace DotRecast.Detour.Crowd @@ -30,8 +31,8 @@ namespace DotRecast.Detour.Crowd private float _maxTimeToEnqueueRequest; private float _maxTimeToFindPath; - private readonly Dictionary _executionTimings = new Dictionary(); - private readonly Dictionary> _executionTimingSamples = new Dictionary>(); + private readonly Dictionary _executionTimings = new Dictionary(); + private readonly Dictionary> _executionTimingSamples = new Dictionary>(); public float MaxTimeToEnqueueRequest() { @@ -46,7 +47,7 @@ namespace DotRecast.Detour.Crowd public List ToExecutionTimings() { return _executionTimings - .Select(e => new RcTelemetryTick(e.Key, e.Value)) + .Select(e => new RcTelemetryTick(e.Key.Label, e.Value)) .OrderByDescending(x => x.Ticks) .ToList(); } @@ -67,19 +68,19 @@ namespace DotRecast.Detour.Crowd { _maxTimeToFindPath = Math.Max(_maxTimeToFindPath, time); } - - public IDisposable ScopedTimer(string name) + + public IDisposable ScopedTimer(DtCrowdTimerLabel label) { - Start(name); - return new RcAnonymousDisposable(() => Stop(name)); + Start(label); + return new RcAnonymousDisposable(() => Stop(label)); } - public void Start(string name) + public void Start(DtCrowdTimerLabel name) { _executionTimings.Add(name, RcFrequency.Ticks); } - public void Stop(string name) + public void Stop(DtCrowdTimerLabel name) { long duration = RcFrequency.Ticks - _executionTimings[name]; if (!_executionTimingSamples.TryGetValue(name, out var s)) diff --git a/src/DotRecast.Detour.Crowd/DtCrowdTimerLabel.cs b/src/DotRecast.Detour.Crowd/DtCrowdTimerLabel.cs new file mode 100644 index 0000000..f7246c1 --- /dev/null +++ b/src/DotRecast.Detour.Crowd/DtCrowdTimerLabel.cs @@ -0,0 +1,27 @@ +namespace DotRecast.Detour.Crowd +{ + public class DtCrowdTimerLabel + { + public static readonly DtCrowdTimerLabel CheckPathValidity = new DtCrowdTimerLabel(nameof(CheckPathValidity)); + public static readonly DtCrowdTimerLabel UpdateMoveRequest = new DtCrowdTimerLabel(nameof(UpdateMoveRequest)); + public static readonly DtCrowdTimerLabel PathQueueUpdate = new DtCrowdTimerLabel(nameof(PathQueueUpdate)); + public static readonly DtCrowdTimerLabel UpdateTopologyOptimization = new DtCrowdTimerLabel(nameof(UpdateTopologyOptimization)); + public static readonly DtCrowdTimerLabel BuildProximityGrid = new DtCrowdTimerLabel(nameof(BuildProximityGrid)); + public static readonly DtCrowdTimerLabel BuildNeighbours = new DtCrowdTimerLabel(nameof(BuildNeighbours)); + public static readonly DtCrowdTimerLabel FindCorners = new DtCrowdTimerLabel(nameof(FindCorners)); + public static readonly DtCrowdTimerLabel TriggerOffMeshConnections = new DtCrowdTimerLabel(nameof(TriggerOffMeshConnections)); + public static readonly DtCrowdTimerLabel CalculateSteering = new DtCrowdTimerLabel(nameof(CalculateSteering)); + public static readonly DtCrowdTimerLabel PlanVelocity = new DtCrowdTimerLabel(nameof(PlanVelocity)); + public static readonly DtCrowdTimerLabel Integrate = new DtCrowdTimerLabel(nameof(Integrate)); + public static readonly DtCrowdTimerLabel HandleCollisions = new DtCrowdTimerLabel(nameof(HandleCollisions)); + public static readonly DtCrowdTimerLabel MoveAgents = new DtCrowdTimerLabel(nameof(MoveAgents)); + public static readonly DtCrowdTimerLabel UpdateOffMeshConnections = new DtCrowdTimerLabel(nameof(UpdateOffMeshConnections)); + + public readonly string Label; + + private DtCrowdTimerLabel(string labelName) + { + Label = labelName; + } + } +} \ No newline at end of file