Skip to content

Commit 5127cfd

Browse files
committed
add profiler info
1 parent 0873f83 commit 5127cfd

7 files changed

+166
-0
lines changed

app/Assets/UniDebugMenu/Example/Scripts/ExampleTopListCreator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public ExampleTopListCreator()
5252
new ActionData( "ボタン表示サンプル 2列" , () => OpenAdd( DMType.BUTTON_COL_2 , new TextListCreatorExample() ) ),
5353
new ActionData( "ボタン表示サンプル 3列" , () => OpenAdd( DMType.BUTTON_COL_3 , new TextListCreatorExample() ) ),
5454
new ActionData( "システム情報" , () => OpenAdd( DMType.TEXT_TAB_6 , new SystemInfoListCreator() ) ),
55+
new ActionData( "プロファイラ情報" , () => OpenAdd( DMType.TEXT_TAB_6 , new ProfilerInfoListCreator() ) ),
5556
new ActionData( "システムコマンド" , () => OpenAdd( DMType.COMMAND_TAB_6 , new SystemCommandListCreator() ) ),
5657
new ActionData( "ゲームオブジェクト一覧" , () => OpenAdd( DMType.COMMAND_TAB_6 , new GameObjectListCreator() ) ),
5758
new ActionData( "ログ情報" , () => OpenAdd( DMType.TEXT_TAB_6 , m_logDataCreator ) ),
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using UnityEngine.Profiling;
2+
3+
namespace UniDebugMenu.Example
4+
{
5+
public sealed class MonoMemoryChecker
6+
{
7+
public float Used { get; private set; }
8+
public float Total { get; private set; }
9+
10+
public string UsedText { get; private set; }
11+
public string TotalText { get; private set; }
12+
13+
public void Update()
14+
{
15+
Used = ( Profiler.GetMonoUsedSizeLong() >> 10 ) / 1024f;
16+
17+
// ヒープが大きいほど GC の時間がかかりますが、実行される頻度は少なくなる
18+
Total = ( Profiler.GetMonoHeapSizeLong() >> 10 ) / 1024f;
19+
20+
UsedText = Used.ToString( "0.0" ) + " MB";
21+
TotalText = Total.ToString( "0.0" ) + " MB";
22+
}
23+
}
24+
}

app/Assets/UniDebugMenu/Example/Scripts/MonoMemoryChecker.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace UniDebugMenu.Example
6+
{
7+
/// <summary>
8+
/// プロファイラ情報を表示するクラス
9+
/// </summary>
10+
[Serializable]
11+
public sealed class ProfilerInfoListCreator : ListCreatorBase<ActionData>
12+
{
13+
//==============================================================================
14+
// 変数(readonly)
15+
//==============================================================================
16+
private readonly MonoMemoryChecker m_monoMemoryChecker = new MonoMemoryChecker();
17+
private readonly UnityMemoryChecker m_unityMemoryChecker = new UnityMemoryChecker();
18+
19+
//==============================================================================
20+
// 変数
21+
//==============================================================================
22+
private IList<ActionData> m_list;
23+
24+
//==============================================================================
25+
// プロパティ
26+
//==============================================================================
27+
public override int Count => m_list.Count;
28+
29+
//==============================================================================
30+
// 関数
31+
//==============================================================================
32+
/// <summary>
33+
/// リストの表示に使用するデータを作成します
34+
/// </summary>
35+
protected override void DoCreate( ListCreateData data )
36+
{
37+
m_list = ToText()
38+
.Split( '\n' )
39+
.Where( c => data.IsMatch( c ) )
40+
.Select( c => new ActionData( c ) )
41+
.ToArray()
42+
.ReverseIf( data.IsReverse )
43+
;
44+
}
45+
46+
/// <summary>
47+
/// 指定されたインデックスの要素の表示に使用するデータを返します
48+
/// </summary>
49+
protected override ActionData DoGetElemData( int index ) => m_list.ElementAtOrDefault( index );
50+
51+
/// <summary>
52+
/// テキストを整形して返します
53+
/// </summary>
54+
private string ToText()
55+
{
56+
m_monoMemoryChecker.Update();
57+
m_unityMemoryChecker.Update();
58+
59+
var appender = new StringAppender
60+
{
61+
{ "<b>Mono</b>" },
62+
{ "" },
63+
{ $" Used: {m_monoMemoryChecker.UsedText}" },
64+
{ $" Total: {m_monoMemoryChecker.TotalText}" },
65+
{ "" },
66+
{ "<b>Unity</b>" },
67+
{ "" },
68+
{ $" Used: {m_unityMemoryChecker.UsedText}" },
69+
{ $" Unused: {m_unityMemoryChecker.UnusedText}" },
70+
{ $" Total: {m_unityMemoryChecker.TotalText}" },
71+
{ "" },
72+
};
73+
74+
return appender.ToString();
75+
}
76+
}
77+
}

app/Assets/UniDebugMenu/Example/Scripts/ProfilerInfoListCreator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using UnityEngine.Profiling;
2+
3+
namespace UniDebugMenu.Example
4+
{
5+
public sealed class UnityMemoryChecker
6+
{
7+
public float Used { get; private set; }
8+
public float Unused { get; private set; }
9+
public float Total { get; private set; }
10+
11+
public string UsedText { get; private set; }
12+
public string UnusedText { get; private set; }
13+
public string TotalText { get; private set; }
14+
15+
public void Update()
16+
{
17+
// Unity によって割り当てられたメモリ
18+
Used = ( Profiler.GetTotalAllocatedMemoryLong() >> 10 ) / 1024f;
19+
20+
// 予約済みだが割り当てられていないメモリ
21+
Unused = ( Profiler.GetTotalUnusedReservedMemoryLong() >> 10 ) / 1024f;
22+
23+
// Unity が現在および将来の割り当てのために確保している総メモリ
24+
Total = ( Profiler.GetTotalReservedMemoryLong() >> 10 ) / 1024f;
25+
26+
UsedText = Used.ToString( "0.0" ) + " MB";
27+
UnusedText = Unused.ToString( "0.0" ) + " MB";
28+
TotalText = Total.ToString( "0.0" ) + " MB";
29+
}
30+
}
31+
}

app/Assets/UniDebugMenu/Example/Scripts/UnityMemoryChecker.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)