Skip to content

Commit

Permalink
Engine - Systems: add on (enabled/disabled) to system perf log
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Jun 9, 2024
1 parent cbec645 commit e1e23ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
11 changes: 6 additions & 5 deletions Engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,14 @@ Console.WriteLine(root.GetPerfLog());

The log result will look like:
```js
stores: 1 last ms sum ms updates last mem sum mem entities
--------------------- -------- -------- -------- -------- -------- --------
Systems [2] 0.079 3.074 10 128 1392
| ScaleSystem 0.039 1.789 10 64 696 10000
| PositionSystem 0.039 1.278 10 64 696 10000
stores: 1 on last ms sum ms updates last mem sum mem entities
--------------------- -- -------- -------- -------- -------- -------- --------
Systems [2] + 0.076 3.322 10 128 1392
| ScaleSystem + 0.038 2.088 10 64 696 10000
| PositionSystem + 0.038 1.222 10 64 696 10000
```
```
on + enabled - disabled
last ms, sum ms last/sum system execution time in ms
updates number of executions
last mem, sum mem last/sum allocated bytes
Expand Down
5 changes: 3 additions & 2 deletions Engine/src/ECS/Systems/BaseSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ public string GetPerfLog()
/// </summary>
public void AppendPerfLog(StringBuilder stringBuilder) {
var stores = SystemRoot?.stores.count ?? 0;
stringBuilder.Append($"stores: {stores,-3} last ms sum ms updates last mem sum mem entities\n");
stringBuilder.Append("--------------------- -------- -------- -------- -------- -------- --------\n");
stringBuilder.Append($"stores: {stores,-3} on last ms sum ms updates last mem sum mem entities\n");
stringBuilder.Append("--------------------- -- -------- -------- -------- -------- -------- --------\n");
AppendPerfStats(stringBuilder, 0);
stringBuilder.Replace(',', '.'); // no more patience with NumberFormatInfo
}
Expand All @@ -290,6 +290,7 @@ internal virtual void AppendPerfStats(StringBuilder sb, int depth)
}
var len = 30 - (sb.Length - start);
sb.Append(' ', len);
sb.Append(enabled ? " +" : " -");
sb.Append($" {(double)Perf.LastMs,12:0.000}"); // (double) prevents allocation
sb.Append($" {(double)Perf.SumMs,12:0.000}");
sb.Append($" {Perf.UpdateCount,12}");
Expand Down
14 changes: 7 additions & 7 deletions Engine/src/Tests-internal/ECS/Test_Systems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static void Test_Systems_AllSystems()
{
var group = new SystemGroup("Update") {
new TestSystem1(),
new MySystem1()
new MySystem1 { Enabled = false }
};
var root = new SystemRoot("Systems") { group };
var rootSystems = root.AllSystems;
Expand All @@ -136,12 +136,12 @@ public static void Test_Systems_AllSystems()
root.AppendPerfLog(sb);
var log = sb.ToString();
AreEqual(
@"stores: 0 last ms sum ms updates last mem sum mem entities
--------------------- -------- -------- -------- -------- -------- --------
Systems [1] -1.000 0.000 0 0 0
| Update [2] -1.000 0.000 0 0 0
| TestSystem1 -1.000 0.000 0 0 0 0
| MySystem1 -1.000 0.000 0 0 0
@"stores: 0 on last ms sum ms updates last mem sum mem entities
--------------------- -- -------- -------- -------- -------- -------- --------
Systems [1] + -1.000 0.000 0 0 0
| Update [2] + -1.000 0.000 0 0 0
| TestSystem1 + -1.000 0.000 0 0 0 0
| MySystem1 - -1.000 0.000 0 0 0
", log);

sb.Clear();
Expand Down
11 changes: 6 additions & 5 deletions Engine/src/Tests/ECS/Systems/Test_SystemGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,12 @@ public static void Test_SystemGroup_GetPerfLog()
}
Console.WriteLine(root.GetPerfLog());
/*
stores: 1 last ms sum ms updates last mem sum mem entities
--------------------- -------- -------- -------- -------- -------- --------
Systems [2] 0.095 6.205 10 128 1392
| ScaleSystem 0.047 3.611 10 64 696 10000
| PositionSystem 0.048 2.031 10 64 696 10000
stores: 1 on last ms sum ms updates last mem sum mem entities
--------------------- -- -------- -------- -------- -------- -------- --------
Systems [2] + 0.073 5.534 10 128 1392
| ScaleSystem + 0.037 3.197 10 64 696 10000
| PositionSystem + 0.036 1.782 10 64 696 10000
*/
}

Expand Down
16 changes: 8 additions & 8 deletions Engine/src/Tests/ECS/Systems/Test_SystemRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public static void Test_SystemRoot_Add_System()
root.SetMonitorPerf(true);
Console.WriteLine(root.GetPerfLog());
AreEqual(
@"stores: 1 last ms sum ms updates last mem sum mem entities
--------------------- -------- -------- -------- -------- -------- --------
Systems [1] -1.000 0.000 0 0 0
| Update [1] -1.000 0.000 0 0 0
| TestSystem1 -1.000 0.000 0 0 0 1
@"stores: 1 on last ms sum ms updates last mem sum mem entities
--------------------- -- -------- -------- -------- -------- -------- --------
Systems [1] + -1.000 0.000 0 0 0
| Update [1] + -1.000 0.000 0 0 0
| TestSystem1 + -1.000 0.000 0 0 0 1
", root.GetPerfLog());

AreEqual(
@"stores: 1 last ms sum ms updates last mem sum mem entities
--------------------- -------- -------- -------- -------- -------- --------
TestSystem1 -1.000 0.000 0 0 0 1
@"stores: 1 on last ms sum ms updates last mem sum mem entities
--------------------- -- -------- -------- -------- -------- -------- --------
TestSystem1 + -1.000 0.000 0 0 0 1
", testSystem1.GetPerfLog());

var tick = new UpdateTick(42, 0);
Expand Down

0 comments on commit e1e23ab

Please sign in to comment.