라이브러리 초기화 및 작업 확인

이 페이지에서는 게임 코드에서 라이브러리를 초기화하고 Google Play에 데이터를 업로드하고 있는지 확인하는 방법을 설명합니다. 특정 라이브러리 함수에 관해 자세히 알아보려면 참조 문서를 확인하세요.

라이브러리 초기화

게임 시작 시 초기화 메서드에서 다음과 같이 AndroidPerformanceTuner를 인스턴스화하고 Start() 메서드를 호출하여 라이브러리를 초기화합니다.

using Google.Android.PerformanceTuner;
using UnityEngine;

public class SomeBehaviour : MonoBehaviour
{
    AndroidPerformanceTuner<FidelityParams, Annotation> tuner =
            new AndroidPerformanceTuner<FidelityParams, Annotation>();

    void Start()
    {
        ErrorCode startErrorCode = tuner.Start();
        Debug.Log("Android Performance Tuner started with code: " + startErrorCode);

        tuner.onReceiveUploadLog += request =>
        {
            Debug.Log("Telemetry uploaded with request name: " + request.name);
        };
    }
}

이 코드로 충분히 Android Performance Tuner를 시작하고 게임을 계측할 수 있습니다. 로그 구문은 Android Performance Tuner가 시작된 시기 및 원격 분석이 Google Play Console API에 업로드된 시기를 나타냅니다. 나중에 플러그인이 올바르게 작동하는지 확인하기 위해 로그에서 이러한 구문을 찾아볼 수 있습니다.

늦은 초기화(Vulkan만 해당)

게임이 Vulkan을 타겟팅하고 Android Frame Pacing을 사용한다면 Android Performance Tuner에는 늦은 초기화가 있어야 합니다.

IEnumerator Start()
{
    yield return new WaitForEndOfFrame();
    ErrorCode startErrorCode = tuner.Start();
    Debug.Log("Android Performance Tuner started with code: " + startErrorCode);

    tuner.onReceiveUploadLog += request =>
    {
        Debug.Log("Telemetry uploaded with request name: " + request.name);
    };
}

원격 분석 업로드 간의 간격 확인

플러그인 설정에서 원격 분석 업로드 간의 기본 간격은 30초입니다. 이 시간은 원격 분석의 적절한 업로드를 쉽게 확인할 수 있도록 짧은 간격으로 설정됩니다. 게임을 프로덕션으로 출시할 때 게임이 API에 너무 많은 요청을 하지 않도록 이 시간을 긴 간격(예: 매 10분)으로 설정합니다. 이는 무제한 데이터가 포함된 모바일 데이터 요금제가 없는 사용자에게 특히 중요합니다. 또한 간격을 길게 설정하면 기기 배터리가 과도하게 사용되는 것을 방지합니다.

간격이 30초로 설정되어 있는지 확인하려면 다음 단계를 따르세요.

  1. Google > Android Performance Tuner를 선택하여 설정에 액세스합니다.
  2. Instrumentation Settings(계측 설정) 탭을 선택하고 Use advanced settings(고급 설정 사용)를 클릭합니다.
  3. Intervals (minutes)(간격[분]) 필드에 0.5가 있는지 확인합니다.

플러그인의 Instrumentation Settings(계측 설정)

적절한 작업 확인

IL2CPP 또는 코드 스트리핑을 사용하고 있다면 코드 스트리핑 관리를 참고하세요.

Android용 게임을 빌드합니다. 게임이 기기에서 실행되는 동안 컴퓨터에서 터미널을 열고 다음과 같이 adb logcat을 실행합니다.

adb logcat

다음과 같이 adb logcat의 출력에서 'TuningFork'를 검색합니다(Tuning Fork는 라이브러리의 내부 이름임).

02-03 16:55:45.103 10511 10536 I TuningFork: Got settings from tuningfork/tuningfork_settings.bin
02-03 16:55:45.103 10511 10536 I TuningFork: Using local file cache at /data/user/0/com.Unity3d.BoatAttackDay/cache/tuningfork
02-03 16:55:45.105 10511 10536 I TuningFork: OpenGL version 3.2
02-03 16:55:45.105 10511 10536 I TuningFork: TuningFork.GoogleEndpoint: OK
02-03 16:55:45.106 10511 10611 I TuningFork: Creating directory /data/user/0/com.Unity3d.BoatAttackDay/cache/tuningfork
02-03 16:55:45.106 10511 10536 I TuningFork: TuningFork Settings:

[...]

02-03 16:55:45.116 10511 10536 I Unity   : Tuningfork started with code: Ok
02-03 16:55:45.107 10511 10536 I TuningFork: TuningFork initialized
02-03 16:55:45.107 10511 10536 I UnityTuningfork: Swappy backend: 1
02-03 16:55:45.107 10511 10536 I TuningFork: Creating directory /data/user/0/com.Unity3d.BoatAttackDay/cache/tuningfork/V1
02-03 16:55:45.110 10511 10613 I TuningFork: OpenGL version 3.2
02-03 16:55:45.110 10511 10613 I TuningFork:Web: Connecting to: https://performanceparameters.googleapis.com/v1/applications/com.Unity3d.BoatAttackDay/apks/1:generateTuningParameters

플러그인을 설정하는 동안 API 키 설정을 잊어버리는 등 실수를 한 경우 다음과 같이 초기화 로그에 오류가 표시됩니다.

02-03 16:49:44.970  8815  8831 I TuningFork: Got settings from tuningfork/tuningfork_settings.bin
02-03 16:49:44.971  8815  8831 I TuningFork: Using local file cache at /data/user/0/com.Unity3d.BoatAttackDay/cache/tuningfork
02-03 16:49:44.972  8815  8831 I TuningFork: OpenGL version 3.2
02-03 16:49:44.972  8815  8831 W TuningFork.GE: The API key in Tuning Fork TFSettings is invalid
02-03 16:49:44.972  8815  8831 E TuningFork: TuningFork.GoogleEndpoint: FAILED
02-03 16:49:44.973  8815  8831 I Unity   : Tuningfork started with code: BadParameter

Android Performance Tuner가 원격 분석을 업로드하는지 확인합니다. 로그에 TuningFork initialized가 표시되면 조금 더 기다렸다가 원격 분석이 업로드되고 있음을 나타내는 로그를 찾습니다.

02-03 16:58:00.552 10511 10611 I TuningFork:Web: Connecting to: https://performanceparameters.googleapis.com/v1/applications/com.Unity3d.BoatAttackDay/apks/1:uploadTelemetry
02-03 16:58:00.898 10511 10611 I TuningFork:Web: Response code: 200
02-03 16:58:00.898 10511 10611 I TuningFork:Web: Response message: OK
02-03 16:58:00.899 10511 10611 I TuningFork.GE: UPLOAD request returned 200 {}

로그에서 'Connecting to:(연결 중:)'를 검색할 수도 있습니다. 이 메시지 몇 줄 뒤에는 응답 코드가 나옵니다.

원격 분석 업로드 로그가 표시되지 않으면 Android Performance Tuner 설정에서 각 업로드 간의 간격을 30초와 같은 작은 값으로 적절하게 설정했는지 확인합니다.

코드 스트리핑 관리

Google.Protobuf.dll은 리플렉션을 사용합니다. 코드 스트리핑 도중에 필수 코드 중 일부가 삭제될 수 있습니다. 이러한 삭제를 방지하기 위해 플러그인에는 보존해야 하는 기호에 관한 정보가 있는 link.xml 파일이 포함되어 있습니다. 리플렉션을 사용하는 protobuf의 일부 기능이 필요하며 코드 스트리핑을 사용 설정했다면 이 정보를 link.xml 파일에 추가하여 기호를 보존합니다.

Unity 문서에서 관리형 코드 스트리핑에 관한 자세한 내용을 확인할 수 있습니다.

protobuf의 모든 기호를 보존해야 한다면 다음이 포함된 link.xml 파일을 프로젝트에 추가합니다.

<linker>
  <assembly fullname="Google.Protobuf" preserve="all"/>
</linker>

AOT(Ahead-of-time) 컴파일

IL2CPP 백엔드와 Unity 버전 2017 및 2018에는 AOT 컴파일이 필요합니다(Unity 최신 버전에는 필요하지 않음).

AOT 컴파일러는 제네릭 메서드의 코드를 생성하지 않을 수 있습니다. 다음 메서드를 추가하여 컴파일러가 protobuf에 필요한 적절한 코드를 생성하도록 강제해야 합니다.

using Google.Protobuf.Reflection;
using UnityEngine.Scripting;

...

// Don't call this method.
[Preserve]
void ExampleOfForceReflectionInitializationForProtobuf()
{
    FileDescriptor.ForceReflectionInitialization<Scene>();
    FileDescriptor.ForceReflectionInitialization<ShadowType>();
    FileDescriptor.ForceReflectionInitialization<LevelType>();
    ...
    // Add FileDescriptor.ForceReflectionInitialization<T> for each generated enum.
    // You can find the list of enums in DevTuningfork.cs -> enum section
    // or in the list of enums in Google -> Android Performance Tuner.
}

Unity 문서에서 스크립팅 제한사항에 관한 자세한 내용을 확인할 수 있습니다.