Skip to content

Commit

Permalink
Add column M to PerfLog. Its values a 'm' if MonitorPerf is true
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Nov 29, 2024
1 parent ed26ad6 commit bf7fd0b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
13 changes: 10 additions & 3 deletions 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} on last ms sum ms updates last mem sum mem entities\n");
stringBuilder.Append("--------------------- -- -------- -------- -------- -------- -------- --------\n");
stringBuilder.Append($"stores: {stores,-3} E M 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 @@ -288,9 +288,16 @@ internal virtual void AppendPerfStats(StringBuilder sb, int depth)
sb.Append(group.childSystems.Count);
sb.Append(']');
}
bool monitored;
if (this is SystemGroup) {
monitored = ((SystemGroup)this).MonitorPerf;
} else {
monitored = parentGroup?.MonitorPerf ?? false;
}
var len = 30 - (sb.Length - start);
sb.Append(' ', len);
sb.Append(enabled ? " +" : " -");
sb.Append(enabled ? "+ " : "- ");
sb.Append(monitored ? "m" : " ");
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
12 changes: 6 additions & 6 deletions src/Tests-internal/ECS/Test_Systems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ public static void Test_Systems_AllSystems()
root.AppendPerfLog(sb);
var log = sb.ToString();
AreEqual(
@"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
@"stores: 0 E M last ms sum ms updates last mem sum mem entities
--------------------- --- -------- -------- -------- -------- -------- --------
Systems [1] + m -1.000 0.000 0 0 0
| Update [2] + m -1.000 0.000 0 0 0
| TestSystem1 + m -1.000 0.000 0 0 0 0
| MySystem1 - m -1.000 0.000 0 0 0
", log);

sb.Clear();
Expand Down
6 changes: 3 additions & 3 deletions src/Tests/ECS/Systems/Test_SystemGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ public static void Test_SystemGroup_Perf()

var emptyLog = perfSystem1.GetPerfLog();
AreEqual(
@"stores: 0 on last ms sum ms updates last mem sum mem entities
--------------------- -- -------- -------- -------- -------- -------- --------
PerfSystem + -1.000 0.000 0 0 0
@"stores: 0 E M last ms sum ms updates last mem sum mem entities
--------------------- --- -------- -------- -------- -------- -------- --------
PerfSystem + -1.000 0.000 0 0 0
", emptyLog);

root.Add(child1);
Expand Down
26 changes: 18 additions & 8 deletions src/Tests/ECS/Systems/Test_SystemRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,30 @@ public static void Test_SystemRoot_Add_System()
AreEqual(1, testSystem1.EntityCount);
AreSame(root, testSystem1.SystemRoot);

// MonitorPerf is disabled by default. So the 'M' column is empty
Console.WriteLine(root.GetPerfLog());
AreEqual(
@"stores: 1 E M 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());

root.SetMonitorPerf(true);
Console.WriteLine(root.GetPerfLog());
AreEqual(
@"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
@"stores: 1 E M last ms sum ms updates last mem sum mem entities
--------------------- --- -------- -------- -------- -------- -------- --------
Systems [1] + m -1.000 0.000 0 0 0
| Update [1] + m -1.000 0.000 0 0 0
| TestSystem1 + m -1.000 0.000 0 0 0 1
", root.GetPerfLog());

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

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

0 comments on commit bf7fd0b

Please sign in to comment.