Another fix for network profiler to properly handle stats updating when recording is disabled
#2815
This commit is contained in:
@@ -44,7 +44,8 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
private readonly Table _tableRep;
|
private readonly Table _tableRep;
|
||||||
private List<Row> _tableRowsCache;
|
private List<Row> _tableRowsCache;
|
||||||
private SamplesBuffer<ProfilingTools.NetworkEventStat[]> _events;
|
private SamplesBuffer<ProfilingTools.NetworkEventStat[]> _events;
|
||||||
private NetworkDriverStats _prevStats;
|
private NetworkDriverStats _frameStats;
|
||||||
|
private NetworkDriverStats _prevTotalStats;
|
||||||
private List<NetworkDriverStats> _stats;
|
private List<NetworkDriverStats> _stats;
|
||||||
|
|
||||||
public Network()
|
public Network()
|
||||||
@@ -109,34 +110,41 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
_dataReceivedRateChart.Clear();
|
_dataReceivedRateChart.Clear();
|
||||||
_events?.Clear();
|
_events?.Clear();
|
||||||
_stats?.Clear();
|
_stats?.Clear();
|
||||||
_prevStats = new NetworkDriverStats();
|
_frameStats = _prevTotalStats = new NetworkDriverStats();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void UpdateStats()
|
||||||
|
{
|
||||||
|
// Gather peer stats
|
||||||
|
var peers = NetworkPeer.Peers;
|
||||||
|
var totalStats = new NetworkDriverStats();
|
||||||
|
totalStats.RTT = Time.UnscaledGameTime; // Store sample time in RTT
|
||||||
|
foreach (var peer in peers)
|
||||||
|
{
|
||||||
|
var peerStats = peer.NetworkDriver.GetStats();
|
||||||
|
totalStats.TotalDataSent += peerStats.TotalDataSent;
|
||||||
|
totalStats.TotalDataReceived += peerStats.TotalDataReceived;
|
||||||
|
}
|
||||||
|
var stats = totalStats;
|
||||||
|
stats.TotalDataSent = (uint)Mathf.Max((long)totalStats.TotalDataSent - (long)_prevTotalStats.TotalDataSent, 0);
|
||||||
|
stats.TotalDataReceived = (uint)Mathf.Max((long)totalStats.TotalDataReceived - (long)_prevTotalStats.TotalDataReceived, 0);
|
||||||
|
_frameStats = stats;
|
||||||
|
_prevTotalStats = totalStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Update(ref SharedUpdateData sharedData)
|
public override void Update(ref SharedUpdateData sharedData)
|
||||||
{
|
{
|
||||||
// Gather peer stats
|
// Add this-frame stats
|
||||||
var peers = NetworkPeer.Peers;
|
_dataSentChart.AddSample(_frameStats.TotalDataSent);
|
||||||
var thisStats = new NetworkDriverStats();
|
_dataReceivedChart.AddSample(_frameStats.TotalDataReceived);
|
||||||
thisStats.RTT = Time.UnscaledGameTime; // Store sample time in RTT
|
|
||||||
foreach (var peer in peers)
|
|
||||||
{
|
|
||||||
var peerStats = peer.NetworkDriver.GetStats();
|
|
||||||
thisStats.TotalDataSent += peerStats.TotalDataSent;
|
|
||||||
thisStats.TotalDataReceived += peerStats.TotalDataReceived;
|
|
||||||
}
|
|
||||||
var stats = thisStats;
|
|
||||||
stats.TotalDataSent = (uint)Mathf.Max((long)thisStats.TotalDataSent - (long)_prevStats.TotalDataSent, 0);
|
|
||||||
stats.TotalDataReceived = (uint)Mathf.Max((long)thisStats.TotalDataReceived - (long)_prevStats.TotalDataReceived, 0);
|
|
||||||
_dataSentChart.AddSample(stats.TotalDataSent);
|
|
||||||
_dataReceivedChart.AddSample(stats.TotalDataReceived);
|
|
||||||
_prevStats = thisStats;
|
|
||||||
if (_stats == null)
|
if (_stats == null)
|
||||||
_stats = new List<NetworkDriverStats>();
|
_stats = new List<NetworkDriverStats>();
|
||||||
_stats.Add(stats);
|
_stats.Add(_frameStats);
|
||||||
|
|
||||||
// Remove all stats older than 1 second
|
// Remove all stats older than 1 second
|
||||||
while (_stats.Count > 0 && thisStats.RTT - _stats[0].RTT >= 1.0f)
|
while (_stats.Count > 0 && _frameStats.RTT - _stats[0].RTT >= 1.0f)
|
||||||
_stats.RemoveAt(0);
|
_stats.RemoveAt(0);
|
||||||
|
|
||||||
// Calculate average data rates (from last second)
|
// Calculate average data rates (from last second)
|
||||||
|
|||||||
@@ -120,6 +120,13 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tick called before updating any modes display. Can be used to update per-frame statistics data.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void UpdateStats()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the mode view. Called after init and on selected frame changed.
|
/// Updates the mode view. Called after init and on selected frame changed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -230,6 +230,12 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnUpdate()
|
public override void OnUpdate()
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < _tabs.ChildrenCount; i++)
|
||||||
|
{
|
||||||
|
if (_tabs.Children[i] is ProfilerMode mode)
|
||||||
|
mode.UpdateStats();
|
||||||
|
}
|
||||||
|
|
||||||
if (LiveRecording)
|
if (LiveRecording)
|
||||||
{
|
{
|
||||||
FlaxEngine.Profiler.BeginEvent("ProfilerWindow.OnUpdate");
|
FlaxEngine.Profiler.BeginEvent("ProfilerWindow.OnUpdate");
|
||||||
|
|||||||
Reference in New Issue
Block a user