Skip to content

Commit ae4183e

Browse files
refactor!: Removing the old MLAPI Profiler from UNITY_2020_2_OR_LATER (#516)
* refactor!: Removing the old MLAPI Profiler from UNITY_2020_2_OR_LATER * Also remove the menu item
1 parent 20a89c7 commit ae4183e

3 files changed

Lines changed: 44 additions & 9 deletions

File tree

com.unity.multiplayer.mlapi/Editor/MLAPIProfiler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ namespace UnityEditor
99
{
1010
public class MLAPIProfiler : EditorWindow
1111
{
12+
#if !UNITY_2020_2_OR_LATER
1213
[MenuItem("Window/MLAPI Profiler")]
1314
public static void ShowWindow()
1415
{
1516
GetWindow<MLAPIProfiler>();
1617
}
18+
#endif
1719

1820
GUIStyle wrapStyle
1921
{

com.unity.multiplayer.mlapi/Runtime/Core/NetworkingManager.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ public void Shutdown()
677677
}
678678
networkTickSystem = null;
679679

680+
#if !UNITY_2020_2_OR_LATER
680681
NetworkProfiler.Stop();
682+
#endif
681683
IsListening = false;
682684
IsServer = false;
683685
IsClient = false;
@@ -731,7 +733,9 @@ private void OnNetworkEarlyUpdate()
731733
#endif
732734
var IsLoopBack = false;
733735

736+
#if !UNITY_2020_2_OR_LATER
734737
NetworkProfiler.StartTick(TickType.Receive);
738+
#endif
735739

736740
//If we are in loopback mode, we don't need to touch the transport
737741
if (!IsLoopBack)
@@ -750,7 +754,9 @@ private void OnNetworkEarlyUpdate()
750754

751755
m_LastReceiveTickTime = NetworkTime;
752756

757+
#if !UNITY_2020_2_OR_LATER
753758
NetworkProfiler.EndTick();
759+
#endif
754760

755761
#if DEVELOPMENT_BUILD || UNITY_EDITOR
756762
s_ReceiveTick.End();
@@ -769,7 +775,7 @@ private void OnNetworkPreUpdate()
769775
#if DEVELOPMENT_BUILD || UNITY_EDITOR
770776
s_EventTick.Begin();
771777
#endif
772-
#if UNITY_EDITOR
778+
#if UNITY_EDITOR && !UNITY_2020_2_OR_LATER
773779
NetworkProfiler.StartTick(TickType.Event);
774780
#endif
775781

@@ -794,7 +800,7 @@ private void OnNetworkPreUpdate()
794800
{
795801
m_LastEventTickTime = NetworkTime;
796802
}
797-
#if UNITY_EDITOR
803+
#if UNITY_EDITOR && !UNITY_2020_2_OR_LATER
798804
NetworkProfiler.EndTick();
799805
#endif
800806

@@ -804,25 +810,25 @@ private void OnNetworkPreUpdate()
804810
}
805811
else if (IsServer && m_EventOvershootCounter >= ((1f / NetworkConfig.EventTickrate)))
806812
{
807-
#if UNITY_EDITOR
813+
#if UNITY_EDITOR && !UNITY_2020_2_OR_LATER
808814
NetworkProfiler.StartTick(TickType.Event);
809815
#endif
810816
//We run this one to compensate for previous update overshoots.
811817
m_EventOvershootCounter -= (1f / NetworkConfig.EventTickrate);
812818
LagCompensationManager.AddFrames();
813-
#if UNITY_EDITOR
819+
#if UNITY_EDITOR && !UNITY_2020_2_OR_LATER
814820
NetworkProfiler.EndTick();
815821
#endif
816822
}
817823

818824
if (IsServer && NetworkConfig.EnableTimeResync && NetworkTime - m_LastTimeSyncTime >= NetworkConfig.TimeResyncInterval)
819825
{
820-
#if UNITY_EDITOR
826+
#if UNITY_EDITOR && !UNITY_2020_2_OR_LATER
821827
NetworkProfiler.StartTick(TickType.Event);
822828
#endif
823829
SyncTime();
824830
m_LastTimeSyncTime = NetworkTime;
825-
#if UNITY_EDITOR
831+
#if UNITY_EDITOR && !UNITY_2020_2_OR_LATER
826832
NetworkProfiler.EndTick();
827833
#endif
828834
}
@@ -903,7 +909,9 @@ private void HandleRawTransportPoll(NetEventType eventType, ulong clientId, Chan
903909
#if DEVELOPMENT_BUILD || UNITY_EDITOR
904910
s_TransportConnect.Begin();
905911
#endif
912+
#if !UNITY_2020_2_OR_LATER
906913
NetworkProfiler.StartEvent(TickType.Receive, (uint)payload.Count, channel, "TRANSPORT_CONNECT");
914+
#endif
907915
if (IsServer)
908916
{
909917
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer) NetworkLog.LogInfo("Client Connected");
@@ -922,7 +930,9 @@ private void HandleRawTransportPoll(NetEventType eventType, ulong clientId, Chan
922930
SendConnectionRequest();
923931
StartCoroutine(ApprovalTimeout(clientId));
924932
}
933+
#if !UNITY_2020_2_OR_LATER
925934
NetworkProfiler.EndEvent();
935+
#endif
926936
#if DEVELOPMENT_BUILD || UNITY_EDITOR
927937
s_TransportConnect.End();
928938
#endif
@@ -937,7 +947,9 @@ private void HandleRawTransportPoll(NetEventType eventType, ulong clientId, Chan
937947
#if DEVELOPMENT_BUILD || UNITY_EDITOR
938948
s_TransportDisconnect.Begin();
939949
#endif
950+
#if !UNITY_2020_2_OR_LATER
940951
NetworkProfiler.StartEvent(TickType.Receive, 0, Channel.Internal, "TRANSPORT_DISCONNECT");
952+
#endif
941953

942954
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer) NetworkLog.LogInfo("Disconnect Event From " + clientId);
943955

@@ -951,7 +963,10 @@ private void HandleRawTransportPoll(NetEventType eventType, ulong clientId, Chan
951963

952964
if (OnClientDisconnectCallback != null)
953965
OnClientDisconnectCallback.Invoke(clientId);
966+
967+
#if !UNITY_2020_2_OR_LATER
954968
NetworkProfiler.EndEvent();
969+
#endif
955970
#if DEVELOPMENT_BUILD || UNITY_EDITOR
956971
s_TransportDisconnect.End();
957972
#endif
@@ -988,7 +1003,10 @@ internal void HandleIncomingData(ulong clientId, Channel channel, ArraySegment<b
9881003
}
9891004

9901005
uint headerByteSize = (uint)Arithmetic.VarIntSize(messageType);
1006+
1007+
#if !UNITY_2020_2_OR_LATER
9911008
NetworkProfiler.StartEvent(TickType.Receive, (uint)(data.Count - headerByteSize), channel, messageType);
1009+
#endif
9921010

9931011
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer) NetworkLog.LogInfo("Data Header: messageType=" + messageType);
9941012

@@ -1117,7 +1135,9 @@ internal void HandleIncomingData(ulong clientId, Channel channel, ArraySegment<b
11171135
}
11181136
#endregion
11191137

1138+
#if !UNITY_2020_2_OR_LATER
11201139
NetworkProfiler.EndEvent();
1140+
#endif
11211141
}
11221142
#if DEVELOPMENT_BUILD || UNITY_EDITOR
11231143
s_HandleIncomingData.End();

com.unity.multiplayer.mlapi/Runtime/Messaging/InternalMessageSender.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ internal static void Send(ulong clientId, byte messageType, Channel channel, Bit
1818

1919
using (BitStream stream = MessagePacker.WrapMessage(messageType, messageStream))
2020
{
21+
#if !UNITY_2020_2_OR_LATER
2122
NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channel, MLAPIConstants.MESSAGE_NAMES[messageType]);
23+
#endif
2224

2325
NetworkingManager.Singleton.NetworkConfig.NetworkTransport.Send(clientId, new ArraySegment<byte>(stream.GetBuffer(), 0, (int)stream.Length), channel);
2426
ProfilerStatManager.bytesSent.Record((int)stream.Length);
2527
PerformanceDataManager.Increment(ProfilerConstants.NumberBytesSent, (int)stream.Length);
2628

29+
#if !UNITY_2020_2_OR_LATER
2730
NetworkProfiler.EndEvent();
31+
#endif
2832
}
2933
}
3034

@@ -34,7 +38,9 @@ internal static void Send(byte messageType, Channel channel, BitStream messageSt
3438

3539
using (BitStream stream = MessagePacker.WrapMessage(messageType, messageStream))
3640
{
41+
#if !UNITY_2020_2_OR_LATER
3742
NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channel, MLAPIConstants.MESSAGE_NAMES[messageType]);
43+
#endif
3844
for (int i = 0; i < NetworkingManager.Singleton.ConnectedClientsList.Count; i++)
3945
{
4046
if (NetworkingManager.Singleton.IsServer && NetworkingManager.Singleton.ConnectedClientsList[i].ClientId == NetworkingManager.Singleton.ServerClientId)
@@ -44,8 +50,9 @@ internal static void Send(byte messageType, Channel channel, BitStream messageSt
4450
ProfilerStatManager.bytesSent.Record((int)stream.Length);
4551
PerformanceDataManager.Increment(ProfilerConstants.NumberBytesSent, (int)stream.Length);
4652
}
47-
53+
#if !UNITY_2020_2_OR_LATER
4854
NetworkProfiler.EndEvent();
55+
#endif
4956
}
5057
}
5158

@@ -61,7 +68,9 @@ internal static void Send(byte messageType, Channel channel, List<ulong> clientI
6168

6269
using (BitStream stream = MessagePacker.WrapMessage(messageType, messageStream))
6370
{
71+
#if !UNITY_2020_2_OR_LATER
6472
NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channel, MLAPIConstants.MESSAGE_NAMES[messageType]);
73+
#endif
6574
for (int i = 0; i < clientIds.Count; i++)
6675
{
6776
if (NetworkingManager.Singleton.IsServer && clientIds[i] == NetworkingManager.Singleton.ServerClientId)
@@ -71,8 +80,9 @@ internal static void Send(byte messageType, Channel channel, List<ulong> clientI
7180
ProfilerStatManager.bytesSent.Record((int)stream.Length);
7281
PerformanceDataManager.Increment(ProfilerConstants.NumberBytesSent, (int)stream.Length);
7382
}
74-
83+
#if !UNITY_2020_2_OR_LATER
7584
NetworkProfiler.EndEvent();
85+
#endif
7686
}
7787
}
7888

@@ -82,7 +92,9 @@ internal static void Send(byte messageType, Channel channel, ulong clientIdToIgn
8292

8393
using (BitStream stream = MessagePacker.WrapMessage(messageType, messageStream))
8494
{
95+
#if !UNITY_2020_2_OR_LATER
8596
NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channel, MLAPIConstants.MESSAGE_NAMES[messageType]);
97+
#endif
8698
for (int i = 0; i < NetworkingManager.Singleton.ConnectedClientsList.Count; i++)
8799
{
88100
if (NetworkingManager.Singleton.ConnectedClientsList[i].ClientId == clientIdToIgnore ||
@@ -93,8 +105,9 @@ internal static void Send(byte messageType, Channel channel, ulong clientIdToIgn
93105
ProfilerStatManager.bytesSent.Record((int)stream.Length);
94106
PerformanceDataManager.Increment(ProfilerConstants.NumberBytesSent, (int)stream.Length);
95107
}
96-
108+
#if !UNITY_2020_2_OR_LATER
97109
NetworkProfiler.EndEvent();
110+
#endif
98111
}
99112
}
100113
}

0 commit comments

Comments
 (0)