Version: 2020.2
GPU Usage Profiler module
물리 프로파일러 모듈

Memory Profiler module

There are two ways of analyzing memory usage in your application in Unity:

  • Memory Profiler module: This built-in Profiler module gives you basic information on where your application uses memory.
  • Memory Profiler package: This is a separate package that you can add to your Project. It adds an additional Memory Profiler window to the Unity Editor, which you can then use to analyze memory usage in your application in even more detail. You can store and compare snapshots to find memory leaks more easily, or see the memory layout to find memory fragmentation issues.

This page covers information on the built-in Memory Profiler module. For more information on the Memory profiler package, see the Memory Profiler documentation.

메모리 프로파일러 모듈은 애플리케이션에 할당된 총 메모리를 나타내는 카운터를 시각화합니다. 메모리 모듈을 사용하면 로드된 오브젝트 수, 카테고리별로 차지하는 총 메모리 등과 같은 정보를 볼 수 있습니다. 또한 프로파일러 프레임당 GC 할당 수도 확인할 수 있습니다.

When you profile your application in the Editor, the information in the Memory module indicates the memory usage in the Editor. These numbers are generally larger than when running on the release platform, because running the Unity Editor uses specific objects that take up memory, and the Editor window itself uses extra memory. Additionally, the Profiler displays memory that it uses, because Unity cannot cleanly separate it from the memory that the Play mode Player uses. For more precise numbers and memory usage for your application, connect the Profiler to the running player via the Attach to Player menu. This allows you to see the actual usage on the target device.

차트 카테고리

메모리 모듈은 애플리케이션이 메모리를 소비하는 위치에 대한 자세한 정보를 보여주는 6개의 차트로 구성됩니다. 차트에서 카테고리 순서를 변경할 수 있습니다. 이렇게 하려면 카테고리를 차트 범례에 끌어다 놓으십시오. 카테고리의 컬러 범례를 클릭하여 표시 여부를 토글할 수도 있습니다.

카테고리 설명
Total Allocated The total memory your application has used.
Texture Memory How much memory the Textures in your application have used.
Mesh Memory How much memory the Meshes in your application have used.
Material Count The number of Material instances in your application.
Object Count The number of native object instances in your application.
GC Used Memory The amount of memory used by the GC heap.
GC Allocated in Frame The amount of memory allocated per frame on the GC heap.

모듈 세부 정보 창

프로파일러 창 하단에 있는 모듈 세부 정보 창에서는 SimpleDetailed 뷰를 사용할 수 있습니다. 뷰를 변경하려면 모듈 세부 정보 창의 왼쪽 상단에 있는 드롭다운에서 사용할 뷰를 선택하십시오.

Simple view

The Simple view displays an overview of how Unity uses memory in real-time on a per-frame basis.

Unity reserves memory pools for allocations to avoid asking the operating system for memory too often. The Profiler displays how much memory is reserved, and how much Unity is using.

The Simple Memory module view
The Simple Memory module view

This information is also available via the ProfilerRecorder API and in the Profiler Module Editor so you can add them to a custom Profiler module.

Statistic 설명 Available in Release Players
Total Used Memory Total value of memory that Unity uses and tracks. 지원
Total Reserved Memory Total reserved memory that Unity uses for tracking purposes and pool allocations. 지원
GC Used Memory

GC Reserved Memory
The used heap size and total heap size that managed code uses. This memory is garbage collected. 지원
Gfx Used Memory

Gfx Reserved Memory
The estimated amount of memory the driver uses on Textures, render targets, Shaders, and Mesh data. 지원
Audio Used Memory

Audio Reserved Memory
The Audio system’s estimated memory usage. 지원
Video Used Memory

Video Reserved Memory
The Video system’s estimated memory usage 지원
Profiler Used Memory

Profiler Reserved Memory
The memory the Profiler functionality uses and reserves from the system. 지원
System Used Memory The values in the Profiler are different to those displayed in your operating system’s task manager, because the Memory Profiler does not track all memory usage in your system. This includes memory that some drivers and plug-ins use, and memory used for executable code.

On platforms that support getting the total memory size of the application from the operating system, the System Memory Usage is over 0 and is the same size in a task manager.
지원
Texture Count

Texture Memory
The total count of loaded textures and memory they use. 미지원
Mesh Count

Mesh Memory
The total count of loaded meshes and memory they use. 미지원
Material Count

Material Memory
The total count of loaded materials and memory they use. 미지원
AnimationClip Count

AnimationClip Memory
The total count of loaded AnimationClips and memory they use. 미지원
Asset Count The total number of loaded assets. 미지원
GameObject Count The total number of GameObject instances in the scene. 미지원
Scene Object Count The total number of dynamic UnityEngine.Objects. This number includes the GameObject Count, plus the total number of components, and everything which is not asset in the scene. 미지원
Object Count The total number of native UnityEngine.Objects that your application creates or loads. This number includes the Scene Object Count, plus the total number of all assets. If this number rises over time, your application is creating GameObjects or other assets and never destroying or unloading them. 미지원
GC Allocation In Frame Count

GC Allocated In Frame
Amount of managed allocations and its total size in bytes. 미지원

Availability in Players

You can use the ProfilerRecorder API to access the Memory Profiler module’s counters in Players. The following example contains a simple script that collects “Total Reserved Memory”, “GC Reserved Memory” and “System Used Memory” metrics, and displays those as a GUI.TextArea. The Memory Profiler module information belongs to the ProfilerCategory.Memory Profiler category.

using System.Text;
using Unity.Profiling;
using UnityEngine;

public class MemoryStatsScript : MonoBehaviour
{
    string statsText;
    ProfilerRecorder totalReservedMemoryRecorder;
    ProfilerRecorder gcReservedMemoryRecorder;
    ProfilerRecorder systemUsedMemoryRecorder;

    void OnEnable()
    {
        totalReservedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "Total Reserved Memory");
        gcReservedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "GC Reserved Memory");
        systemUsedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "System Used Memory");
    }

    void OnDisable()
    {
        totalReservedMemoryRecorder.Dispose();
        gcReservedMemoryRecorder.Dispose();
        systemUsedMemoryRecorder.Dispose();
    }

    void Update()
    {
        var sb = new StringBuilder(500);
        if (totalReservedMemoryRecorder.Valid)
            sb.AppendLine($"Total Reserved Memory: {totalReservedMemoryRecorder.LastValue}");
        if (gcReservedMemoryRecorder.Valid)
            sb.AppendLine($"GC Reserved Memory: {gcReservedMemoryRecorder.LastValue}");
        if (systemUsedMemoryRecorder.Valid)
            sb.AppendLine($"System Used Memory: {systemUsedMemoryRecorder.LastValue}");
        statsText = sb.ToString();
    }

    void OnGUI()
    {
        GUI.TextArea(new Rect(10, 30, 250, 50), statsText);
    }
}

The following screenshot shows the result of adding the script to the Tanks! tutorial project.

Tanks! tutorial with the overlaid memory information
Tanks! tutorial with the overlaid memory information

This information is available in Release Players, as are the other high level counters in the table above. If you want to see the selected Memory counters in a custom module in the Profiler window, use the Module Editor to configure the chart.

Detailed view

The Detailed view provides a snapshot of your application’s current state. Click the Take Sample button to capture detailed memory usage for the current target. It takes the Profiler time to get this data, so the Detailed view does not give you real-time details. After the Profiler takes a sample, the Profiler window displays a list view where you can explore your application’s memory usage in more detail.

The Detailed memory module view
The Detailed memory module view

Enable the Gather object references setting at the top of the module details pane to collect information about what is referencing an object at the time of the snapshot. The Profiler displays this information in the right-hand pane of the window.

The list view divides objects that use memory into the following categories:

  • Other: Objects that are neither Assets, GameObjects, or components. This includes information such as the memory Unity uses for different systems.
  • Not Saved: DontSave로 표시된 오브젝트
  • Builtin Resources: Unity Editor resources or Unity default resources, such as Shaders you have added to the Always Included Shaders list of the Graphics settings.
  • Assets: Assets referenced from user or native code.
  • Scene Memory: Objects and attached components.

When you click on a GameObject in the Assets or Scene Memory list, it’s highlighted in the Project or Scene view.

Note: In the Other category, memory reported under System.ExecutableAndDlls is read-only memory. The operating system might discard these pages as needed and later reload them from the file system. This generates lower memory usage, and usually does not directly contribute to the operating system’s decision to close your application if it uses too much memory. Some of these pages might also be shared with other applications that are using the same frameworks.

GPU Usage Profiler module
물리 프로파일러 모듈