프로파일러 카운터 시각화
커스텀 프로파일러 모듈에 프로파일러 카운터를 추가합니다.
읽는 시간 4분최근 업데이트: 9일 전
프로파일러 카운터를 코드에 추가하면 프로파일러 창 또는 애플리케이션 빌드에서 시각화할 수 있습니다.
프로파일러 창 커스텀 카운터 시각화
프로파일러 창에서 또는 가 생성하는 데이터를 보려면 커스텀 프로파일러 모듈을 사용할 수 있습니다. 이는 다른 시스템 지표와의 관계를 시각적으로 인식하고 성능 문제를 신속하게 식별하는 데 도움이 될 수 있습니다.
ProfilerCounterProfilerCounterValue코드에 지표 추가
다음 예제에서는 GameManager 클래스가 고수준 로직을 처리하고 적에 대해 알고 있다고 가정합니다. 카운터의 값을 업데이트하려면 또는 메서드(적을 생성하거나 파괴하는 로직을 수행하는 시점에 따라)에서 메서드를 사용하여 적의 카운터 값을 프로파일러로 푸시합니다.
UpdateLateUpdateSampleusing UnityEngine;using Unity.Profiling;class GameManager : MonoBehaviour{ 적[] m_Enemies; void Update() { GameStats.EnemyCount.Sample(m_Enemies.Length); }}
총알 수를 프로파일러에 전달하기 위해 이 예제에서는 총알 라이프사이클을 관리하는 셸 스크립트가 있다고 가정합니다. 그런 다음 게임의 현재 총알 흐름에 대한 정확한 정보를 제공하기 위해 값을 단위로 증가시키고 단위로 줄입니다.
GameStats.BulletCountAwakeOnDestroyusing UnityEngine;using Unity.Profiling;public class Shell : MonoBehaviour{ void Awake() { GameStats.BulletCount.Value += 1; } void OnDestroy() { GameStats.BulletCount.Value -= 1; }}
프로파일러 창 커스텀 모듈 추가
시각화를 위해 빌트인 또는 새로 추가된 카운터를 선택하려면 프로파일러 모듈 에디터를 사용합니다. 프로파일러 모듈 에디터를 열려면 다음 단계를 따르십시오.
- 프로파일러 창(Window > Analysis > Profiler)을 엽니다.
- 창 왼쪽 상단의 Profiler Module 드롭다운을 선택합니다. 기어 아이콘을 클릭 수 프로파일러 모듈 에디터가 새 창에서 열립니다.
- 추가를 선택한 다음 창 오른쪽의 사용자 목록에서 시각화할 카운터를 선택합니다.
그러면 프로파일러 창 다른 카운터와 함께 데이터를 볼 수 있습니다. 자세한 내용은 커스텀 프로파일러 모듈 생성을 참고하십시오.

Module with custom counters in Profiler Window.
빌드된 플레이어에서 프로파일러 카운터 시각화
빌드된 플레이어에서 프로젝트를 실행하면 프로파일러 창 액세스할 수 없습니다. 하지만 빌드된 플레이어에서 카운터를 UI 요소로 표시할 수 있습니다. 따라서 애플리케이션 빌드에 프로파일링 툴을 포함할 수 있습니다.
다음 이미지는 빌드된 플레이어의 커스텀 UI를 사용하여 씬의 왼쪽 상단에 있는 카운터를 보여줍니다.

Tanks game with custom information overlaid
플레이어의 카운터 값 가져오기
프로파일러 카운터는 중요한 게임 또는 엔진 시스템 지표에 대한 인사이트를 제공합니다. 지속적인 통합 설정이 있거나 테스트 플레이 중에 애플리케이션의 주요 성능 지표를 시각화하려는 경우 API를 사용하여 맞춤형 및 빌트인 프로파일러 카운터 값을 가져올 수 있습니다.
ProfilerRecorder예를 들어 다음 스크립트는 프레임 시간, Mono/IL2CPP 힙 크기 및 애플리케이션이 사용하는 총 메모리를 표시합니다.
using System.Collections.Generic;using System.Text;using Unity.Profiling;using UnityEngine;public class StatsScript : MonoBehaviour{ string statsText; ProfilerRecorder systemMemoryRecorder; ProfilerRecorder gcMemoryRecorder; ProfilerRecorder mainThreadTimeRecorder; 더블 GetRecorderFrameAverage(ProfilerRecorder Recorder) { var samplesCount = recorder.Capacity; if (samplesCount == 0) return 0; double r = 0; 안전하지 않음 { var samples = stackalloc ProfilerRecorderSample[samplesCount]; recorder.CopyTo(samples, samplesCount); for (var i = 0; i < samplesCount; ++i) r += samples[i].Value; r /= samplesCount; } return r; } void OnEnable() { systemMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "System Used Memory"); gcMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "GC Reserved Memory"); mainThreadTimeRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Internal, "Main Thread", 15); } void OnDisable() { systemMemoryRecorder.Dispose(); gcMemoryRecorder.Dispose(); mainThreadTimeRecorder.Dispose(); } void Update() { var sb = new StringBuilder(500); sb.AppendLine($"Frame Time: {GetRecorderFrameAverage(mainThreadTimeRecorder) * (1e-6f):F1} ms"); sb.AppendLine($"GC Memory: {gcMemoryRecorder.LastValue / (1024 * 1024)} MB"); sb.AppendLine($"System Memory: {systemMemoryRecorder.LastValue / (1024 * 1024)} MB"); statsText = sb.ToString(); } void OnGUI() { GUI.TextArea(new Rect(10, 30, 250, 50), statsText); }}
에디터에서 프로파일러 프레임 데이터에서 카운터 값 가져오기
에디터에서 프로파일러 프레임 데이터를 처리할 때 프로파일러 카운터 값을 가져오려면 API를 사용하십시오.
FrameDataView다음과 같이 특정 카운터의 프레임 값을 얻기 위해 , , 및 를 사용할 수 있습니다.
FrameDataView.GetCounterValueAsIntFrameDataView.GetCounterValueAsLongFrameDataView.GetCounterValueAsFloatFrameDataView.GetCounterValueAsDoubleusing UnityEditor.Profiling;클래스 예시{ static int ExtractMyCounterValue(FrameDataView frameData, string counterName) { var counterMarkerId = frameData.GetMarkerId(counterName); return frameData.GetCounterValueAsInt(counterMarkerId); }}