Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Ignore everything:
/Assets/*
!/Assets/FishNet
!/Assets/FishNet.meta
!.gitignore

DefaultPrefabObjects.asset
Expand Down
13 changes: 13 additions & 0 deletions .idea/.idea.FishNet/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.FishNet/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.FishNet/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/FishNet.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/FishNet/Runtime/Editor/Profiling.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using FishNet.Utility.Performance.Profiling;

namespace Fishnet.NetworkProfiler.ModuleGUI
{
internal interface ICountRecorderProvider
{
CountRecorder GetCountRecorder();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/FishNet/Runtime/Editor/Profiling/Messages.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions Assets/FishNet/Runtime/Editor/Profiling/Messages/Columns.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Collections;
using System.Collections.Generic;
using Fishnet.NetworkProfiler.ModuleGUI.UITable;

namespace Fishnet.NetworkProfiler.ModuleGUI.Messages
{
internal sealed class Columns : IEnumerable<ColumnInfo>
{
private const int EXPAND_WIDTH = 25;
private const int SHORT_NAME_WIDTH = 75;
private const int FULL_NAME_WIDTH = 300;
private const int NAME_WIDTH = 450;
private const int OTHER_WIDTH = 100;

private readonly ColumnInfo[] _columns;

public readonly ColumnInfo Expand;
public readonly ColumnInfo FullName;
public readonly ColumnInfo TotalBytes;
public readonly ColumnInfo Count;
public readonly ColumnInfo BytesPerMessage;
//public readonly ColumnInfo NetId;
public readonly ColumnInfo ObjectName;
public readonly ColumnInfo PropertyName;

public Columns()
{
Expand = new ColumnInfo("+", EXPAND_WIDTH, x => "");

FullName = new ColumnInfo("Packet Type", SHORT_NAME_WIDTH, x => x.PacketIdName);
FullName.AddSort(m => m.Name, m => m.PacketIdName);

TotalBytes = new ColumnInfo("Total Bytes", OTHER_WIDTH, x => x.TotalBytes.ToString());
TotalBytes.AddSort(m => m.TotalBytes, m => m.TotalBytes);

Count = new ColumnInfo("Count", OTHER_WIDTH, x => x.Count.ToString());
Count.AddSort(m => m.TotalCount, m => m.Count);

BytesPerMessage = new ColumnInfo("Bytes", OTHER_WIDTH, x => x.Bytes.ToString());
BytesPerMessage.AddSort(null, m => m.Bytes);

// NetId = new ColumnInfo("Net id", OTHER_WIDTH, x => x.NetId.HasValue ? x.NetId.ToString() : "");
// NetId.AddSort(null, m => m.NetId.GetValueOrDefault());

ObjectName = new ColumnInfo("GameObject Name", NAME_WIDTH, x => x.ObjectName);
ObjectName.AddSort(null, m => m.ObjectName);

PropertyName = new ColumnInfo("Prop Name (hover for full name)", FULL_NAME_WIDTH, x => RpcShortName(x.RpcName));
PropertyName.AddSort(null, m => m.RpcName);
// full name in tooltip
PropertyName.AddToolTip(m => m.RpcName);

_columns = new ColumnInfo[] {

Expand,
FullName,
TotalBytes,
Count,
BytesPerMessage,
//NetId,
ObjectName,
PropertyName,
};
}

private string RpcShortName(string fullName)
{
if (string.IsNullOrEmpty(fullName))
return string.Empty;

const char separator = '.';

if (fullName.Contains(separator))
{
var split = fullName.Split(separator);
var count = split.Length;
if (count >= 2)
{
return $"{split[count - 2]}.{split[count - 1]}";
}
}

return fullName;
}


public IEnumerator<ColumnInfo> GetEnumerator() => ((IEnumerable<ColumnInfo>)_columns).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => _columns.GetEnumerator();
}
}
11 changes: 11 additions & 0 deletions Assets/FishNet/Runtime/Editor/Profiling/Messages/Columns.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Assets/FishNet/Runtime/Editor/Profiling/Messages/CounterNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Fishnet.NetworkProfiler.ModuleGUI.Messages
{
internal struct CounterNames
{
public readonly string Count;
public readonly string Bytes;
public readonly string PerSecond;

public CounterNames(string count, string bytes, string perSecond)
{
Count = count;
Bytes = bytes;
PerSecond = perSecond;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/FishNet/Runtime/Editor/Profiling/Messages/DrawnMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Fishnet.NetworkProfiler.ModuleGUI.UITable;
using FishNet.Utility.Performance.Profiling;

namespace Fishnet.NetworkProfiler.ModuleGUI.Messages
{
internal class DrawnMessage
{
public PacketInfo Info;
public Row Row;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions Assets/FishNet/Runtime/Editor/Profiling/Messages/Group.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using Fishnet.NetworkProfiler.ModuleGUI.UITable;
using FishNet.Utility.Performance.Profiling;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace Fishnet.NetworkProfiler.ModuleGUI.Messages
{
internal class Group
{
public readonly List<Row> Rows = new List<Row>();
public readonly string Name;
public readonly List<DrawnMessage> Messages = new List<DrawnMessage>();

private readonly Table _table;
private readonly Columns _columns;

public Row Head;

public int TotalBytes { get; private set; }
public int TotalCount { get; private set; }
public int Order { get; private set; }

public bool Expanded { get; private set; }

public Group(string name, Table table, Columns columns)
{
Name = name;
_table = table;
_columns = columns;
// start at max, then take min each time message is added
Order = int.MaxValue;
}

public void AddMessage(PacketInfo msg)
{
Messages.Add(new DrawnMessage { Info = msg });
TotalBytes += msg.TotalBytes;
TotalCount += msg.Count;
Order = Math.Min(Order, msg.Order);
}

public void ToggleExpand()
{
Expand(!Expanded);
}

public void Expand(bool expanded)
{
Expanded = expanded;
// create rows if needed
LazyCreateRows();
foreach (var row in Rows)
{
row.VisualElement.style.display = expanded ? DisplayStyle.Flex : DisplayStyle.None;
}

// head can be null if ungrouped
Head?.SetText(_columns.Expand, Expanded ? "-" : "+");
}

public void LazyCreateRows()
{
// not visible, do nothing till row is expanded
if (!Expanded)
return;
// already created
if (Rows.Count > 0)
return;

DrawMessages();
}


/// <param name="messages">Messages to add to table</param>
/// <param name="createdRows">list to add rows to once created, Can be null</param>
private void DrawMessages()
{
var previous = Head;
var backgroundColor = GetBackgroundColor();

foreach (var drawn in Messages)
{
var row = _table.AddRow(previous);
Rows.Add(row);

// set previous to be new row, so that message are added in order after previous
previous = row;

drawn.Row = row;
var info = drawn.Info;
DrawMessage(row, info);

// set color of labels not whole row, otherwise color will be outside of table as well
foreach (var ele in row.GetChildren())
ele.style.backgroundColor = backgroundColor;
}
}

private void DrawMessage(Row row, PacketInfo info)
{
foreach (var column in _columns)
{
row.SetText(column, column.TextGetter.Invoke(info));
if (column.HasToolTip)
{
var label = row.GetLabel(column);
label.tooltip = column.ToolTipGetter.Invoke(info);
}
}
}

private static Color GetBackgroundColor()
{
// pick color that is lighter/darker than default editor background
// todo check if there is a way to get the real color, or do we have to use `isProSkin`?
return EditorGUIUtility.isProSkin
? (Color)new Color32(56, 56, 56, 255) / 0.8f
: (Color)new Color32(194, 194, 194, 255) * .8f;
}
}
}
11 changes: 11 additions & 0 deletions Assets/FishNet/Runtime/Editor/Profiling/Messages/Group.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading