diff --git a/com.unity.netcode.gameobjects/Editor/NetcodeProfiler.cs b/com.unity.netcode.gameobjects/Editor/NetcodeProfiler.cs deleted file mode 100644 index 5273f32b13..0000000000 --- a/com.unity.netcode.gameobjects/Editor/NetcodeProfiler.cs +++ /dev/null @@ -1,421 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using UnityEditor; -using UnityEngine; - -namespace Unity.Netcode.Editor -{ - public class NetcodeProfiler : EditorWindow - { -#if !UNITY_2020_2_OR_NEWER - [MenuItem("Window/Netcode Profiler")] - public static void ShowWindow() - { - GetWindow(); - } -#endif - - private static GUIStyle s_WrapStyle - { - get - { - Color color = EditorStyles.label.normal.textColor; - GUIStyle style = EditorStyles.centeredGreyMiniLabel; - style.wordWrap = true; - style.normal.textColor = color; - return style; - } - } - - private float m_HoverAlpha = 0f; - private float m_UpdateDelay = 1f; - private int m_CaptureCount = 100; - private float m_ShowMax = 0; - private float m_ShowMin = 0; - private AnimationCurve m_Curve = AnimationCurve.Linear(0, 0, 1, 0); - private readonly List m_CurrentTicks = new List(); - private float m_LastDrawn = 0; - - private class ProfilerContainer - { - public ProfilerTick[] Ticks; - - public byte[] ToBytes() - { - var buffer = new NetworkBuffer(); - var writer = new NetworkWriter(buffer); - - writer.WriteUInt16Packed((ushort)Ticks.Length); - - for (int i = 0; i < Ticks.Length; i++) - { - Ticks[i].SerializeToStream(buffer); - } - - return buffer.ToArray(); - } - - public static ProfilerContainer FromBytes(byte[] bytes) - { - var container = new ProfilerContainer(); - var buffer = new NetworkBuffer(bytes); - var reader = new NetworkReader(buffer); - var count = reader.ReadUInt16Packed(); - - container.Ticks = new ProfilerTick[count]; - - for (int i = 0; i < count; i++) - { - container.Ticks[i] = ProfilerTick.FromStream(buffer); - } - - return container; - } - } - - private void StopRecording() - { - NetworkProfiler.Stop(); - } - - private void StartRecording() - { - if (NetworkProfiler.IsRunning) - { - StopRecording(); - } - - if (NetworkProfiler.Ticks != null && NetworkProfiler.Ticks.Count >= 2) - { - m_Curve = AnimationCurve.Constant(NetworkProfiler.Ticks.ElementAt(0).Frame, NetworkProfiler.Ticks.ElementAt(NetworkProfiler.Ticks.Count - 1).Frame, 0); - } - else - { - m_Curve = AnimationCurve.Constant(0, 1, 0); - } - - m_LastDrawn = 0; - NetworkProfiler.Start(m_CaptureCount); - } - - private void ClearDrawing() - { - m_CurrentTicks.Clear(); - m_Curve = AnimationCurve.Constant(0, 1, 0); - m_LastDrawn = 0; - } - - private void ChangeRecordState() - { - if (NetworkProfiler.IsRunning) - { - StopRecording(); - } - else - { - StartRecording(); - } - } - - private TickEvent m_EventHover = null; - private double m_LastSetup = 0; - - private void OnGUI() - { - bool recording = NetworkProfiler.IsRunning; - float deltaTime = (float)(EditorApplication.timeSinceStartup - m_LastSetup); - - m_LastSetup = EditorApplication.timeSinceStartup; - - //Draw top bar - EditorGUILayout.BeginVertical(); - EditorGUILayout.BeginHorizontal(); - - if (GUILayout.Button(recording ? "Stop" : "Capture")) - { - ChangeRecordState(); - } - - if (GUILayout.Button("Clear")) - { - ClearDrawing(); - } - - EditorGUILayout.Space(); - EditorGUILayout.Space(); - EditorGUILayout.Space(); - - if (GUILayout.Button("Import datafile")) - { - string path = EditorUtility.OpenFilePanel("Choose a NetworkProfiler file", "", ""); - if (!string.IsNullOrEmpty(path)) - { - var ticks = ProfilerContainer.FromBytes(File.ReadAllBytes(path)).Ticks; - if (ticks.Length >= 2) - { - m_Curve = AnimationCurve.Constant(ticks[0].EventId, ticks[(ticks.Length - 1)].EventId, 0); - m_ShowMax = ticks.Length; - m_ShowMin = ticks.Length - Mathf.Clamp(100, 0, ticks.Length); - } - else - { - m_Curve = AnimationCurve.Constant(0, 1, 0); - } - - m_CurrentTicks.Clear(); - for (int i = 0; i < ticks.Length; i++) - { - m_CurrentTicks.Add(ticks[i]); - - uint bytes = 0; - if (ticks[i].Events.Count > 0) - { - for (int j = 0; j < ticks[i].Events.Count; j++) - { - var tickEvent = ticks[i].Events[j]; - bytes += tickEvent.Bytes; - } - } - - m_Curve.AddKey(ticks[i].EventId, bytes); - } - } - } - - if (GUILayout.Button("Export datafile")) - { - int max = (int)m_ShowMax; - int min = (int)m_ShowMin; - int ticksInRange = max - min; - var ticks = new ProfilerTick[ticksInRange]; - for (int i = min; i < max; i++) - { - ticks[i - min] = m_CurrentTicks[i]; - } - - string path = EditorUtility.SaveFilePanel("Save NetworkProfiler data", "", "networkProfilerData", ""); - if (!string.IsNullOrEmpty(path)) - { - File.WriteAllBytes(path, new ProfilerContainer { Ticks = ticks }.ToBytes()); - } - } - - EditorGUILayout.EndHorizontal(); - float prevHis = m_CaptureCount; - m_CaptureCount = EditorGUILayout.DelayedIntField("History count", m_CaptureCount); - if (m_CaptureCount <= 0) - { - m_CaptureCount = 1; - } - - m_UpdateDelay = EditorGUILayout.Slider("Refresh delay", m_UpdateDelay, 0.1f, 10f); - EditorGUILayout.EndVertical(); - - if (prevHis != m_CaptureCount) - { - StartRecording(); - } - - //Cache - if (NetworkProfiler.IsRunning) - { - if (Time.unscaledTime - m_LastDrawn > m_UpdateDelay) - { - m_LastDrawn = Time.unscaledTime; - m_CurrentTicks.Clear(); - if (NetworkProfiler.Ticks.Count >= 2) - { - m_Curve = AnimationCurve.Constant(NetworkProfiler.Ticks.ElementAt(0).EventId, NetworkProfiler.Ticks.ElementAt(NetworkProfiler.Ticks.Count - 1).EventId, 0); - } - - for (int i = 0; i < NetworkProfiler.Ticks.Count; i++) - { - var tick = NetworkProfiler.Ticks.ElementAt(i); - m_CurrentTicks.Add(tick); - - uint bytes = 0; - if (tick.Events.Count > 0) - { - for (int j = 0; j < tick.Events.Count; j++) - { - var tickEvent = tick.Events[j]; - bytes += tickEvent.Bytes; - } - } - - m_Curve.AddKey(tick.EventId, bytes); - } - } - } - - - //Draw Animation curve and slider - m_Curve = EditorGUILayout.CurveField(m_Curve); - EditorGUILayout.MinMaxSlider(ref m_ShowMin, ref m_ShowMax, 0, m_CurrentTicks.Count); - //Verify slider values - if (m_ShowMin < 0) - { - m_ShowMin = 0; - } - - if (m_ShowMax > m_CurrentTicks.Count) - { - m_ShowMax = m_CurrentTicks.Count; - } - - if (m_ShowMin <= 0 && m_ShowMax <= 0) - { - m_ShowMin = 0; - m_ShowMax = m_CurrentTicks.Count; - } - - //Draw main board - bool hover = false; - int nonEmptyTicks = 0; - int largestTickCount = 0; - int totalTicks = ((int)m_ShowMax - (int)m_ShowMin); - - for (int i = (int)m_ShowMin; i < (int)m_ShowMax; i++) - { - if (m_CurrentTicks[i].Events.Count > 0) - { - nonEmptyTicks++; //Count non empty ticks - } - - if (m_CurrentTicks[i].Events.Count > largestTickCount) - { - largestTickCount = m_CurrentTicks[i].Events.Count; //Get how many events the tick with most events has - } - } - - int emptyTicks = totalTicks - nonEmptyTicks; - - float equalWidth = position.width / totalTicks; - float propWidth = equalWidth * 0.3f; - float widthPerTick = ((position.width - emptyTicks * propWidth) / nonEmptyTicks); - - float currentX = 0; - int emptyStreak = 0; - for (int i = (int)m_ShowMin; i < (int)m_ShowMax; i++) - { - var tick = m_CurrentTicks[i]; - if (tick.Events.Count == 0 && i != totalTicks - 1) - { - emptyStreak++; - continue; - } - - if (emptyStreak > 0 || i == totalTicks - 1) - { - var dataRect = new Rect(currentX, 140f, propWidth * emptyStreak, position.height - 140f); - currentX += propWidth * emptyStreak; - if (emptyStreak >= 2) - { - EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height), emptyStreak.ToString(), s_WrapStyle); - } - - emptyStreak = 0; - } - - if (tick.Events.Count > 0) - { - float heightPerEvent = ((position.height - 140f) - (5f * largestTickCount)) / largestTickCount; - - float currentY = 140f; - for (int j = 0; j < tick.Events.Count; j++) - { - var tickEvent = tick.Events[j]; - var dataRect = new Rect(currentX, currentY, widthPerTick, heightPerEvent); - - if (dataRect.Contains(Event.current.mousePosition)) - { - hover = true; - m_EventHover = tickEvent; - } - - EditorGUI.DrawRect(dataRect, TickTypeToColor(tickEvent.EventType, true)); - EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height / 2), tickEvent.EventType.ToString(), s_WrapStyle); - EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + dataRect.height / 2, dataRect.width, dataRect.height / 2), tickEvent.Bytes + "B", s_WrapStyle); - - currentY += heightPerEvent + 5f; - } - } - - EditorGUI.DrawRect(new Rect(currentX, 100, widthPerTick, 40), TickTypeToColor(tick.Type, false)); - EditorGUI.LabelField(new Rect(currentX, 100, widthPerTick, 20), tick.Type.ToString(), s_WrapStyle); - EditorGUI.LabelField(new Rect(currentX, 120, widthPerTick, 20), tick.Frame.ToString(), s_WrapStyle); - currentX += widthPerTick; - } - - //Calculate alpha - if (hover) - { - m_HoverAlpha += deltaTime * 10f; - - if (m_HoverAlpha > 1f) - { - m_HoverAlpha = 1f; - } - else if (m_HoverAlpha < 0f) - { - m_HoverAlpha = 0f; - } - } - else - { - m_HoverAlpha -= deltaTime * 10f; - if (m_HoverAlpha > 1f) - { - m_HoverAlpha = 1f; - } - else if (m_HoverAlpha < 0f) - { - m_HoverAlpha = 0f; - } - } - - //Draw hover thingy - if (m_EventHover != null) - { - var rect = new Rect(Event.current.mousePosition, new Vector2(500, 100)); - EditorGUI.DrawRect(rect, GetEditorColorWithAlpha(m_HoverAlpha)); - - float heightPerField = (rect.height - 5) / 4; - EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 5, rect.width, rect.height), "EventType: " + m_EventHover.EventType, GetStyleWithTextAlpha(EditorStyles.label, m_HoverAlpha)); - EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 1 + 5, rect.width, rect.height), "Size: " + m_EventHover.Bytes + "B", GetStyleWithTextAlpha(EditorStyles.label, m_HoverAlpha)); - EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 2 + 5, rect.width, rect.height), "Channel: " + m_EventHover.ChannelName, GetStyleWithTextAlpha(EditorStyles.label, m_HoverAlpha)); - EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 3 + 5, rect.width, rect.height), "MessageType: " + m_EventHover.MessageType, GetStyleWithTextAlpha(EditorStyles.label, m_HoverAlpha)); - } - - Repaint(); - } - - private Color TickTypeToColor(TickType type, bool alpha) - { - switch (type) - { - case TickType.Event: - return new Color(0.58f, 0f, 0.56f, alpha ? 0.37f : 0.7f); - case TickType.Receive: - return new Color(0f, 0.85f, 0.85f, alpha ? 0.28f : 0.7f); - case TickType.Send: - return new Color(0, 0.55f, 1f, alpha ? 0.06f : 0.7f); - default: - return Color.clear; - } - } - - private Color EditorColor => EditorGUIUtility.isProSkin ? new Color32(56, 56, 56, 255) : new Color32(194, 194, 194, 255); - - private Color GetEditorColorWithAlpha(float alpha) => EditorGUIUtility.isProSkin ? new Color(0.22f, 0.22f, 0.22f, alpha) : new Color(0.76f, 0.76f, 0.76f, alpha); - - private GUIStyle GetStyleWithTextAlpha(GUIStyle style, float alpha) - { - Color textColor = style.normal.textColor; - textColor.a = alpha; - var newStyle = new GUIStyle(style); - newStyle.normal.textColor = textColor; - return newStyle; - } - } -} diff --git a/com.unity.netcode.gameobjects/Editor/NetcodeProfiler.cs.meta b/com.unity.netcode.gameobjects/Editor/NetcodeProfiler.cs.meta deleted file mode 100644 index 4895f6e666..0000000000 --- a/com.unity.netcode.gameobjects/Editor/NetcodeProfiler.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 696c1401e8a6b80409a9a02b51cb469c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Editor/NetcodeProfilerModule.cs b/com.unity.netcode.gameobjects/Editor/NetcodeProfilerModule.cs deleted file mode 100644 index 953236656c..0000000000 --- a/com.unity.netcode.gameobjects/Editor/NetcodeProfilerModule.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections.Generic; -using Unity.Profiling; -using UnityEditor; -using UnityEngine; - -namespace Unity.Netcode.Editor -{ - [InitializeOnLoad] - internal static class NetcodeProfilerModule - { -#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER - private const string k_RpcModuleName = "Netcode RPCs"; - private const string k_OperationModuleName = "Netcode Operations"; - private const string k_MessageModuleName = "Netcode Messages"; - -#pragma warning disable IDE1006 // disable naming rule violation check - /// - /// This needs to be in synced with the internal dynamic module structure to provide our own counters - /// - [Serializable] - private class NetcodeProfilerCounter - { - // Note: These fields are named this way for internal serialization - public string m_Name; - public string m_Category; - } - - /// - /// This needs to be in synced with the internal dynamic module structure to provide our own counters - /// - [Serializable] - private class NetcodeProfilerModuleData - { - // Note: These fields are named this way for internal serialization - public List m_ChartCounters = new List(); - public List m_DetailCounters = new List(); - public string m_Name; - } - - /// - /// This needs to be in synced with the internal dynamic module structure to provide our own counters - /// - [Serializable] - private class NetcodeModules - { - // Note: These fields are named this way for internal serialization - public List m_Modules; - } -#pragma warning restore IDE1006 // restore naming rule violation check - - private static List CreateRPCCounters() => new List() - { - new NetcodeProfilerCounter { m_Name = ProfilerConstants.RpcSent, m_Category = ProfilerCategory.Network.Name }, - new NetcodeProfilerCounter { m_Name = ProfilerConstants.RpcReceived, m_Category = ProfilerCategory.Network.Name }, - }; - - private static List CreateOperationsCounters() => new List() - { - new NetcodeProfilerCounter { m_Name = ProfilerConstants.Connections, m_Category = ProfilerCategory.Network.Name }, - new NetcodeProfilerCounter { m_Name = ProfilerConstants.ReceiveTickRate, m_Category = ProfilerCategory.Network.Name }, - }; - - private static List CreateMessagesCounters() => new List() - { - new NetcodeProfilerCounter { m_Name = ProfilerConstants.NamedMessageReceived, m_Category = ProfilerCategory.Network.Name }, - new NetcodeProfilerCounter { m_Name = ProfilerConstants.UnnamedMessageReceived, m_Category = ProfilerCategory.Network.Name }, - new NetcodeProfilerCounter { m_Name = ProfilerConstants.NamedMessageSent, m_Category = ProfilerCategory.Network.Name }, - new NetcodeProfilerCounter { m_Name = ProfilerConstants.UnnamedMessageSent, m_Category = ProfilerCategory.Network.Name }, - new NetcodeProfilerCounter { m_Name = ProfilerConstants.ByteSent, m_Category = ProfilerCategory.Network.Name }, - new NetcodeProfilerCounter { m_Name = ProfilerConstants.ByteReceived, m_Category = ProfilerCategory.Network.Name }, - new NetcodeProfilerCounter { m_Name = ProfilerConstants.NetworkVarUpdates, m_Category = ProfilerCategory.Network.Name }, - new NetcodeProfilerCounter { m_Name = ProfilerConstants.NetworkVarDeltas, m_Category = ProfilerCategory.Network.Name }, - }; - - private delegate List CounterListFactoryDelegate(); - - private static bool CreateNetcodeDynamicModule(ref NetcodeModules netcodeModules, string moduleName, CounterListFactoryDelegate counterListFactoryDelegate) - { - var module = netcodeModules.m_Modules.Find(x => x.m_Name == moduleName); - if (module == null) - { - var newModule = new NetcodeProfilerModuleData - { - m_Name = moduleName, - m_ChartCounters = counterListFactoryDelegate(), - m_DetailCounters = counterListFactoryDelegate(), - }; - netcodeModules.m_Modules.Add(newModule); - - return true; - } - - return false; - } -#endif - - static NetcodeProfilerModule() - { -#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER - var dynamicModulesJson = EditorPrefs.GetString("ProfilerWindow.DynamicModules"); - var dynamicModules = JsonUtility.FromJson(dynamicModulesJson); - - if (dynamicModules != null) - { - bool wasCreated = CreateNetcodeDynamicModule(ref dynamicModules, k_RpcModuleName, CreateRPCCounters); - wasCreated |= CreateNetcodeDynamicModule(ref dynamicModules, k_OperationModuleName, CreateOperationsCounters); - wasCreated |= CreateNetcodeDynamicModule(ref dynamicModules, k_MessageModuleName, CreateMessagesCounters); - - if (wasCreated) - { - EditorPrefs.SetString("ProfilerWindow.DynamicModules", JsonUtility.ToJson(dynamicModules)); - } - } -#endif - } - } -} diff --git a/com.unity.netcode.gameobjects/Editor/NetcodeProfilerModule.cs.meta b/com.unity.netcode.gameobjects/Editor/NetcodeProfilerModule.cs.meta deleted file mode 100644 index 9fd1481bc8..0000000000 --- a/com.unity.netcode.gameobjects/Editor/NetcodeProfilerModule.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ff21a65efe3f4150b3cba2842f170d7d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs index 98824f00f5..31d4b5421d 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs @@ -666,8 +666,6 @@ internal static void HandleNetworkVariableDeltas(List networkV long readStartPos = stream.Position; networkVariableList[i].ReadDelta(stream, networkManager.IsServer); - PerformanceDataManager.Increment(ProfilerConstants.NetworkVarDeltas); - ProfilerStatManager.NetworkVarsRcvd.Record(); networkManager.NetworkMetrics.TrackNetworkVariableDeltaReceived(clientId, logInstance.NetworkObjectId, logInstance.name, networkVariableList[i].Name, stream.Length); (stream as NetworkBuffer).SkipPadBits(); @@ -753,8 +751,6 @@ internal static void HandleNetworkVariableUpdate(List networkV long readStartPos = stream.Position; networkVariableList[i].ReadField(stream); - PerformanceDataManager.Increment(ProfilerConstants.NetworkVarUpdates); - ProfilerStatManager.NetworkVarsRcvd.Record(); if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety) { diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index 6d8ce73446..950c9892d1 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -12,7 +12,7 @@ namespace Unity.Netcode /// The main component of the library /// [AddComponentMenu("Netcode/" + nameof(NetworkManager), -100)] - public class NetworkManager : MonoBehaviour, INetworkUpdateSystem, IProfilableTransportProvider + public class NetworkManager : MonoBehaviour, INetworkUpdateSystem { #pragma warning disable IDE1006 // disable naming rule violation check @@ -576,8 +576,6 @@ private void Initialize(bool server) NetworkConfig.NetworkTransport.ResetChannelCache(); NetworkConfig.NetworkTransport.Init(); - - ProfilerNotifier.Initialize(this); } /// @@ -880,9 +878,6 @@ public void Shutdown() NetworkTickSystem = null; } -#if !UNITY_2020_2_OR_NEWER - NetworkProfiler.Stop(); -#endif IsListening = false; IsServer = false; IsClient = false; @@ -938,23 +933,15 @@ public void NetworkUpdate(NetworkUpdateStage updateStage) private void OnNetworkEarlyUpdate() { - NotifyProfilerListeners(); - ProfilerBeginTick(); + NetworkMetrics.DispatchFrame(); if (IsListening) { - PerformanceDataManager.Increment(ProfilerConstants.ReceiveTickRate); - ProfilerStatManager.RcvTickRate.Record(); - #if DEVELOPMENT_BUILD || UNITY_EDITOR s_TransportPoll.Begin(); #endif var isLoopBack = false; -#if !UNITY_2020_2_OR_NEWER - NetworkProfiler.StartTick(TickType.Receive); -#endif - //If we are in loopback mode, we don't need to touch the transport if (!isLoopBack) { @@ -969,10 +956,6 @@ private void OnNetworkEarlyUpdate() } while (IsListening && networkEvent != NetworkEvent.Nothing); } -#if !UNITY_2020_2_OR_NEWER - NetworkProfiler.EndTick(); -#endif - #if DEVELOPMENT_BUILD || UNITY_EDITOR s_TransportPoll.End(); #endif @@ -1065,17 +1048,11 @@ internal IEnumerator TimeOutSwitchSceneProgress(SceneSwitchProgress switchSceneP private void HandleRawTransportPoll(NetworkEvent networkEvent, ulong clientId, NetworkChannel networkChannel, ArraySegment payload, float receiveTime) { - PerformanceDataManager.Increment(ProfilerConstants.ByteReceived, payload.Count); - ProfilerStatManager.BytesRcvd.Record(payload.Count); - switch (networkEvent) { case NetworkEvent.Connect: #if DEVELOPMENT_BUILD || UNITY_EDITOR s_TransportConnect.Begin(); -#endif -#if !UNITY_2020_2_OR_NEWER - NetworkProfiler.StartEvent(TickType.Receive, (uint)payload.Count, networkChannel, "TRANSPORT_CONNECT"); #endif if (IsServer) { @@ -1103,9 +1080,6 @@ private void HandleRawTransportPoll(NetworkEvent networkEvent, ulong clientId, N StartCoroutine(ApprovalTimeout(clientId)); } -#if !UNITY_2020_2_OR_NEWER - NetworkProfiler.EndEvent(); -#endif #if DEVELOPMENT_BUILD || UNITY_EDITOR s_TransportConnect.End(); #endif @@ -1124,9 +1098,6 @@ private void HandleRawTransportPoll(NetworkEvent networkEvent, ulong clientId, N #if DEVELOPMENT_BUILD || UNITY_EDITOR s_TransportDisconnect.Begin(); #endif -#if !UNITY_2020_2_OR_NEWER - NetworkProfiler.StartEvent(TickType.Receive, 0, NetworkChannel.Internal, "TRANSPORT_DISCONNECT"); -#endif if (NetworkLog.CurrentLogLevel <= LogLevel.Developer) { @@ -1145,9 +1116,6 @@ private void HandleRawTransportPoll(NetworkEvent networkEvent, ulong clientId, N OnClientDisconnectCallback?.Invoke(clientId); -#if !UNITY_2020_2_OR_NEWER - NetworkProfiler.EndEvent(); -#endif #if DEVELOPMENT_BUILD || UNITY_EDITOR s_TransportDisconnect.End(); #endif @@ -1186,10 +1154,6 @@ internal void HandleIncomingData(ulong clientId, NetworkChannel networkChannel, var messageType = (MessageQueueContainer.MessageType)messageStream.ReadByte(); MessageHandler.MessageReceiveQueueItem(clientId, messageStream, receiveTime, messageType, networkChannel); } - -#if !UNITY_2020_2_OR_NEWER - NetworkProfiler.EndEvent(); -#endif } #if DEVELOPMENT_BUILD || UNITY_EDITOR s_HandleIncomingData.End(); @@ -1288,8 +1252,6 @@ public void DisconnectClient(ulong clientId) if (ConnectedClientsList[i].ClientId == clientId) { ConnectedClientsList.RemoveAt(i); - PerformanceDataManager.Increment(ProfilerConstants.Connections, -1); - ProfilerStatManager.Connections.Record(-1); } } @@ -1354,8 +1316,6 @@ internal void OnClientDisconnectFromServer(ulong clientId) if (ConnectedClientsList[i].ClientId == clientId) { ConnectedClientsList.RemoveAt(i); - PerformanceDataManager.Increment(ProfilerConstants.Connections, -1); - ProfilerStatManager.Connections.Record(-1); break; } } @@ -1403,9 +1363,6 @@ internal void HandleApproval(ulong ownerClientId, bool createPlayerObject, uint? ConnectedClients.Add(ownerClientId, client); ConnectedClientsList.Add(client); - PerformanceDataManager.Increment(ProfilerConstants.Connections); - ProfilerStatManager.Connections.Record(); - if (createPlayerObject) { var networkObject = SpawnManager.CreateLocalNetworkObject(false, playerPrefabHash ?? NetworkConfig.PlayerPrefab.GetComponent().GlobalObjectIdHash, ownerClientId, null, position, rotation); @@ -1538,21 +1495,5 @@ private IInternalMessageHandler CreateMessageHandler() return messageHandler; } - - private void ProfilerBeginTick() - { - ProfilerNotifier.ProfilerBeginTick(); - } - - private void NotifyProfilerListeners() - { - ProfilerNotifier.NotifyProfilerListeners(); - NetworkMetrics.DispatchFrame(); - } - - public ITransportProfilerData Transport - { - get { return NetworkConfig.NetworkTransport as ITransportProfilerData; } - } } } diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/CustomMessageManager.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/CustomMessageManager.cs index 79b737b9b5..f8117b1d7c 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/CustomMessageManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/CustomMessageManager.cs @@ -60,7 +60,6 @@ public void SendUnnamedMessage(List clientIds, NetworkBuffer buffer, Netw } } - PerformanceDataManager.Increment(ProfilerConstants.UnnamedMessageSent); m_NetworkManager.NetworkMetrics.TrackUnnamedMessageSent(clientIds, buffer.Length); } @@ -206,13 +205,12 @@ public void SendNamedMessage(string name, ulong clientId, Stream stream, Network stream.Position = 0; stream.CopyTo(nonNullContext.NetworkWriter.GetStream()); - + var size = bufferSizeCapture.StopMeasureSegment(); m_NetworkManager.NetworkMetrics.TrackNamedMessageSent(clientId, name, size); } } - PerformanceDataManager.Increment(ProfilerConstants.NamedMessageSent); } /// @@ -259,7 +257,6 @@ public void SendNamedMessage(string name, List clientIds, Stream stream, m_NetworkManager.NetworkMetrics.TrackNamedMessageSent(clientIds, name, size); } } - PerformanceDataManager.Increment(ProfilerConstants.NamedMessageSent); } } } diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/InternalMessageHandler.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/InternalMessageHandler.cs index 9aa1c85285..92d680dc4e 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/InternalMessageHandler.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/InternalMessageHandler.cs @@ -317,29 +317,17 @@ public void MessageReceiveQueueItem(ulong clientId, Stream stream, float receive return; } - if (messageType == MessageQueueContainer.MessageType.ClientRpc || - messageType == MessageQueueContainer.MessageType.ServerRpc) - { - ProfilerStatManager.RpcsRcvd.Record(); - PerformanceDataManager.Increment(ProfilerConstants.RpcReceived); - } - var messageQueueContainer = NetworkManager.MessageQueueContainer; messageQueueContainer.AddQueueItemToInboundFrame(messageType, receiveTime, clientId, (NetworkBuffer)stream, receiveChannel); } public void HandleUnnamedMessage(ulong clientId, Stream stream) { - PerformanceDataManager.Increment(ProfilerConstants.UnnamedMessageReceived); - ProfilerStatManager.UnnamedMessage.Record(); NetworkManager.CustomMessagingManager.InvokeUnnamedMessage(clientId, stream); } public void HandleNamedMessage(ulong clientId, Stream stream) { - PerformanceDataManager.Increment(ProfilerConstants.NamedMessageReceived); - ProfilerStatManager.NamedMessage.Record(); - using (var reader = PooledNetworkReader.Get(stream)) { ulong hash = reader.ReadUInt64Packed(); diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/MessageBatcher.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/MessageBatcher.cs index 22df862b66..cc4a158561 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/MessageBatcher.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/MessageBatcher.cs @@ -152,16 +152,6 @@ public void QueueItem(in MessageFrameItem item, int automaticSendThresholdBytes, // write the message to send sendStream.Writer.WriteBytes(item.MessageData.Array, item.MessageData.Count, item.MessageData.Offset); - if (item.MessageType == MessageQueueContainer.MessageType.ClientRpc || - item.MessageType == MessageQueueContainer.MessageType.ServerRpc) - { - ProfilerStatManager.RpcsSent.Record(); - PerformanceDataManager.Increment(ProfilerConstants.RpcSent); - } - ProfilerStatManager.BytesSent.Record(item.MessageData.Count); - PerformanceDataManager.Increment(ProfilerConstants.ByteSent, item.MessageData.Count); - - if (sendStream.Buffer.Length >= automaticSendThresholdBytes) { sendCallback(clientId, sendStream); diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/MessageQueue/MessageQueueProcessor.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/MessageQueue/MessageQueueProcessor.cs index e518c1acf6..bbe86e60c6 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/MessageQueue/MessageQueueProcessor.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/MessageQueue/MessageQueueProcessor.cs @@ -330,31 +330,13 @@ private void SendFrameQueueItem(MessageFrameItem item) // TODO: Can we remove this special case for server RPCs? { m_MessageQueueContainer.NetworkManager.NetworkConfig.NetworkTransport.Send(item.NetworkId, item.MessageData, channel); - - //For each packet sent, we want to record how much data we have sent - - PerformanceDataManager.Increment(ProfilerConstants.ByteSent, (int)item.StreamSize); - PerformanceDataManager.Increment(ProfilerConstants.RpcSent); - ProfilerStatManager.BytesSent.Record((int)item.StreamSize); - ProfilerStatManager.RpcsSent.Record(); break; } - case MessageQueueContainer.MessageType.ClientRpc: - - //For each client we send to, we want to record how many messages we have sent - PerformanceDataManager.Increment(ProfilerConstants.RpcSent, item.ClientNetworkIds.Length); - ProfilerStatManager.RpcsSent.Record(item.ClientNetworkIds.Length); - // Falls through - goto default; default: { foreach (ulong clientid in item.ClientNetworkIds) { m_MessageQueueContainer.NetworkManager.NetworkConfig.NetworkTransport.Send(clientid, item.MessageData, channel); - - //For each packet sent, we want to record how much data we have sent - PerformanceDataManager.Increment(ProfilerConstants.ByteSent, (int)item.StreamSize); - ProfilerStatManager.BytesSent.Record((int)item.StreamSize); } break; diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/IProfilableTransportProvider.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/IProfilableTransportProvider.cs deleted file mode 100644 index f554875a92..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/IProfilableTransportProvider.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Unity.Netcode -{ - public interface IProfilableTransportProvider - { - ITransportProfilerData Transport { get; } - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/IProfilableTransportProvider.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/IProfilableTransportProvider.cs.meta deleted file mode 100644 index dbcd7976d2..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/IProfilableTransportProvider.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 02cc48a5664f497ca5c792b68cb15ba0 -timeCreated: 1616427501 \ No newline at end of file diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ITransportProfilerData.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ITransportProfilerData.cs deleted file mode 100644 index 76fc6d64a4..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ITransportProfilerData.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; - -namespace Unity.Netcode -{ - public interface ITransportProfilerData - { - void BeginNewTick(); - IReadOnlyDictionary GetTransportProfilerData(); - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ITransportProfilerData.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ITransportProfilerData.cs.meta deleted file mode 100644 index 79b223c14e..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ITransportProfilerData.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0c016323c9d0c4e8990d946f8f3d6ce2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/NetworkProfiler.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/NetworkProfiler.cs deleted file mode 100644 index b49de8c92e..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/NetworkProfiler.cs +++ /dev/null @@ -1,190 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -namespace Unity.Netcode -{ - /// - /// NetworkProfiler for profiling network traffic - /// - internal static class NetworkProfiler - { - /// - /// The ticks that has been recorded - /// - public static FixedQueue Ticks { get; private set; } - - /// - /// Whether or not the profiler is recording data - /// - public static bool IsRunning { get; private set; } - - private static int s_TickHistory = 1024; - private static int s_EventIdCounter = 0; - private static ProfilerTick s_CurrentTick; - - /// - /// Starts recording data for the Profiler - /// - /// The amount of ticks to keep in memory - public static void Start(int historyLength) - { - if (IsRunning) - { - return; - } - - s_EventIdCounter = 0; - Ticks = new FixedQueue(historyLength); - s_TickHistory = historyLength; - s_CurrentTick = null; - IsRunning = true; - } - - /// - /// Stops recording data - /// - public static void Stop() - { - Ticks = null; //leave to GC - s_CurrentTick = null; //leave to GC - IsRunning = false; - } - - /// - /// Stops recording data and fills the buffer with the recorded ticks and returns the length; - /// - /// The buffer to fill with the ticks - /// The number of ticks recorded - public static int Stop(ref ProfilerTick[] tickBuffer) - { - if (!IsRunning) - { - return 0; - } - - int iteration = Ticks.Count > tickBuffer.Length ? tickBuffer.Length : Ticks.Count; - for (int i = 0; i < iteration; i++) - { - tickBuffer[i] = Ticks[i]; - } - - Ticks = null; //leave to GC - s_CurrentTick = null; //leave to GC - IsRunning = false; - - return iteration; - } - - /// - /// Stops recording data and fills the buffer with the recorded ticks and returns the length; - /// - /// The buffer to fill with the ticks - /// The number of ticks recorded - public static int Stop(ref List tickBuffer) - { - if (!IsRunning) - { - return 0; - } - - int iteration = Ticks.Count > tickBuffer.Count ? tickBuffer.Count : Ticks.Count; - for (int i = 0; i < iteration; i++) - { - tickBuffer[i] = Ticks[i]; - } - - Ticks = null; //leave to GC - s_CurrentTick = null; //leave to GC - IsRunning = false; - - return iteration; - } - - internal static void StartTick(TickType type) - { - if (!IsRunning) - { - return; - } - - if (Ticks.Count == s_TickHistory) - { - Ticks.Dequeue(); - } - - var tick = new ProfilerTick() - { - Type = type, - Frame = Time.frameCount, - EventId = s_EventIdCounter - }; - s_EventIdCounter++; - Ticks.Enqueue(tick); - s_CurrentTick = tick; - } - - internal static void EndTick() - { - if (!IsRunning) - { - return; - } - - if (s_CurrentTick == null) - { - return; - } - - s_CurrentTick = null; - } - - internal static void StartEvent(TickType eventType, uint bytes, NetworkChannel networkChannel, MessageQueueContainer.MessageType messageType) - { - if (!IsRunning) - { - return; - } - - if (s_CurrentTick == null) - { - return; - } - - string messageName = messageType.ToString(); - - string channelName = networkChannel.ToString(); - s_CurrentTick.StartEvent(eventType, bytes, channelName, messageName); - } - - internal static void StartEvent(TickType eventType, uint bytes, NetworkChannel networkChannel, string messageName) - { - if (!IsRunning) - { - return; - } - - if (s_CurrentTick == null) - { - return; - } - - string channelName = networkChannel.ToString(); - s_CurrentTick.StartEvent(eventType, bytes, channelName, messageName); - } - - internal static void EndEvent() - { - if (!IsRunning) - { - return; - } - - if (s_CurrentTick == null) - { - return; - } - - s_CurrentTick.EndEvent(); - } - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/NetworkProfiler.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/NetworkProfiler.cs.meta deleted file mode 100644 index fd1f71dca5..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/NetworkProfiler.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1009676d0b4d5ea4ba2a8532b573ad32 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceDataManager.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceDataManager.cs deleted file mode 100644 index bd12f95681..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceDataManager.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Unity.Netcode -{ - internal static class PerformanceDataManager - { - private static PerformanceTickData s_ProfilerData = new PerformanceTickData(); - private static int s_TickId; - - internal static void BeginNewTick() - { - s_TickId = Math.Max(s_TickId, 0); - s_TickId++; - s_ProfilerData.Reset(); - s_ProfilerData.TickId = s_TickId; - } - - internal static void Increment(string fieldName, int count = 1) - { - s_ProfilerData.Increment(fieldName, count); - } - - internal static void AddTransportData(IReadOnlyDictionary transportProfilerData) - { - s_ProfilerData.AddNonDuplicateData(transportProfilerData); - } - - internal static PerformanceTickData GetData() - { - return s_ProfilerData; - } - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceDataManager.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceDataManager.cs.meta deleted file mode 100644 index 4029ae06e9..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceDataManager.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 09fbe4f2c41c841b0a93d9ddea3c8413 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceTickData.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceTickData.cs deleted file mode 100644 index b21e54905e..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceTickData.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections.Generic; - -namespace Unity.Netcode -{ - internal class PerformanceTickData - { - public int TickId; - - private readonly ProfilingDataStore m_TickData = new ProfilingDataStore(); - - public void Increment(string fieldName, int count = 1) - { - m_TickData.Increment(fieldName, count); - } - - public void AddNonDuplicateData(IReadOnlyDictionary transportProfilerData) - { - foreach (var entry in transportProfilerData) - { - if (m_TickData.HasData(entry.Key)) - { - continue; - } - m_TickData.Add(entry.Key, entry.Value); - } - } - - public int GetData(string fieldName) - { - return m_TickData.GetData(fieldName); - } - - public bool HasData(string fieldName) - { - return m_TickData.HasData(fieldName); - } - - public void Reset() - { - m_TickData.Clear(); - } - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceTickData.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceTickData.cs.meta deleted file mode 100644 index bf2de6a4f8..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/PerformanceTickData.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9f4b98642f26d4f599a78409be2af56e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerConstants.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerConstants.cs deleted file mode 100644 index e9fddea6e0..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerConstants.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Unity.Netcode -{ - internal static class ProfilerConstants - { - public const string Connections = nameof(Connections); - public const string ReceiveTickRate = nameof(ReceiveTickRate); - public const string NamedMessageReceived = nameof(NamedMessageReceived); - public const string UnnamedMessageReceived = nameof(UnnamedMessageReceived); - public const string NamedMessageSent = nameof(NamedMessageSent); - public const string UnnamedMessageSent = nameof(UnnamedMessageSent); - public const string ByteSent = nameof(ByteSent); - public const string ByteReceived = nameof(ByteReceived); - public const string NetworkVarDeltas = nameof(NetworkVarDeltas); - public const string NetworkVarUpdates = nameof(NetworkVarUpdates); - public const string RpcSent = nameof(RpcSent); - public const string RpcReceived = nameof(RpcReceived); - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerConstants.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerConstants.cs.meta deleted file mode 100644 index 7faafd31ac..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerConstants.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9a98852a5495e4a3aa515f0b5903847a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterUtility.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterUtility.cs deleted file mode 100644 index 734a18513d..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterUtility.cs +++ /dev/null @@ -1,35 +0,0 @@ -#if UNITY_2020_2_OR_NEWER -using System; -using Unity.Profiling.LowLevel; -#endif - -namespace Unity.Netcode -{ - internal struct ProfilerCounterUtility - { -#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER - public static byte GetProfilerMarkerDataType() - { - switch (Type.GetTypeCode(typeof(T))) - { - case TypeCode.Int32: - return (byte)ProfilerMarkerDataType.Int32; - case TypeCode.UInt32: - return (byte)ProfilerMarkerDataType.UInt32; - case TypeCode.Int64: - return (byte)ProfilerMarkerDataType.Int64; - case TypeCode.UInt64: - return (byte)ProfilerMarkerDataType.UInt64; - case TypeCode.Single: - return (byte)ProfilerMarkerDataType.Float; - case TypeCode.Double: - return (byte)ProfilerMarkerDataType.Double; - case TypeCode.String: - return (byte)ProfilerMarkerDataType.String16; - default: - throw new ArgumentException($"Type {typeof(T)} is unsupported by ProfilerCounter."); - } - } -#endif - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterUtility.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterUtility.cs.meta deleted file mode 100644 index 3ca9ed1269..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterUtility.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 07be8245ee1e14efa8eb0331bbd9e618 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterValue.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterValue.cs deleted file mode 100644 index a77b1d4bb2..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterValue.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.Runtime.InteropServices; -#if UNITY_2020_2_OR_NEWER -using System; -using System.Runtime.CompilerServices; -using Unity.Profiling; -using Unity.Profiling.LowLevel; -using Unity.Profiling.LowLevel.Unsafe; -using Unity.Collections.LowLevel.Unsafe; -#endif - -namespace Unity.Netcode -{ -#if ENABLE_PROFILER - [StructLayout(LayoutKind.Sequential)] -#else - [StructLayout(LayoutKind.Sequential, Size = 0)] -#endif - internal readonly struct ProfilerCounterValue where T : unmanaged - { -#if UNITY_2020_2_OR_NEWER -#if ENABLE_PROFILER - [NativeDisableUnsafePtrRestriction] - [NonSerialized] - private readonly unsafe T* m_Value; -#endif - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ProfilerCounterValue(ProfilerCategory category, string name, ProfilerMarkerDataUnit dataUnit, ProfilerCounterOptions counterOptions) - { -#if ENABLE_PROFILER - byte dataType = ProfilerCounterUtility.GetProfilerMarkerDataType(); - unsafe - { - m_Value = (T*)ProfilerUnsafeUtility.CreateCounterValue(out var counterPtr, name, category, MarkerFlags.Default, dataType, (byte)dataUnit, UnsafeUtility.SizeOf(), counterOptions); - } -#endif - } - - public T Value - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { -#if ENABLE_PROFILER - unsafe - { - return *m_Value; - } -#else - return default; -#endif - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { -#if ENABLE_PROFILER - unsafe - { - *m_Value = value; - } -#endif - } - } -#endif - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterValue.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterValue.cs.meta deleted file mode 100644 index a36be3530d..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCounterValue.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0ba4f4ffe57ff47f2a99db73a9871b4e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCountersInfo.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCountersInfo.cs deleted file mode 100644 index 8cee14d250..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCountersInfo.cs +++ /dev/null @@ -1,123 +0,0 @@ -#if UNITY_2020_2_OR_NEWER -using UnityEngine; -using Unity.Profiling; -#endif - -namespace Unity.Netcode -{ - internal static class ProfilerCountersInfo - { -#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER - // Operations - private static readonly ProfilerCounterValue k_ConnectionsCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.Connections, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame); - - private static readonly ProfilerCounterValue k_TickRateCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.ReceiveTickRate, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - // Messages - private static readonly ProfilerCounterValue k_NamedMessageReceivedCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.NamedMessageReceived, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - private static readonly ProfilerCounterValue k_UnnamedMessageReceivedCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.UnnamedMessageReceived, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - private static readonly ProfilerCounterValue k_NamedMessageSentCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.NamedMessageSent, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - private static readonly ProfilerCounterValue k_UnnamedMessageSentCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.UnnamedMessageSent, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - private static readonly ProfilerCounterValue k_BytesSentCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.ByteSent, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - private static readonly ProfilerCounterValue k_BytesReceivedCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.ByteReceived, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - private static readonly ProfilerCounterValue k_NetworkVarDeltasCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.NetworkVarDeltas, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - private static readonly ProfilerCounterValue k_NetworkVarUpdatesCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.NetworkVarUpdates, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - // Queue Stats - private static readonly ProfilerCounterValue k_RPCsSentCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.RpcSent, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - private static readonly ProfilerCounterValue k_RPCsReceivedCounterValue = - new ProfilerCounterValue(ProfilerCategory.Network, ProfilerConstants.RpcReceived, - ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush); - - [RuntimeInitializeOnLoadMethod] - private static void RegisterNetcodePerformanceEvent() - { - InitializeCounters(); - ProfilerNotifier.OnPerformanceDataEvent += OnPerformanceTickData; - ProfilerNotifier.OnNoTickDataEvent += OnNoTickData; - } - - private static void OnNoTickData() - { - Debug.LogWarning("There was a profiler event that was not captured in a tick"); - } - - private static void InitializeCounters() - { - k_ConnectionsCounterValue.Value = 0; - k_TickRateCounterValue.Value = 0; - - k_NamedMessageReceivedCounterValue.Value = 0; - k_UnnamedMessageReceivedCounterValue.Value = 0; - k_NamedMessageSentCounterValue.Value = 0; - k_UnnamedMessageSentCounterValue.Value = 0; - k_BytesSentCounterValue.Value = 0; - k_BytesReceivedCounterValue.Value = 0; - k_NetworkVarDeltasCounterValue.Value = 0; - k_NetworkVarUpdatesCounterValue.Value = 0; - - k_RPCsSentCounterValue.Value = 0; - k_RPCsReceivedCounterValue.Value = 0; - } - - private static void OnPerformanceTickData(PerformanceTickData tickData) - { - // Operations - UpdateIntCounter(tickData, k_ConnectionsCounterValue, ProfilerConstants.Connections); - UpdateIntCounter(tickData, k_TickRateCounterValue, ProfilerConstants.ReceiveTickRate); - - // Messages - UpdateIntCounter(tickData, k_NamedMessageReceivedCounterValue, ProfilerConstants.NamedMessageReceived); - UpdateIntCounter(tickData, k_UnnamedMessageReceivedCounterValue, ProfilerConstants.UnnamedMessageReceived); - UpdateIntCounter(tickData, k_NamedMessageSentCounterValue, ProfilerConstants.NamedMessageSent); - UpdateIntCounter(tickData, k_UnnamedMessageSentCounterValue, ProfilerConstants.UnnamedMessageSent); - UpdateIntCounter(tickData, k_BytesSentCounterValue, ProfilerConstants.ByteSent); - UpdateIntCounter(tickData, k_BytesReceivedCounterValue, ProfilerConstants.ByteReceived); - UpdateIntCounter(tickData, k_NetworkVarDeltasCounterValue, ProfilerConstants.NetworkVarDeltas); - UpdateIntCounter(tickData, k_NetworkVarUpdatesCounterValue, ProfilerConstants.NetworkVarUpdates); - - // Queue stats - UpdateIntCounter(tickData, k_RPCsSentCounterValue, ProfilerConstants.RpcSent); - UpdateIntCounter(tickData, k_RPCsReceivedCounterValue, ProfilerConstants.RpcReceived); - } - - private static void UpdateIntCounter(PerformanceTickData tickData, ProfilerCounterValue counter, string fieldName) - { - if (tickData.HasData(fieldName)) - { - counter.Value += tickData.GetData(fieldName); - } - } -#endif - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCountersInfo.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCountersInfo.cs.meta deleted file mode 100644 index 34e930ed6a..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerCountersInfo.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c12e40b02ca5a49ca8f9dbe35d34ab1b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerNotifier.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerNotifier.cs deleted file mode 100644 index 717cd3ed58..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerNotifier.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; - -namespace Unity.Netcode -{ - internal static class ProfilerNotifier - { - public delegate void PerformanceDataEventHandler(PerformanceTickData profilerData); - - public static event PerformanceDataEventHandler OnPerformanceDataEvent; - - public delegate void NoTickDataHandler(); - - public static event NoTickDataHandler OnNoTickDataEvent; - - private static IProfilableTransportProvider s_ProfilableTransportProvider; - private static bool s_FailsafeCheck; - - public static void Initialize(IProfilableTransportProvider profilableNetwork) - { - s_ProfilableTransportProvider = profilableNetwork - ?? throw new ArgumentNullException( - $"{nameof(profilableNetwork)} was not set"); - s_FailsafeCheck = false; - } - - public static void ProfilerBeginTick() - { - PerformanceDataManager.BeginNewTick(); - var transport = s_ProfilableTransportProvider.Transport; - transport?.BeginNewTick(); - s_FailsafeCheck = true; - } - - public static void NotifyProfilerListeners() - { - if (!s_FailsafeCheck) - { - return; - } - - s_FailsafeCheck = false; - - var data = PerformanceDataManager.GetData(); - var eventHandler = OnPerformanceDataEvent; - if (eventHandler != null) - { - if (data != null) - { - var transport = s_ProfilableTransportProvider.Transport; - if (transport != null) - { - var transportProfilerData = transport.GetTransportProfilerData(); - - PerformanceDataManager.AddTransportData(transportProfilerData); - } - - eventHandler.Invoke(data); - } - else - { - NetworkLog.LogWarning( - "No data available. Did you forget to call PerformanceDataManager.BeginNewTick() first?"); - } - } - } - - public static void Increment(string fieldName, int count = 1) - { - if (!s_FailsafeCheck) - { - OnNoTickDataEvent?.Invoke(); - } - - PerformanceDataManager.Increment(fieldName); - } - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerNotifier.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerNotifier.cs.meta deleted file mode 100644 index 015d08aa4b..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerNotifier.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 12af6f0ff6554caaab917445ae94d809 -timeCreated: 1616427513 \ No newline at end of file diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStat.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStat.cs deleted file mode 100644 index c26e950cc8..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStat.cs +++ /dev/null @@ -1,55 +0,0 @@ -using UnityEngine; - -namespace Unity.Netcode -{ - internal class ProfilerStat - { - public ProfilerStat(string name) - { - PrettyPrintName = name; - ProfilerStatManager.Add(this); - } - - public string PrettyPrintName; - - private int m_CurrentSecond = 0; - private int m_TotalAmount = 0; - private int m_Sample = 0; - - public virtual void Record(int amt = 1) - { - int currentSecond = (int)Time.unscaledTime; - if (currentSecond != m_CurrentSecond) - { - m_Sample = m_TotalAmount; - - m_TotalAmount = 0; - m_CurrentSecond = currentSecond; - } - - m_TotalAmount += amt; - } - - public virtual float SampleRate() - { - return m_Sample; - } - } - - internal class ProfilerIncStat : ProfilerStat - { - public ProfilerIncStat(string name) : base(name) { } - - private float m_InternalValue = 0f; - - public override void Record(int amt = 1) - { - m_InternalValue += amt; - } - - public override float SampleRate() - { - return m_InternalValue; - } - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStat.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStat.cs.meta deleted file mode 100644 index 6aac0dcf94..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStat.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7868721cc45b74ed29d0d2f75247a94c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStatManager.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStatManager.cs deleted file mode 100644 index 2442ea47ed..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStatManager.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; - -namespace Unity.Netcode -{ - internal static class ProfilerStatManager - { - public static List AllStats = new List(); - - public static readonly ProfilerIncStat Connections = new ProfilerIncStat("Connections"); - public static readonly ProfilerStat BytesRcvd = new ProfilerStat("Bytes Rcvd"); - public static readonly ProfilerStat BytesSent = new ProfilerStat("Bytes Sent"); - public static readonly ProfilerStat RcvTickRate = new ProfilerStat("Rcv Tick Rate"); - public static readonly ProfilerStat NetworkVarsRcvd = new ProfilerStat("Network Vars Rcvd"); - public static readonly ProfilerStat NamedMessage = new ProfilerStat("Named Message"); - public static readonly ProfilerStat UnnamedMessage = new ProfilerStat("UnNamed Message"); - - public static readonly ProfilerStat RpcsRcvd = new ProfilerStat("RPCs Rcvd"); - public static readonly ProfilerStat RpcsSent = new ProfilerStat("RPCs Sent"); - public static readonly ProfilerIncStat NetTranforms = new ProfilerIncStat("NetTransforms"); - - - public static void Add(ProfilerStat s) - { - AllStats.Add(s); - } - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStatManager.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStatManager.cs.meta deleted file mode 100644 index 0acd8c943f..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerStatManager.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 84b82ec95778845a0bdb486da306cdb3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerTickData.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerTickData.cs deleted file mode 100644 index 2813433739..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerTickData.cs +++ /dev/null @@ -1,201 +0,0 @@ -using System.Collections.Generic; -using System.IO; - -namespace Unity.Netcode -{ - /// - /// The type of Tick - /// - internal enum TickType - { - /// - /// Event tick. During EventTick NetworkVars are flushed etc - /// - Event, - - /// - /// Receive tick. During ReceiveTick data is received from the transport - /// - Receive, - - /// - /// Send tick. During Send data is sent from Transport queue - /// - Send - } - - /// - /// A tick in used for the Profiler - /// - internal class ProfilerTick - { - /// - /// The events that occured during this tick - /// - public readonly List Events = new List(); - - /// - /// Writes the current ProfilerTick to the stream - /// - /// The stream containing - public void SerializeToStream(Stream stream) - { - using (var writer = PooledNetworkWriter.Get(stream)) - { - writer.WriteUInt16Packed((ushort)Events.Count); - - for (int i = 0; i < Events.Count; i++) - { - Events[i].SerializeToStream(stream); - } - } - } - - /// - /// Creates a ProfilerTick from data in the provided stream - /// - /// The stream containing the ProfilerTick data - /// The ProfilerTick with data read from the stream - public static ProfilerTick FromStream(Stream stream) - { - var tick = new ProfilerTick(); - - using (var reader = PooledNetworkReader.Get(stream)) - { - ushort count = reader.ReadUInt16Packed(); - for (int i = 0; i < count; i++) - { - tick.Events.Add(TickEvent.FromStream(stream)); - } - - return tick; - } - } - - internal void EndEvent() - { - for (int i = Events.Count - 1; i >= 0; i--) - { - if (!Events[i].Closed) - { - Events[i].Closed = true; - return; - } - } - } - - internal void StartEvent(TickType type, uint bytes, string channelName, string messageType) - { - var tickEvent = new TickEvent() - { - Bytes = bytes, - ChannelName = string.IsNullOrEmpty(channelName) ? "NONE" : channelName, - MessageType = string.IsNullOrEmpty(messageType) ? "NONE" : messageType, - EventType = type, - Closed = false - }; - Events.Add(tickEvent); - } - - /// - /// The type of tick - /// - public TickType Type; - - /// - /// The frame the tick executed on - /// - public int Frame; - - /// - /// The id of the tick - /// - public int EventId; - - /// - /// The amount of bytes that were sent and / or received during this tick - /// - public uint Bytes - { - get - { - uint bytes = 0; - for (int i = 0; i < Events.Count; i++) - { - bytes += Events[i].Bytes; - } - - return bytes; - } - } - } - - /// - /// A event that can occur during a Event - /// - internal class TickEvent - { - /// - /// The type of evenmt - /// - public TickType EventType; - - /// - /// The amount of bytes sent or received - /// - public uint Bytes; - - /// - /// The name of the channel - /// - public string ChannelName; - - /// - /// The message type - /// - public string MessageType; - - /// - /// Whether or not the event is closed - /// - public bool Closed; - - /// - /// Writes the TickEvent data to the stream - /// - /// The stream to write the TickEvent data to - public void SerializeToStream(Stream stream) - { - using (var writer = PooledNetworkWriter.Get(stream)) - { - writer.WriteByte((byte)EventType); - writer.WriteUInt32Packed(Bytes); - writer.WriteStringPacked(ChannelName); - writer.WriteStringPacked(MessageType); - writer.WriteBool(Closed); - } - } - - /// - /// Creates a TickEvent from data in the provided stream - /// - /// The stream containing the TickEvent data - /// The TickEvent with data read from the stream - public static TickEvent FromStream(Stream stream) - { - using (var reader = PooledNetworkReader.Get(stream)) - { - var tickEvent = new TickEvent - { - EventType = (TickType)reader.ReadByte(), - Bytes = reader.ReadUInt32Packed(), - ChannelName = reader.ReadStringPacked(), - MessageType = reader.ReadStringPacked(), - Closed = reader.ReadBool() - }; - - return tickEvent; - } - } - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerTickData.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerTickData.cs.meta deleted file mode 100644 index 0e79c7035b..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilerTickData.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fb0351e1061093243937674addac2367 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilingDataStore.cs b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilingDataStore.cs deleted file mode 100644 index c2da091fc2..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilingDataStore.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; - -namespace Unity.Netcode -{ - internal class ProfilingDataStore - { - private readonly Dictionary m_Dictionary = new Dictionary(); - - public void Add(string fieldName, int value) - { - m_Dictionary.Add(fieldName, value); - } - - public void Increment(string fieldName, int count = 1) - { - if (m_Dictionary.TryGetValue(fieldName, out int value)) - { - m_Dictionary[fieldName] = value + count; - } - else - { - m_Dictionary[fieldName] = count; - } - } - - public bool HasData(string fieldName) - { - return m_Dictionary.ContainsKey(fieldName); - } - - public int GetData(string fieldName) - { - return m_Dictionary.TryGetValue(fieldName, out int value) ? value : 0; - } - - public void Clear() - { - m_Dictionary.Clear(); - } - - public IReadOnlyDictionary GetReadonly() - { - return m_Dictionary; - } - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilingDataStore.cs.meta b/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilingDataStore.cs.meta deleted file mode 100644 index f6b345dbc9..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Profiling/ProfilingDataStore.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 18cab32e87876465396e5f222a1a8c07 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Timing/NetworkTickSystem.cs b/com.unity.netcode.gameobjects/Runtime/Timing/NetworkTickSystem.cs index f7a20e659e..6f1e599ae2 100644 --- a/com.unity.netcode.gameobjects/Runtime/Timing/NetworkTickSystem.cs +++ b/com.unity.netcode.gameobjects/Runtime/Timing/NetworkTickSystem.cs @@ -74,15 +74,8 @@ public void UpdateTick(double localTimeSec, double serverTimeSec) #if DEVELOPMENT_BUILD || UNITY_EDITOR s_Tick.Begin(); -#endif -#if UNITY_EDITOR && !UNITY_2020_2_OR_NEWER - NetworkProfiler.StartTick(TickType.Event); #endif Tick?.Invoke(); - -#if UNITY_EDITOR && !UNITY_2020_2_OR_NEWER - NetworkProfiler.EndTick(); -#endif #if DEVELOPMENT_BUILD || UNITY_EDITOR s_Tick.End(); #endif diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UNET/ProfilerConstants.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UNET/ProfilerConstants.cs deleted file mode 100644 index 010d6a9b25..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Transports/UNET/ProfilerConstants.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Unity.Netcode.Transports.UNET -{ - public static class ProfilerConstants - { - public const string NumberOfTransportSends = nameof(NumberOfTransportSends); - public const string NumberOfTransportSendQueues = nameof(NumberOfTransportSendQueues); - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UNET/ProfilerConstants.cs.meta b/com.unity.netcode.gameobjects/Runtime/Transports/UNET/ProfilerConstants.cs.meta deleted file mode 100644 index 44c0a94639..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/Transports/UNET/ProfilerConstants.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c5bc85b7565054d6295b7847967cdbd8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UNET/UNetTransport.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UNET/UNetTransport.cs index ece8aa1149..b693d3edaf 100644 --- a/com.unity.netcode.gameobjects/Runtime/Transports/UNET/UNetTransport.cs +++ b/com.unity.netcode.gameobjects/Runtime/Transports/UNET/UNetTransport.cs @@ -7,7 +7,7 @@ namespace Unity.Netcode.Transports.UNET { - public class UNetTransport : NetworkTransport, ITransportProfilerData + public class UNetTransport : NetworkTransport { public enum SendMode { @@ -15,9 +15,6 @@ public enum SendMode Queued } - private static ProfilingDataStore s_TransportProfilerData = new ProfilingDataStore(); - public static bool ProfilerEnabled; - // Inspector / settings public int MessageBufferSize = 1024 * 5; public int MaxConnections = 100; @@ -96,11 +93,6 @@ protected void LateUpdate() public override void Send(ulong clientId, ArraySegment data, NetworkChannel networkChannel) { - if (ProfilerEnabled) - { - s_TransportProfilerData.Increment(ProfilerConstants.NumberOfTransportSends); - } - GetUNetConnectionDetails(clientId, out byte hostId, out ushort connectionId); int channelId = 0; @@ -162,11 +154,6 @@ public override void Send(ulong clientId, ArraySegment data, NetworkChanne #if !UNITY_WEBGL public void SendQueued(ulong clientId) { - if (ProfilerEnabled) - { - s_TransportProfilerData.Increment(ProfilerConstants.NumberOfTransportSendQueues); - } - GetUNetConnectionDetails(clientId, out byte hostId, out ushort connectionId); RelayTransport.SendQueuedMessages(hostId, connectionId, out byte error); @@ -360,8 +347,6 @@ public override void Init() m_MessageBuffer = new byte[MessageBufferSize]; - s_TransportProfilerData.Clear(); - UnityEngine.Networking.NetworkTransport.Init(); } @@ -479,16 +464,6 @@ private void UpdateRelay() RelayTransport.RelayAddress = NetcodeRelayAddress; RelayTransport.RelayPort = (ushort)NetcodeRelayPort; } - - public void BeginNewTick() - { - s_TransportProfilerData.Clear(); - } - - public IReadOnlyDictionary GetTransportProfilerData() - { - return s_TransportProfilerData.GetReadonly(); - } } } #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member diff --git a/com.unity.netcode.gameobjects/Tests/Editor/ProfilerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/ProfilerTests.cs deleted file mode 100644 index 916f540113..0000000000 --- a/com.unity.netcode.gameobjects/Tests/Editor/ProfilerTests.cs +++ /dev/null @@ -1,200 +0,0 @@ -using System; -using System.Collections.Generic; -using NUnit.Framework; - -namespace Unity.Netcode.EditorTests -{ - public class TestTransport : ITransportProfilerData - { - internal static class ProfilerConstants - { - public const string TransportTestData = nameof(TransportTestData); - } - - private static ProfilingDataStore s_TransportProfilerData = new ProfilingDataStore(); - - public void BeginNewTick() - { - s_TransportProfilerData.Clear(); - } - - public IReadOnlyDictionary GetTransportProfilerData() - { - return s_TransportProfilerData.GetReadonly(); - } - - public void Send(string testMessage) - { - PerformanceDataManager.Increment(ProfilerConstants.TransportTestData); - } - } - - public class TestProfiler : IProfilableTransportProvider - { - internal static class ProfilerConstants - { - public const string NetworkTestData = nameof(NetworkTestData); - } - - private TestTransport m_Transport; - private bool m_HasSentAnyData; - - public ITransportProfilerData Transport => m_Transport; - public bool HasSentAnyData => m_HasSentAnyData; - - public void Initialize(bool useNullTransport) - { - m_Transport = useNullTransport ? null : new TestTransport(); - m_HasSentAnyData = false; - ProfilerNotifier.Initialize(this); - } - - public static void ProfilerBeginTick() - { - ProfilerNotifier.ProfilerBeginTick(); - } - - public static void NotifyProfilerListeners() - { - ProfilerNotifier.NotifyProfilerListeners(); - } - - public void Send() - { - ProfilerNotifier.Increment(ProfilerConstants.NetworkTestData); - m_Transport?.Send("testMessage"); - m_HasSentAnyData = true; - } - } - - public class NoTickDataException : Exception - { - } - - public class ProfilerTests - { - private static TestProfiler SetupTestProfiler(bool useNullTransport) - { - var testProfiler = new TestProfiler(); - testProfiler.Initialize(useNullTransport); - return testProfiler; - } - - private static void RegisterStaticAsserts(bool useNullTransport) - { - ProfilerNotifier.OnNoTickDataEvent += RaiseExceptionNoTickDataEvent; - if (useNullTransport) - { - ProfilerNotifier.OnPerformanceDataEvent += AssertNetworkDataExists; - } - else - { - ProfilerNotifier.OnPerformanceDataEvent += AssertNetworkAndTransportDataExists; - } - } - - private static void AssertNetworkAndTransportDataExists(PerformanceTickData profilerData) - { - Assert.IsTrue(profilerData.HasData(TestProfiler.ProfilerConstants.NetworkTestData)); - Assert.IsTrue(profilerData.HasData(TestTransport.ProfilerConstants.TransportTestData)); - } - - private static void AssertNetworkDataExists(PerformanceTickData profilerData) - { - Assert.IsTrue(profilerData.HasData(TestProfiler.ProfilerConstants.NetworkTestData)); - Assert.IsFalse(profilerData.HasData(TestTransport.ProfilerConstants.TransportTestData)); - } - - private static void RaiseExceptionNoTickDataEvent() - { - throw new NoTickDataException(); - } - - [TearDown] - public void TearDown() - { - ProfilerNotifier.OnPerformanceDataEvent -= AssertNetworkAndTransportDataExists; - ProfilerNotifier.OnPerformanceDataEvent -= AssertNetworkDataExists; - ProfilerNotifier.OnNoTickDataEvent -= RaiseExceptionNoTickDataEvent; - } - - [Test] - public void TestSentNoData() - { - const bool useNullTransport = true; - TestProfiler testProfiler = SetupTestProfiler(useNullTransport); - - TestProfiler.ProfilerBeginTick(); - TestProfiler.NotifyProfilerListeners(); - - Assert.False(testProfiler.HasSentAnyData); - } - - [Test] - public void TestNormalRegisterAndNotifyFlow_NullTransport() - { - const bool useNullTransport = true; - TestProfiler testProfiler = SetupTestProfiler(useNullTransport); - - RegisterStaticAsserts(useNullTransport); - - TestProfiler.ProfilerBeginTick(); - testProfiler.Send(); - TestProfiler.NotifyProfilerListeners(); - - Assert.IsTrue(testProfiler.HasSentAnyData); - } - - [Test] - public void TestNormalRegisterAndNotifyFlow() - { - const bool useNullTransport = false; - TestProfiler testProfiler = SetupTestProfiler(useNullTransport); - - RegisterStaticAsserts(useNullTransport); - - TestProfiler.ProfilerBeginTick(); - testProfiler.Send(); - TestProfiler.NotifyProfilerListeners(); - - Assert.IsTrue(testProfiler.HasSentAnyData); - } - - [Test] - public void TestDroppedRegisterAndNotifyFlow() - { - const bool useNullTransport = false; - TestProfiler testProfiler = SetupTestProfiler(useNullTransport); - - RegisterStaticAsserts(useNullTransport); - - TestProfiler.ProfilerBeginTick(); - testProfiler.Send(); - TestProfiler.NotifyProfilerListeners(); - - // Capturing data after notifying listeners is bad - Assert.Catch(() => - { - testProfiler.Send(); - }); - - Assert.IsTrue(testProfiler.HasSentAnyData); - } - - [Test] - public void TestProperMatchRegisterAndNotifyFlow() - { - const bool useNullTransport = false; - TestProfiler testProfiler = SetupTestProfiler(useNullTransport); - - RegisterStaticAsserts(useNullTransport); - - TestProfiler.NotifyProfilerListeners(); - TestProfiler.ProfilerBeginTick(); - testProfiler.Send(); - TestProfiler.NotifyProfilerListeners(); - - Assert.IsTrue(testProfiler.HasSentAnyData); - } - } -} diff --git a/com.unity.netcode.gameobjects/Tests/Editor/ProfilerTests.cs.meta b/com.unity.netcode.gameobjects/Tests/Editor/ProfilerTests.cs.meta deleted file mode 100644 index ff71e12578..0000000000 --- a/com.unity.netcode.gameobjects/Tests/Editor/ProfilerTests.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 69750fc1f921f490fabad933b42ff9c5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: