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
117 changes: 0 additions & 117 deletions com.unity.multiplayer.mlapi/Editor/MLAPIProfilerModule.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

namespace Unity.Netcode.Editor
{
public class MLAPIProfiler : EditorWindow
public class NetcodeProfiler : EditorWindow
{
#if !UNITY_2020_2_OR_NEWER
[MenuItem("Window/MLAPI Profiler")]
[MenuItem("Window/Netcode Profiler")]
public static void ShowWindow()
{
GetWindow<MLAPIProfiler>();
GetWindow<NetcodeProfiler>();
}
#endif

Expand Down
117 changes: 117 additions & 0 deletions com.unity.multiplayer.mlapi/Editor/NetcodeProfilerModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
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 = "MLAPI RPCs";
private const string k_OperationModuleName = "MLAPI Operations";
private const string k_MessageModuleName = "MLAPI Messages";

#pragma warning disable IDE1006 // disable naming rule violation check
/// <summary>
/// This needs to be in synced with the internal dynamic module structure to provide our own counters
/// </summary>
[Serializable]
private class NetcodeProfilerCounter
{
// Note: These fields are named this way for internal serialization
public string m_Name;
public string m_Category;
}

/// <summary>
/// This needs to be in synced with the internal dynamic module structure to provide our own counters
/// </summary>
[Serializable]
private class NetcodeProfilerModuleData
{
// Note: These fields are named this way for internal serialization
public List<NetcodeProfilerCounter> m_ChartCounters = new List<NetcodeProfilerCounter>();
public List<NetcodeProfilerCounter> m_DetailCounters = new List<NetcodeProfilerCounter>();
public string m_Name;
}

/// <summary>
/// This needs to be in synced with the internal dynamic module structure to provide our own counters
/// </summary>
[Serializable]
private class NetcodeModules
{
// Note: These fields are named this way for internal serialization
public List<NetcodeProfilerModuleData> m_Modules;
}
#pragma warning restore IDE1006 // restore naming rule violation check

private static List<NetcodeProfilerCounter> CreateRPCCounters() => new List<NetcodeProfilerCounter>()
{
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<NetcodeProfilerCounter> CreateOperationsCounters() => new List<NetcodeProfilerCounter>()
{
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<NetcodeProfilerCounter> CreateMessagesCounters() => new List<NetcodeProfilerCounter>()
{
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<NetcodeProfilerCounter> CounterListFactoryDelegate();

private static bool CreateNetcodeDynamicModule(ref NetcodeModules mlapiModules, string moduleName, CounterListFactoryDelegate counterListFactoryDelegate)
{
var module = mlapiModules.m_Modules.Find(x => x.m_Name == moduleName);
if (module == null)
{
var newModule = new NetcodeProfilerModuleData
{
m_Name = moduleName,
m_ChartCounters = counterListFactoryDelegate(),
m_DetailCounters = counterListFactoryDelegate(),
};
mlapiModules.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<NetcodeModules>(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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal static class ProfilerCountersInfo
ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush);

[RuntimeInitializeOnLoadMethod]
private static void RegisterMLAPIPerformanceEvent()
private static void RegisterNetcodePerformanceEvent()
{
InitializeCounters();
ProfilerNotifier.OnPerformanceDataEvent += OnPerformanceTickData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override NetworkEvent PollEvent(out ulong clientId, out NetworkChannel ne

if (networkEvent != NetworkEvent.Nothing)
{
clientId = GetMLAPIClientId(i, connectionId, false);
clientId = GetNetcodeClientId(i, connectionId, false);

return networkEvent;
}
Expand Down Expand Up @@ -165,7 +165,7 @@ public override SocketTasks StartServer()
}


public ulong GetMLAPIClientId(byte transportId, ulong connectionId, bool isServer)
public ulong GetNetcodeClientId(byte transportId, ulong connectionId, bool isServer)
{
if (isServer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal void ResetChannelCache()
m_ChannelsCache = null;
}

public TransportChannel[] MLAPI_CHANNELS
public TransportChannel[] NETCODE_CHANNELS
{
get
{
Expand All @@ -67,16 +67,16 @@ public TransportChannel[] MLAPI_CHANNELS

OnChannelRegistration?.Invoke(transportChannels);

m_ChannelsCache = new TransportChannel[MLAPI_INTERNAL_CHANNELS.Length + transportChannels.Count];
m_ChannelsCache = new TransportChannel[NETCODE_INTERNAL_CHANNELS.Length + transportChannels.Count];

for (int i = 0; i < MLAPI_INTERNAL_CHANNELS.Length; i++)
for (int i = 0; i < NETCODE_INTERNAL_CHANNELS.Length; i++)
{
m_ChannelsCache[i] = MLAPI_INTERNAL_CHANNELS[i];
m_ChannelsCache[i] = NETCODE_INTERNAL_CHANNELS[i];
}

for (int i = 0; i < transportChannels.Count; i++)
{
m_ChannelsCache[i + MLAPI_INTERNAL_CHANNELS.Length] = transportChannels[i];
m_ChannelsCache[i + NETCODE_INTERNAL_CHANNELS.Length] = transportChannels[i];
}
}

Expand All @@ -85,10 +85,10 @@ public TransportChannel[] MLAPI_CHANNELS
}

/// <summary>
/// The channels the MLAPI will use when sending internal messages.
/// The channels the Netcode will use when sending internal messages.
/// </summary>
#pragma warning disable IDE1006 // disable naming rule violation check
private readonly TransportChannel[] MLAPI_INTERNAL_CHANNELS =
private readonly TransportChannel[] NETCODE_INTERNAL_CHANNELS =
#pragma warning restore IDE1006 // restore naming rule violation check
{
new TransportChannel(NetworkChannel.Internal, NetworkDelivery.ReliableSequenced),
Expand Down
Loading