Add pooling for timeline table row controls in profiler
This commit is contained in:
@@ -54,6 +54,7 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
private SamplesBuffer<ProfilingTools.ThreadStats[]> _events;
|
private SamplesBuffer<ProfilingTools.ThreadStats[]> _events;
|
||||||
private List<Timeline.TrackLabel> _timelineLabelsCache;
|
private List<Timeline.TrackLabel> _timelineLabelsCache;
|
||||||
private List<Timeline.Event> _timelineEventsCache;
|
private List<Timeline.Event> _timelineEventsCache;
|
||||||
|
private List<Row> _tableRowsCache;
|
||||||
private bool _showOnlyLastUpdateEvents;
|
private bool _showOnlyLastUpdateEvents;
|
||||||
|
|
||||||
public CPU()
|
public CPU()
|
||||||
@@ -193,6 +194,8 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
_timelineLabelsCache = new List<Timeline.TrackLabel>();
|
_timelineLabelsCache = new List<Timeline.TrackLabel>();
|
||||||
if (_timelineEventsCache == null)
|
if (_timelineEventsCache == null)
|
||||||
_timelineEventsCache = new List<Timeline.Event>();
|
_timelineEventsCache = new List<Timeline.Event>();
|
||||||
|
if (_tableRowsCache == null)
|
||||||
|
_tableRowsCache = new List<Row>();
|
||||||
|
|
||||||
var viewRange = GetEventsViewRange();
|
var viewRange = GetEventsViewRange();
|
||||||
UpdateTimeline(ref viewRange);
|
UpdateTimeline(ref viewRange);
|
||||||
@@ -205,6 +208,7 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
Clear();
|
Clear();
|
||||||
_timelineLabelsCache?.Clear();
|
_timelineLabelsCache?.Clear();
|
||||||
_timelineEventsCache?.Clear();
|
_timelineEventsCache?.Clear();
|
||||||
|
_tableRowsCache?.Clear();
|
||||||
|
|
||||||
base.OnDestroy();
|
base.OnDestroy();
|
||||||
}
|
}
|
||||||
@@ -424,8 +428,21 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
|
|
||||||
private void UpdateTable(ref ViewRange viewRange)
|
private void UpdateTable(ref ViewRange viewRange)
|
||||||
{
|
{
|
||||||
_table.DisposeChildren();
|
_table.IsLayoutLocked = true;
|
||||||
_table.LockChildrenRecursive();
|
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);
|
UpdateTableInner(ref viewRange);
|
||||||
|
|
||||||
@@ -480,36 +497,44 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
|
|
||||||
string name = e.Name.Replace("::", ".");
|
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
|
Values = new object[6],
|
||||||
name,
|
};
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// Event
|
||||||
|
row.Values[0] = name;
|
||||||
|
|
||||||
// Total (%)
|
// Total (%)
|
||||||
(int)(time / totalTimeMs * 1000.0f) / 10.0f,
|
row.Values[1] = (int)(time / totalTimeMs * 1000.0f) / 10.0f;
|
||||||
|
|
||||||
// Self (%)
|
// Self (%)
|
||||||
(int)((time - subEventsTimeTotal) / time * 1000.0f) / 10.0f,
|
row.Values[2] = (int)((time - subEventsTimeTotal) / time * 1000.0f) / 10.0f;
|
||||||
|
|
||||||
// Time ms
|
// Time ms
|
||||||
(float)((time * 10000.0f) / 10000.0f),
|
row.Values[3] = (float)((time * 10000.0f) / 10000.0f);
|
||||||
|
|
||||||
// Self ms
|
// Self ms
|
||||||
(float)(((time - subEventsTimeTotal) * 10000.0f) / 10000.0f),
|
row.Values[4] = (float)(((time - subEventsTimeTotal) * 10000.0f) / 10000.0f);
|
||||||
|
|
||||||
// Memory Alloc
|
// Memory Alloc
|
||||||
subEventsMemoryTotal,
|
row.Values[5] = subEventsMemoryTotal;
|
||||||
},
|
}
|
||||||
Depth = e.Depth,
|
row.Depth = e.Depth;
|
||||||
Width = _table.Width,
|
row.Width = _table.Width;
|
||||||
Parent = _table,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (i % 2 == 0)
|
|
||||||
row.BackgroundColor = rowColor2;
|
|
||||||
row.Visible = e.Depth < 3;
|
row.Visible = e.Depth < 3;
|
||||||
|
row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent;
|
||||||
|
row.Parent = _table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
private readonly Table _table;
|
private readonly Table _table;
|
||||||
private SamplesBuffer<ProfilerGPU.Event[]> _events;
|
private SamplesBuffer<ProfilerGPU.Event[]> _events;
|
||||||
private List<Timeline.Event> _timelineEventsCache;
|
private List<Timeline.Event> _timelineEventsCache;
|
||||||
|
private List<Row> _tableRowsCache;
|
||||||
|
|
||||||
public GPU()
|
public GPU()
|
||||||
: base("GPU")
|
: base("GPU")
|
||||||
@@ -147,6 +148,8 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
return;
|
return;
|
||||||
if (_timelineEventsCache == null)
|
if (_timelineEventsCache == null)
|
||||||
_timelineEventsCache = new List<Timeline.Event>();
|
_timelineEventsCache = new List<Timeline.Event>();
|
||||||
|
if (_tableRowsCache == null)
|
||||||
|
_tableRowsCache = new List<Row>();
|
||||||
|
|
||||||
UpdateTimeline();
|
UpdateTimeline();
|
||||||
UpdateTable();
|
UpdateTable();
|
||||||
@@ -157,6 +160,7 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
_timelineEventsCache?.Clear();
|
_timelineEventsCache?.Clear();
|
||||||
|
_tableRowsCache?.Clear();
|
||||||
|
|
||||||
base.OnDestroy();
|
base.OnDestroy();
|
||||||
}
|
}
|
||||||
@@ -286,8 +290,21 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
|
|
||||||
private void UpdateTable()
|
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();
|
_table.LockChildrenRecursive();
|
||||||
|
|
||||||
UpdateTableInner();
|
UpdateTableInner();
|
||||||
@@ -313,36 +330,44 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
var e = data[i];
|
var e = data[i];
|
||||||
string name = new string(e.Name);
|
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
|
Values = new object[6],
|
||||||
name,
|
};
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// Event
|
||||||
|
row.Values[0] = name;
|
||||||
|
|
||||||
// Total (%)
|
// Total (%)
|
||||||
(int)(e.Time / totalTimeMs * 1000.0f) / 10.0f,
|
row.Values[1] = (int)(e.Time / totalTimeMs * 1000.0f) / 10.0f;
|
||||||
|
|
||||||
// GPU ms
|
// GPU ms
|
||||||
(e.Time * 10000.0f) / 10000.0f,
|
row.Values[2] = (e.Time * 10000.0f) / 10000.0f;
|
||||||
|
|
||||||
// Draw Calls
|
// Draw Calls
|
||||||
e.Stats.DrawCalls,
|
row.Values[3] = e.Stats.DrawCalls;
|
||||||
|
|
||||||
// Triangles
|
// Triangles
|
||||||
e.Stats.Triangles,
|
row.Values[4] = e.Stats.Triangles;
|
||||||
|
|
||||||
// Vertices
|
// Vertices
|
||||||
e.Stats.Vertices,
|
row.Values[5] = e.Stats.Vertices;
|
||||||
},
|
}
|
||||||
Depth = e.Depth,
|
row.Depth = e.Depth;
|
||||||
Width = _table.Width,
|
row.Width = _table.Width;
|
||||||
Parent = _table,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (i % 2 == 0)
|
|
||||||
row.BackgroundColor = rowColor2;
|
|
||||||
row.Visible = e.Depth < 3;
|
row.Visible = e.Depth < 3;
|
||||||
|
row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent;
|
||||||
|
row.Parent = _table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user