코드에 프로파일러 마커 추가
프로파일러 마커를 추가하여 코드의 영역을 마킹합니다.
읽는 시간 3분최근 업데이트: 9일 전
코드에 프로파일러 마커를 추가하여 , 또는 가 생성하는 샘플을 프로파일러 창의 CPU 사용 모듈의 타임라인 뷰 및 계층 구조 뷰에서 확인합니다.
ProfilerMarker.BeginProfilerMarker.EndProfilerMarker.Auto
Profiler sample with metadata in Timeline View.

Profiler sample with metadata in Hierarchy View.
필수 조건
일부 예제에서는 시작하기 전에 설치해야 하는 Profiling Core 패키지를 사용합니다. Unity 프로파일링 코어 패키지는 코어 패키지이므로 패키지 관리자 UI에서 검색할 수 없습니다. 패키지를 설치하려면 인 이름으로 패키지를 추가합니다.
com.unity.profiling.core코드 마킹
ProfilerMarkerProfilerMarker.BeginProfilerMarker.Endusing UnityEngine;using Unity.Profiling;public class ProfilerMarkerExample{ static readonly ProfilerMarker k_MyCodeMarker = new ProfilerMarker("My Code"); void Update() { k_MyCodeMarker.Begin(); Debug.Log("This code is being profiled"); k_MyCodeMarker.End(); }}
EndBeginEndEndEndAutoUnity는 프로파일링된 코드 블록의 실행 시간을 기록하고 프로파일러에 보고하여 세부 프로파일링을 사용하지 않고도 CPU 프로파일러 모듈에 표시합니다. CPU 프로파일러 모듈의 계층 구조 뷰에 새 항목으로 표시됩니다.

Profiler sample in the Profiler Window.
프로파일러 마커 코드 블록 자동 닫기
ProfilerMarker.AutoProfilerMarker.Endusing Unity.Profiling;public class MySystemClass{ static readonly ProfilerMarker k_UpdatePerfMarker = new ProfilerMarker("MySystem.Update"); public void Update() { k_UpdatePerfMarker.Begin(); // ... k_UpdatePerfMarker.End(); using (k_UpdatePerfMarker.Auto()) { // ... } }}
Begin()End()ProfilerMarker.Autousing varProfilerMarker.AutoEndProfilerMarkerusing Unity.Profiling;public class MySystemClass{ static readonly ProfilerMarker k_UpdatePerfMarker = new ProfilerMarker("MySystem.Update"); public void Update() { using var _ = k_UpdatePerfMarker.Auto(); // ... }}
샘플에 정수 또는 부동 소수점 파라미터 추가
코드 샘플에 컨텍스트를 추가하여 코드가 오랫동안 실행되는 특정 조건을 식별할 수도 있습니다.
예를 들어 시스템에서 오브젝트 시뮬레이션을 수행하는 경우 프로파일러 샘플로 오브젝트 수를 전달할 수 있습니다. 프로파일러가 샘플 길이와 함께 비정상적인 숫자를 반환하면 시뮬레이션을 위해 다른 스레드를 사용하거나 CPU 작업을 여러 프레임으로 분할(타임라이싱)하거나 애플리케이션 설계를 조정하여 프레임 저하를 방지해야 할 수 있습니다.
ProfilerMarkerProfilerMarker<TP1>ProfilerMarker<TP1, TP2>ProfilerMarker<TP1, TP2, TP3>using Unity.Profiling;public class MySystemClass{ 정적 읽기 전용 ProfilerMarker<int> k_PreparePerfMarker = 새로운 ProfilerMarker<int>("MySystem.Prepare", "Objects Count"); 정적 읽기 전용 ProfilerMarker<float> k_SimulatePerfMarker = 새로운 ProfilerMarker<float>(ProfilerCategory.Scripts, "MySystem.Simulate", "Objects Density"); public void Update(int objectsCount) { k_PreparePerfMarker.Begin(objectsCount); // ... k_PreparePerfMarker.End(); using (k_SimulatePerfMarker.Auto(objectsCount * 1.0f)) { // ... } }}
샘플에 문자열 파라미터 추가
ProfilerMarkerProfilerMarkerExtensionusing Unity.Profiling;public class MySystemClass{ static readonly ProfilerMarker k_PreparePerfMarker = new ProfilerMarker("MySystem.Prepare"); public void Prepare(string path) { k_PreparePerfMarker.Begin(path); // ... k_PreparePerfMarker.End(); }}