---
title: 코드에 프로파일러 마커 추가
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/ko-kr/engine/6000.0/manual/analysis/profiler/customizing/adding-information-code/add-markers-code
latest_url: https://docs.unity.com/ko-kr/engine/7000.0/manual/analysis/profiler/customizing/adding-information-code/add-markers-code.md
last_updated: 2026-10-30
generated_at: 2026-11-19T16:38:42.956Z
locale: ko-kr
---

# 코드에 프로파일러 마커 추가

> 프로파일러 마커를 추가하여 코드의 영역을 마킹합니다.

코드에 [프로파일러 마커를](/engine/6000.0/manual/analysis/profiler/customizing/adding-information-code/intro.md) 추가하여 `ProfilerMarker.Begin`, `ProfilerMarker.End` 또는 `ProfilerMarker.Auto`가 생성하는 샘플을 [프로파일러 창](/engine/6000.0/manual/analysis/profiler/window.md)의 [CPU 사용 모듈](/engine/6000.0/manual/analysis/profiler/visualizing-data/cpu/introduction.md)의 **타임라인 뷰** 및 **계층 구조 뷰**에서 확인합니다.


**Profiler sample with metadata in Timeline View.:**
![](/api/media?file=/engine/6000.0/media/images/profiler-marker-metadata-timeline.png)


**Profiler sample with metadata in Hierarchy View.:**
![](/api/media?file=/engine/6000.0/media/images/profiler-marker-metadata-hierarchy.png)

## 필수 조건##prerequisites

일부 예제에서는 시작하기 전에 설치해야 하는 [Profiling Core 패키지](https://docs.unity3d.com/Packages/com.unity.profiling.core@latest)를 사용합니다. Unity 프로파일링 코어 패키지는 코어 패키지이므로 패키지 관리자 UI에서 검색할 수 없습니다. 패키지를 설치하려면 `com.unity.profiling.core`인 이름으로 패키지를 [추가합니다](/engine/6000.0/manual/packages-list/managing-packages-window/upm-ui-actions/upm-ui-quick.md).

## 코드 마킹##marking-up-your-code

[`ProfilerMarker` API를](/engine/6000.0/script-reference/unity/profiling/profilermarker.md) 사용하려면 `ProfilerMarker.Begin` 및 `ProfilerMarker.End` 호출 사이에 프로파일링할 코드를 넣으십시오. 예제는 아래와 같습니다.

```lang-cs
using 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();
    }
}
```

> **Note:**
>
> 프로파일러 창이 CPU 프로파일러 모듈의 차트 뷰에서 마커를 강조 표시할 수 없도록 프로파일러 마커의 이름에 `/` 문자를 사용하지 마십시오.

`End`가 호출되기 전에 `Begin` 및 `End` 호출 사이의 코드가 범위를 벗어나지 않도록 합니다. `End`가 호출되기 전에 코드가 범위를 벗어나면 오류 메시지가 콘솔에 기록됩니다. 모든 반환 전에 `End`를 호출하지 않으려면 샘플이 범위를 벗어나면 자동으로 종료되도록 `Auto`를 사용하십시오. 자세한 내용은 이 문서의 [자동 닫기 프로파일러 마커 코드 블록](#automatically-close) 섹션을 참조하십시오.

Unity는 프로파일링된 코드 블록의 실행 시간을 기록하고 프로파일러에 보고하여 [세부 프로파일링](/engine/6000.0/manual/analysis/profiler/deep-profiling.md)을 사용하지 않고도 [CPU 프로파일러 모듈](/engine/6000.0/manual/analysis/profiler/visualizing-data/cpu/introduction.md)에 표시합니다. CPU 프로파일러 모듈의 **계층 구조 뷰**에 새 항목으로 표시됩니다.


**Profiler sample in the Profiler Window.:**
![](/api/media?file=/engine/6000.0/media/images/profiler-marker-full-sample.png)

### 프로파일러 마커 코드 블록 자동 닫기##automatically-close-profiler-marker-code-blocks

`ProfilerMarker.Auto`를 사용하여 코드 블록 끝에 `ProfilerMarker.End`가 자동으로 호출되도록 합니다. 다음 호출은 동일합니다.

```lang-cs
using 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()` 호출과 달리, Unity는 개발(릴리스)가 아닌 빌드에서 `ProfilerMarker.Auto` 호출을 컴파일할 수 없습니다. 그러나 대신 null 반환하여 최소한의 오버헤드만 추가합니다.

`using var`와 함께 `ProfilerMarker.Auto`를 사용할 수도 있으며 현재 범위가 종료되면 `End` 호출이 자동으로 수행됩니다. 이 접근 방식은 코드에 `ProfilerMarker` 인스턴스를 추가할 때 변경해야 하는 코드의 양을 최소화합니다.

```lang-cs
using Unity.Profiling;

public class MySystemClass
{
    static readonly ProfilerMarker k_UpdatePerfMarker = new ProfilerMarker("MySystem.Update");

    public void Update()
    {
        using var _ = k_UpdatePerfMarker.Auto();
        // ...
    }
}
```

> **Note:**
>
> `ProfilerMarker`로 표시된 영역 내의 모든 비동기 `await` 및 모든 `yield` 호출은 지원되지 않으며, `Auto`를 사용하더라도 콘솔에 오류 메시지가 기록됩니다.

## 샘플에 정수 또는 부동 소수점 파라미터 추가##adding-integer-or-floating-point-parameters-to-samples

코드 샘플에 컨텍스트를 추가하여 코드가 오랫동안 실행되는 특정 조건을 식별할 수도 있습니다.

예를 들어 시스템에서 오브젝트 시뮬레이션을 수행하는 경우 프로파일러 샘플로 오브젝트 수를 전달할 수 있습니다. 프로파일러가 샘플 길이와 함께 비정상적인 숫자를 반환하면 시뮬레이션을 위해 다른 스레드를 사용하거나 CPU 작업을 여러 프레임으로 분할(타임라이싱)하거나 애플리케이션 설계를 조정하여 프레임 저하를 방지해야 할 수 있습니다.

`ProfilerMarker`는 최대 3개의 숫자 파라미터([`ProfilerMarker<TP1>`](https://docs.unity3d.com/Packages/com.unity.profiling.core@1.0/api/Unity.Profiling.ProfilerMarker-1.html), [`ProfilerMarker<TP1, TP2>`](https://docs.unity3d.com/Packages/com.unity.profiling.core@1.0/api/Unity.Profiling.ProfilerMarker-2.html) 및 [`ProfilerMarker<TP1, TP2, TP3>`](https://docs.unity3d.com/Packages/com.unity.profiling.core@1.0/api/Unity.Profiling.ProfilerMarker-3.html))를 지원합니다.

```lang-cs
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))
    {
      // ...
    }
  }
}
```

## 샘플에 문자열 파라미터 추가##adding-string-parameters-to-samples

`ProfilerMarker` API는 프로파일러 마커에 문자열 파라미터를 추가할 수 있습니다. 문자열 파라미터는 애플리케이션이 레벨 또는 데이터 파일을 로드할 때 레벨 또는 파일의 이름을 표시하려는 경우에 유용합니다. [`ProfilerMarkerExtension`](https://docs.unity3d.com/Packages/com.unity.profiling.core@1.0/api/Unity.Profiling.ProfilerMarkerExtension.html) 메서드를 사용하여 프로파일러 샘플과 함께 문자열 파라미터를 전달합니다.

```lang-cs
using 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();
  }
}
```

## 추가 리소스##additional-resources

* [코드 소개에 프로파일링 정보 추가](/engine/6000.0/manual/analysis/profiler/customizing/adding-information-code/intro.md)
* [코드에 프로파일러 카운터 추가](/engine/6000.0/manual/analysis/profiler/customizing/adding-information-code/add-counters-code.md)
* [CPU 사용 프로파일러 모듈 소개](/engine/6000.0/manual/analysis/profiler/visualizing-data/cpu/introduction.md)
* [`ProfilerMarker` API](/engine/6000.0/script-reference/unity/profiling/profilermarker.md)
* [코어 패키지 프로파일링](https://docs.unity3d.com/Packages/com.unity.profiling.core@latest)
