# 코드 서두에 프로파일링 정보 추가

> Use profiler markers and counters to collect specific data about your application.

기본적으로 [프로파일러 창](/engine/6000.0/manual/analysis/profiler/window-reference.md)에는 Unity의 네이티브 코드에 대한 정보가 표시됩니다. 이는 [빌트인 프로파일러 마커](/engine/6000.0/manual/analysis/profiler/markers.md)를 사용하여 수집한 성능 데이터를 정리하고 분할합니다.

프로파일러 마커를 자체 코드에 추가해서 프로파일러 창의 [`ProfilerMarker` API](/engine/6000.0/script-reference/unity-profiling/profiler-marker.md)를 사용하여 이러한 영역에 소요된 시간을 표시할 수 있습니다.

또한 코드에 프로파일러 카운터를 추가하여 애플리케이션의 지표 관련 데이터를 수집하고, [커스텀 프로파일러 모듈](/engine/6000.0/manual/analysis/profiler/collect-data/visualizing-data/customizing/creating-custom-modules.md)을 사용해 해당 데이터를 표시할 수도 있습니다. 이는 애플리케이션의 성능 변경 사항을 추적할 때 유용하게 사용할 수 있습니다. 프로파일러 카운터를 코드에 추가하면 카운터의 정보를 Unity의 빌트인 카운터 및 계측 데이터와 함께 활용해서 성능 문제를 더욱 빠르게 조사할 수 있습니다.

메타데이터가 포함된 카운터와 마커를 코드에 추가하려면 [Unity Profiling Core](https://docs.unity3d.com/Packages/com.unity.profiling.core@latest?subfolder=/manual/index.html) 패키지를 사용해야 합니다.

**중요:** Unity Profiling Core 패키지는 코어 패키지이므로 패키지 관리자 UI에서 검색할 수 없습니다. 패키지를 설치하려면 [이름으로 패키지를 추가합니다](/engine/6000.0/manual/packages-list/packages/upm-ui/actions/quick.md)(`com.unity.profiling.core`). [이 링크를 통해](/engine/6000.0/manual/com-unity-profiling.md) 설치할 수도 있습니다.

## 프로파일러 마커

[`ProfilerMarker` API](/engine/6000.0/script-reference/unity-profiling/profiler-marker.md)를 사용해서 리소스 집약적인 스크립트 코드 블록을 표시해 Unity 프로파일러에서 확인할 수 있게 하거나, [Unity Profiling Core](https://docs.unity3d.com/Packages/com.unity.profiling.core@latest?subfolder=/manual/index.html) 패키지의 [`ProfilerMarker<TP1>` API](https://docs.unity3d.com/Packages/com.unity.profiling.core@1.0/api/Unity.Profiling.ProfilerMarker-1.html)를 사용하여 생성된 각 샘플에 [메타데이터를 추가](/engine/6000.0/manual/um-profiler-add-markers-code.md#Adding-integer-or-floating-point-parameters-to-samples)할 수 있습니다.

빌트인 Unity 프로파일러가 모든 메서드 호출을 프로파일링하는 않으므로 이 기능은 유용하게 활용할 수 있습니다. 다른 방법은 [세부 프로파일링](/engine/6000.0/manual/analysis/profiler/collect-data/deep-profiling.md)을 사용하는 것입니다. 그러나 이 방법은 애플리케이션 실행 속도를 크게 저하하고 결과를 왜곡시키는 큰 오버헤드를 일으킵니다. `ProfilerMarker`를 사용하면 코드를 더욱 효율적으로 표시할 수 있습니다.

`ProfilerMarker`는 이름이 지정된 프로파일러 핸들을 나타내며 코드를 프로파일링하는 가장 효율적인 방법입니다. 이는 모든 애플리케이션의 C# 코드에서 사용할 수 있습니다.

Unity가 프로파일러 마커를 비개발 빌드에 배포하면 프로파일러 마커에 오버헤드가 발생하지 않으므로 얼마든지 많은 샘플을 마킹할 수 있습니다.

Unity는 [`ConditionalAttribute`](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.conditionalattribute?view=net-8.0)로 `Begin` 및 `End` 메서드를 표시하고 조건부로 컴파일하므로, 비개발 빌드에서는 관련 실행 오버헤드가 발생하지 않습니다. `Auto` 메서드는 비개발 빌드에서 완전히 컴파일되지 않지만, null만 반환하도록 조건부로 컴파일되므로 오버헤드는 미미합니다. 프로파일러 마커의 필드는 릴리스 빌드에 존재하며 그 [`IntPtr`](https://learn.microsoft.com/en-us/dotnet/api/system.intptr?view=net-8.0)와 동일하게 8바이트의 메모리를 차지합니다.

또한 [`ProfilerRecorder`](/engine/6000.0/script-reference/unity-profiling/profiler-recorder.md) API는 프로파일러 마커를 사용하여 성능 데이터를 캡처합니다. Unity 에디터 및 개발 플레이어에서 개발하는 동안, API를 사용하여 코드의 다양한 부분에 대한 성능 개요를 확보하고 성능 문제를 찾아낼 수 있습니다.

## 프로파일러 카운터

Unity 프로파일러에 커스텀 지표를 표시하려면 [Unity Profiling Core](https://docs.unity3d.com/Packages/com.unity.profiling.core@latest?subfolder=/manual/index.html) 패키지의 `ProfilerCounter` API를 사용하십시오. 프로파일러는 [`ProfilerCounter`](https://docs.unity3d.com/Packages/com.unity.profiling.core@1.0/api/Unity.Profiling.ProfilerCounter-1.html) 또는 [`ProfilerCounterValue`](https://docs.unity3d.com/Packages/com.unity.profiling.core@1.0/api/Unity.Profiling.ProfilerCounterValue-1.html)의 데이터를 표시할 수 있습니다.

Unity는 카운터가 프로파일링하는 작업의 유형(렌더링, 스크립팅, 애니메이션 등)에 따라 프로파일러 카운터를 범주화합니다. 커스텀 프로파일러 카운터는 Unity의 어떤 프로파일링 범주에든 할당할 수 있습니다. 사용 가능한 모든 프로파일러 범주의 목록은 [`ProfilerCategory`](/engine/6000.0/script-reference/unity-profiling/profiler-category.md)에서 확인하십시오.

`ProfilerCounter` 또는 `ProfilerCounterValue` API를 사용하여 애플리케이션의 지표를 추적하고 Unity 프로파일러 또는 기타 코드에 확인할 수 있도록 만들 수 있습니다. 에셋 스토어 패키지 개발자는 자신의 코드에 프로파일러 카운터를 추가하여 다른 개발자가 시스템의 중요한 성능적 특성을 이해하는 데 도움을 줄 수 있으며, 해당 정보를 최적화 또는 예산 책정 툴에 사용할 수 있습니다.

다음 도표는 프로파일러 카운터 데이터 플로를 개괄적으로 보여줍니다.


**프로파일러 카운터 플로.:**
![](/api/media?file=/engine/6000.0/media/images/profiler-counter-diagram.png)

[`ProfilerRecorder`](/engine/6000.0/script-reference/unity-profiling/profiler-recorder.md) API는 애플리케이션 코드에서 프로파일러 카운터 데이터를 가져오고, [`RawFrameDataView`](/engine/6000.0/script-reference/unity-editor-profiling/raw-frame-data-view.md) 또는 [`HierarchyFrameDataView`](/engine/6000.0/script-reference/unity-editor-profiling/hierarchy-frame-data-view.md) API는 에디터 코드에서 프로파일러 카운터 데이터를 가져옵니다. 이 카운터 데이터는 [모듈 에디터에서 커스텀 프로파일러 모듈을 설정하여](/engine/6000.0/manual/analysis/profiler/adding-information-code/creating-custom-counters.md) 프로파일러 창에서 시각화할 수 있습니다.

`ProfilerCounter`와 `ProfilerCounterValue`는 다음 유형을 지원하지 않습니다.

* int
* long
* float
* double

## 추가 리소스

* [코드에 프로파일러 마커 추가](/engine/6000.0/manual/analysis/profiler/adding-information-code/add-markers-code.md)
* [코드에 프로파일러 카운터 추가](/engine/6000.0/manual/analysis/profiler/adding-information-code/add-counters-code.md)
* [프로파일러 카운터 시각화](/engine/6000.0/manual/analysis/profiler/adding-information-code/creating-custom-counters.md)
* [`ProfilerMarker` API](/engine/6000.0/script-reference/unity-profiling/profiler-marker.md)
* [Profiling Core 패키지](https://docs.unity3d.com/Packages/com.unity.profiling.core@latest)
