diff --git a/Source/Editor/Windows/Profiler/CPU.cs b/Source/Editor/Windows/Profiler/CPU.cs index e0cfef46f..5d752c0fb 100644 --- a/Source/Editor/Windows/Profiler/CPU.cs +++ b/Source/Editor/Windows/Profiler/CPU.cs @@ -54,6 +54,7 @@ namespace FlaxEditor.Windows.Profiler private SamplesBuffer _events; private List _timelineLabelsCache; private List _timelineEventsCache; + private List _tableRowsCache; private bool _showOnlyLastUpdateEvents; public CPU() @@ -193,6 +194,8 @@ namespace FlaxEditor.Windows.Profiler _timelineLabelsCache = new List(); if (_timelineEventsCache == null) _timelineEventsCache = new List(); + if (_tableRowsCache == null) + _tableRowsCache = new List(); var viewRange = GetEventsViewRange(); UpdateTimeline(ref viewRange); @@ -205,6 +208,7 @@ namespace FlaxEditor.Windows.Profiler Clear(); _timelineLabelsCache?.Clear(); _timelineEventsCache?.Clear(); + _tableRowsCache?.Clear(); base.OnDestroy(); } @@ -424,8 +428,21 @@ namespace FlaxEditor.Windows.Profiler private void UpdateTable(ref ViewRange viewRange) { - _table.DisposeChildren(); - _table.LockChildrenRecursive(); + _table.IsLayoutLocked = true; + int idx = 0; + while (_table.Children.Count > idx) + { + var child = _table.Children[idx]; + if (child is Row row) + { + _tableRowsCache.Add(row); + child.Parent = null; + } + else + { + idx++; + } + } UpdateTableInner(ref viewRange); @@ -480,36 +497,44 @@ namespace FlaxEditor.Windows.Profiler string name = e.Name.Replace("::", "."); - var row = new Row + Row row; + if (_tableRowsCache.Count != 0) { - Values = new object[] + var last = _tableRowsCache.Count - 1; + row = _tableRowsCache[last]; + _tableRowsCache.RemoveAt(last); + } + else + { + row = new Row { - // Event - name, + Values = new object[6], + }; + } + { + // Event + row.Values[0] = name; - // Total (%) - (int)(time / totalTimeMs * 1000.0f) / 10.0f, + // Total (%) + row.Values[1] = (int)(time / totalTimeMs * 1000.0f) / 10.0f; - // Self (%) - (int)((time - subEventsTimeTotal) / time * 1000.0f) / 10.0f, + // Self (%) + row.Values[2] = (int)((time - subEventsTimeTotal) / time * 1000.0f) / 10.0f; - // Time ms - (float)((time * 10000.0f) / 10000.0f), + // Time ms + row.Values[3] = (float)((time * 10000.0f) / 10000.0f); - // Self ms - (float)(((time - subEventsTimeTotal) * 10000.0f) / 10000.0f), + // Self ms + row.Values[4] = (float)(((time - subEventsTimeTotal) * 10000.0f) / 10000.0f); - // Memory Alloc - subEventsMemoryTotal, - }, - Depth = e.Depth, - Width = _table.Width, - Parent = _table, - }; - - if (i % 2 == 0) - row.BackgroundColor = rowColor2; + // Memory Alloc + row.Values[5] = subEventsMemoryTotal; + } + row.Depth = e.Depth; + row.Width = _table.Width; row.Visible = e.Depth < 3; + row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent; + row.Parent = _table; } } } diff --git a/Source/Editor/Windows/Profiler/GPU.cs b/Source/Editor/Windows/Profiler/GPU.cs index da7d04249..cc28bb545 100644 --- a/Source/Editor/Windows/Profiler/GPU.cs +++ b/Source/Editor/Windows/Profiler/GPU.cs @@ -19,6 +19,7 @@ namespace FlaxEditor.Windows.Profiler private readonly Table _table; private SamplesBuffer _events; private List _timelineEventsCache; + private List _tableRowsCache; public GPU() : base("GPU") @@ -147,6 +148,8 @@ namespace FlaxEditor.Windows.Profiler return; if (_timelineEventsCache == null) _timelineEventsCache = new List(); + if (_tableRowsCache == null) + _tableRowsCache = new List(); UpdateTimeline(); UpdateTable(); @@ -157,6 +160,7 @@ namespace FlaxEditor.Windows.Profiler { Clear(); _timelineEventsCache?.Clear(); + _tableRowsCache?.Clear(); base.OnDestroy(); } @@ -286,8 +290,21 @@ namespace FlaxEditor.Windows.Profiler private void UpdateTable() { - _table.DisposeChildren(); - + _table.IsLayoutLocked = true; + int idx = 0; + while (_table.Children.Count > idx) + { + var child = _table.Children[idx]; + if (child is Row row) + { + _tableRowsCache.Add(row); + child.Parent = null; + } + else + { + idx++; + } + } _table.LockChildrenRecursive(); UpdateTableInner(); @@ -313,36 +330,44 @@ namespace FlaxEditor.Windows.Profiler var e = data[i]; string name = new string(e.Name); - var row = new Row + Row row; + if (_tableRowsCache.Count != 0) { - Values = new object[] + var last = _tableRowsCache.Count - 1; + row = _tableRowsCache[last]; + _tableRowsCache.RemoveAt(last); + } + else + { + row = new Row { - // Event - name, + Values = new object[6], + }; + } + { + // Event + row.Values[0] = name; - // Total (%) - (int)(e.Time / totalTimeMs * 1000.0f) / 10.0f, + // Total (%) + row.Values[1] = (int)(e.Time / totalTimeMs * 1000.0f) / 10.0f; - // GPU ms - (e.Time * 10000.0f) / 10000.0f, + // GPU ms + row.Values[2] = (e.Time * 10000.0f) / 10000.0f; - // Draw Calls - e.Stats.DrawCalls, + // Draw Calls + row.Values[3] = e.Stats.DrawCalls; - // Triangles - e.Stats.Triangles, + // Triangles + row.Values[4] = e.Stats.Triangles; - // Vertices - e.Stats.Vertices, - }, - Depth = e.Depth, - Width = _table.Width, - Parent = _table, - }; - - if (i % 2 == 0) - row.BackgroundColor = rowColor2; + // Vertices + row.Values[5] = e.Stats.Vertices; + } + row.Depth = e.Depth; + row.Width = _table.Width; row.Visible = e.Depth < 3; + row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent; + row.Parent = _table; } } }