forked from mirror/DotRecast
add DtCrowdTimerLabel
This commit is contained in:
parent
71b68a4937
commit
74cbb2ee29
|
@ -444,7 +444,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void CheckPathValidity(IList<DtCrowdAgent> agents, float dt)
|
private void CheckPathValidity(IList<DtCrowdAgent> agents, float dt)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("checkPathValidity");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.CheckPathValidity);
|
||||||
|
|
||||||
foreach (DtCrowdAgent ag in agents)
|
foreach (DtCrowdAgent ag in agents)
|
||||||
{
|
{
|
||||||
|
@ -553,7 +553,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void UpdateMoveRequest(IList<DtCrowdAgent> agents, float dt)
|
private void UpdateMoveRequest(IList<DtCrowdAgent> agents, float dt)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("updateMoveRequest");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.UpdateMoveRequest);
|
||||||
|
|
||||||
RcSortedQueue<DtCrowdAgent> queue = new RcSortedQueue<DtCrowdAgent>((a1, a2) => a2.targetReplanTime.CompareTo(a1.targetReplanTime));
|
RcSortedQueue<DtCrowdAgent> queue = new RcSortedQueue<DtCrowdAgent>((a1, a2) => a2.targetReplanTime.CompareTo(a1.targetReplanTime));
|
||||||
|
|
||||||
|
@ -666,7 +666,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update requests.
|
// Update requests.
|
||||||
using (var timer2 = _telemetry.ScopedTimer("pathQueueUpdate"))
|
using (var timer2 = _telemetry.ScopedTimer(DtCrowdTimerLabel.PathQueueUpdate))
|
||||||
{
|
{
|
||||||
_pathQ.Update(_navMesh);
|
_pathQ.Update(_navMesh);
|
||||||
}
|
}
|
||||||
|
@ -807,7 +807,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void UpdateTopologyOptimization(IList<DtCrowdAgent> agents, float dt)
|
private void UpdateTopologyOptimization(IList<DtCrowdAgent> agents, float dt)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("updateTopologyOptimization");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.UpdateTopologyOptimization);
|
||||||
|
|
||||||
RcSortedQueue<DtCrowdAgent> queue = new RcSortedQueue<DtCrowdAgent>((a1, a2) => a2.topologyOptTime.CompareTo(a1.topologyOptTime));
|
RcSortedQueue<DtCrowdAgent> queue = new RcSortedQueue<DtCrowdAgent>((a1, a2) => a2.topologyOptTime.CompareTo(a1.topologyOptTime));
|
||||||
|
|
||||||
|
@ -846,7 +846,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void BuildProximityGrid(IList<DtCrowdAgent> agents)
|
private void BuildProximityGrid(IList<DtCrowdAgent> agents)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("buildProximityGrid");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildProximityGrid);
|
||||||
|
|
||||||
_grid = new DtProximityGrid(_config.maxAgentRadius * 3);
|
_grid = new DtProximityGrid(_config.maxAgentRadius * 3);
|
||||||
|
|
||||||
|
@ -860,7 +860,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void BuildNeighbours(IList<DtCrowdAgent> agents)
|
private void BuildNeighbours(IList<DtCrowdAgent> agents)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("buildNeighbours");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.BuildNeighbours);
|
||||||
|
|
||||||
foreach (DtCrowdAgent ag in agents)
|
foreach (DtCrowdAgent ag in agents)
|
||||||
{
|
{
|
||||||
|
@ -921,7 +921,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void FindCorners(IList<DtCrowdAgent> agents, DtCrowdAgentDebugInfo debug)
|
private void FindCorners(IList<DtCrowdAgent> agents, DtCrowdAgentDebugInfo debug)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("findCorners");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.FindCorners);
|
||||||
|
|
||||||
DtCrowdAgent debugAgent = debug != null ? debug.agent : null;
|
DtCrowdAgent debugAgent = debug != null ? debug.agent : null;
|
||||||
foreach (DtCrowdAgent ag in agents)
|
foreach (DtCrowdAgent ag in agents)
|
||||||
|
@ -969,7 +969,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void TriggerOffMeshConnections(IList<DtCrowdAgent> agents)
|
private void TriggerOffMeshConnections(IList<DtCrowdAgent> agents)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("triggerOffMeshConnections");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.TriggerOffMeshConnections);
|
||||||
|
|
||||||
foreach (DtCrowdAgent ag in agents)
|
foreach (DtCrowdAgent ag in agents)
|
||||||
{
|
{
|
||||||
|
@ -1017,7 +1017,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void CalculateSteering(IList<DtCrowdAgent> agents)
|
private void CalculateSteering(IList<DtCrowdAgent> agents)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("calculateSteering");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.CalculateSteering);
|
||||||
|
|
||||||
foreach (DtCrowdAgent ag in agents)
|
foreach (DtCrowdAgent ag in agents)
|
||||||
{
|
{
|
||||||
|
@ -1114,7 +1114,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void PlanVelocity(DtCrowdAgentDebugInfo debug, IList<DtCrowdAgent> agents)
|
private void PlanVelocity(DtCrowdAgentDebugInfo debug, IList<DtCrowdAgent> agents)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("planVelocity");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.PlanVelocity);
|
||||||
|
|
||||||
DtCrowdAgent debugAgent = debug != null ? debug.agent : null;
|
DtCrowdAgent debugAgent = debug != null ? debug.agent : null;
|
||||||
foreach (DtCrowdAgent ag in agents)
|
foreach (DtCrowdAgent ag in agents)
|
||||||
|
@ -1184,7 +1184,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void Integrate(float dt, IList<DtCrowdAgent> agents)
|
private void Integrate(float dt, IList<DtCrowdAgent> agents)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("integrate");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.Integrate);
|
||||||
|
|
||||||
foreach (DtCrowdAgent ag in agents)
|
foreach (DtCrowdAgent ag in agents)
|
||||||
{
|
{
|
||||||
|
@ -1199,7 +1199,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void HandleCollisions(IList<DtCrowdAgent> agents)
|
private void HandleCollisions(IList<DtCrowdAgent> agents)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("handleCollisions");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.HandleCollisions);
|
||||||
|
|
||||||
for (int iter = 0; iter < 4; ++iter)
|
for (int iter = 0; iter < 4; ++iter)
|
||||||
{
|
{
|
||||||
|
@ -1275,7 +1275,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void MoveAgents(IList<DtCrowdAgent> agents)
|
private void MoveAgents(IList<DtCrowdAgent> agents)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("moveAgents");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.MoveAgents);
|
||||||
|
|
||||||
foreach (DtCrowdAgent ag in agents)
|
foreach (DtCrowdAgent ag in agents)
|
||||||
{
|
{
|
||||||
|
@ -1301,7 +1301,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
private void UpdateOffMeshConnections(IList<DtCrowdAgent> agents, float dt)
|
private void UpdateOffMeshConnections(IList<DtCrowdAgent> agents, float dt)
|
||||||
{
|
{
|
||||||
using var timer = _telemetry.ScopedTimer("updateOffMeshConnections");
|
using var timer = _telemetry.ScopedTimer(DtCrowdTimerLabel.UpdateOffMeshConnections);
|
||||||
|
|
||||||
foreach (DtCrowdAgent ag in agents)
|
foreach (DtCrowdAgent ag in agents)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection.Emit;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd
|
namespace DotRecast.Detour.Crowd
|
||||||
|
@ -30,8 +31,8 @@ namespace DotRecast.Detour.Crowd
|
||||||
private float _maxTimeToEnqueueRequest;
|
private float _maxTimeToEnqueueRequest;
|
||||||
private float _maxTimeToFindPath;
|
private float _maxTimeToFindPath;
|
||||||
|
|
||||||
private readonly Dictionary<string, long> _executionTimings = new Dictionary<string, long>();
|
private readonly Dictionary<DtCrowdTimerLabel, long> _executionTimings = new Dictionary<DtCrowdTimerLabel, long>();
|
||||||
private readonly Dictionary<string, List<long>> _executionTimingSamples = new Dictionary<string, List<long>>();
|
private readonly Dictionary<DtCrowdTimerLabel, List<long>> _executionTimingSamples = new Dictionary<DtCrowdTimerLabel, List<long>>();
|
||||||
|
|
||||||
public float MaxTimeToEnqueueRequest()
|
public float MaxTimeToEnqueueRequest()
|
||||||
{
|
{
|
||||||
|
@ -46,7 +47,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
public List<RcTelemetryTick> ToExecutionTimings()
|
public List<RcTelemetryTick> ToExecutionTimings()
|
||||||
{
|
{
|
||||||
return _executionTimings
|
return _executionTimings
|
||||||
.Select(e => new RcTelemetryTick(e.Key, e.Value))
|
.Select(e => new RcTelemetryTick(e.Key.Label, e.Value))
|
||||||
.OrderByDescending(x => x.Ticks)
|
.OrderByDescending(x => x.Ticks)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
@ -68,18 +69,18 @@ namespace DotRecast.Detour.Crowd
|
||||||
_maxTimeToFindPath = Math.Max(_maxTimeToFindPath, time);
|
_maxTimeToFindPath = Math.Max(_maxTimeToFindPath, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDisposable ScopedTimer(string name)
|
public IDisposable ScopedTimer(DtCrowdTimerLabel label)
|
||||||
{
|
{
|
||||||
Start(name);
|
Start(label);
|
||||||
return new RcAnonymousDisposable(() => Stop(name));
|
return new RcAnonymousDisposable(() => Stop(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start(string name)
|
public void Start(DtCrowdTimerLabel name)
|
||||||
{
|
{
|
||||||
_executionTimings.Add(name, RcFrequency.Ticks);
|
_executionTimings.Add(name, RcFrequency.Ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop(string name)
|
public void Stop(DtCrowdTimerLabel name)
|
||||||
{
|
{
|
||||||
long duration = RcFrequency.Ticks - _executionTimings[name];
|
long duration = RcFrequency.Ticks - _executionTimings[name];
|
||||||
if (!_executionTimingSamples.TryGetValue(name, out var s))
|
if (!_executionTimingSamples.TryGetValue(name, out var s))
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue