Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@ namespace MLAPI.Profiling
{
internal static class PerformanceDataManager
{
private static PerformanceTickData s_ProfilerData;
private static PerformanceTickData s_ProfilerData = new PerformanceTickData();
private static int s_TickId;

internal static void BeginNewTick()
{
s_TickId = Math.Max(s_TickId, 0);
s_ProfilerData = new PerformanceTickData
{
TickId = s_TickId++,
};
s_ProfilerData.Reset();
s_ProfilerData.TickId = s_TickId++;
}

internal static void Increment(string fieldName, int count = 1)
{
s_ProfilerData?.Increment(fieldName, count);
s_ProfilerData.Increment(fieldName, count);
}

internal static void AddTransportData(IReadOnlyDictionary<string, int> transportProfilerData)
{
s_ProfilerData?.AddNonDuplicateData(transportProfilerData);
s_ProfilerData.AddNonDuplicateData(transportProfilerData);
}

internal static PerformanceTickData GetData()
{
return s_ProfilerData;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ public void Increment(string fieldName, int count = 1)

public void AddNonDuplicateData(IReadOnlyDictionary<string, int> transportProfilerData)
{
var nonDuplicates = transportProfilerData.Where(entry => !m_TickData.HasData(entry.Key));
foreach (var entry in nonDuplicates)
foreach (var entry in transportProfilerData)
{
if (m_TickData.HasData(entry.Key))
{
continue;
}
Comment on lines -20 to +24
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fine now. the function name makes it clear enough

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, and also +1 as we've been talking about moving away from LINQ in the library

m_TickData.Add(entry.Key, entry.Value);
}
}
Expand All @@ -32,5 +35,10 @@ public bool HasData(string fieldName)
{
return m_TickData.HasData(fieldName);
}

public void Reset()
{
m_TickData.Clear();
}
}
}