Skip to content

Commit

Permalink
Added recording of processor times. Debug window -> framerates now
Browse files Browse the repository at this point in the history
shows how long each process took.
  • Loading branch information
se5a committed Jan 26, 2019
1 parent defad85 commit 06d34d7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand Down
17 changes: 15 additions & 2 deletions Pulsar4X/Pulsar4X.ECSLib/GameLoop/ManagerSubPulse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Linq;
using System.Runtime.Serialization;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Concurrent;

namespace Pulsar4X.ECSLib
{
Expand All @@ -20,6 +22,8 @@ public class ManagerSubPulse
[JsonProperty]
private SortedDictionary<DateTime, ProcessSet> QueuedProcesses = new SortedDictionary<DateTime, ProcessSet>();

public readonly ConcurrentDictionary<Type, TimeSpan> ProcessTime = new ConcurrentDictionary<Type, TimeSpan>();

private ProcessorManager _processManager;

private EntityManager _entityManager;
Expand Down Expand Up @@ -310,16 +314,25 @@ private void ProcessToNextInterupt(DateTime nextInteruptDateTime)

foreach(var systemProcess in QueuedProcesses[nextInteruptDateTime].SystemProcessors)
{
Stopwatch sw = new Stopwatch();
sw.Start();
systemProcess.ProcessManager(_entityManager, deltaSeconds);
sw.Stop();
ProcessTime[systemProcess.GetType()] = sw.Elapsed;
AddSystemInterupt(nextInteruptDateTime + systemProcess.RunFrequency, systemProcess); //sets the next interupt for this hotloop process
}
foreach(var instanceProcessSet in QueuedProcesses[nextInteruptDateTime].InstanceProcessors)
{
foreach(var entity in instanceProcessSet.Value)
var processor = _processManager.GetInstanceProcessor(instanceProcessSet.Key);
Stopwatch sw = new Stopwatch();
sw.Start();
foreach (var entity in instanceProcessSet.Value)
{
var processor = _processManager.GetInstanceProcessor(instanceProcessSet.Key);

processor.ProcessEntity(entity, nextInteruptDateTime);
}
sw.Stop();
ProcessTime[processor.GetType()] = sw.Elapsed;
}
QueuedProcesses.Remove(nextInteruptDateTime); //once all the processes have been run for that datetime, remove it from the dictionary.
}
Expand Down
12 changes: 11 additions & 1 deletion Pulsar4X/Pulsar4X.ImGuiNetUI/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class DebugWindow :PulsarGuiWindow
{
EntityState _selectedEntityState;
Entity _selectedEntity { get { return _selectedEntityState.Entity; } }
SystemState _systemState;
float largestGFPS = 0;
int largestIndex = 0;

Expand All @@ -33,7 +34,7 @@ public class DebugWindow :PulsarGuiWindow

private DebugWindow()
{
_selectedEntityState = _state.LastClickedEntity;

}
internal static DebugWindow GetInstance()
{
Expand All @@ -45,6 +46,8 @@ internal static DebugWindow GetInstance()
instance = (DebugWindow)_state.LoadedWindows[typeof(DebugWindow)];
instance._selectedEntityState = _state.LastClickedEntity;
}
instance._selectedEntityState = _state.LastClickedEntity;
instance._systemState = _state.StarSystemStates[_state.ActiveSystem.Guid];
return instance;
}

Expand Down Expand Up @@ -159,6 +162,13 @@ internal override void Display()
//ui framerate
ImGui.PlotHistogram("Frame Rate ##FPSHistogram", ref _frameRates[0], _frameRates.Length, _frameRateIndex, _currentFPS.ToString(), 0f, 10000, new Vector2(248, 60), sizeof(float));

foreach (var item in _systemState.StarSystem.ManagerSubpulses.ProcessTime)
{
ImGui.Text(item.Key.Name);
ImGui.SameLine();
ImGui.Text(item.Value.ToString());
}

}
if (ImGui.CollapsingHeader("Entity List"))
{
Expand Down
3 changes: 1 addition & 2 deletions Pulsar4X/Pulsar4X.ImGuiNetUI/OrbitalWidgets/OrbitIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ public override void OnPhysicsUpdate()
public override void OnPhysicsUpdate()
{

Vector4 pos = BodyPositionDB.RelativePosition_AU; //TODO this is the position we should be using, since it'll be faster, however it's sometimes not the same for some reason as the slow way we're getting it below.
//Vector4 pos = OrbitProcessor.GetPosition_AU(_orbitDB, _mgr.ManagerSubpulses.SystemLocalDateTime);
Vector4 pos = BodyPositionDB.RelativePosition_AU;
_bodyRalitivePos = new PointD() { X = pos.X, Y = pos.Y };

double minDist = CalcDistance(_bodyRalitivePos, _points[_index]);
Expand Down

0 comments on commit 06d34d7

Please sign in to comment.