콘텐츠로 이동

Android Performance Tuner로 씬 로딩 시간 측정하기

앱 시작 시 씬 로딩에 걸리는 콜드 스타트 시간을 Android Performance Tuner(APT)로 측정한다.

씬 로드 관리자에서 GamePerformanceManager를 초기화하고, 씬 로드를 시작할 때 loading group과 loading event 기록을 시작한다. loading event는 씬의 build index로 구분한다.

public partial class SceneLoadManager
{
private GamePerformanceManager gamePerformanceManager = new GamePerformanceManager();
public ulong groupHandle;
public ulong eventHandle;
private static bool isInitializeGamePerformanceManager;
public IEnumerator Initialize()
{
yield return StartCoroutine(gamePerformanceManager.Initialize());
isInitializeGamePerformanceManager = true;
Debug.LogWarning("초기화 완료");
}
public static void LoadScene(int buildIndex, LoadSceneMode mode, string sceneName)
{
Debug.LogWarning("ADT Recording Start - " + "로드 씬 이름 : " + sceneName + "씬 인덱스 : " + buildIndex + "씬 모드 : " + mode);
Instance.groupHandle = Instance.gamePerformanceManager.StartRecordingLoadingGroup();
Instance.eventHandle = Instance.gamePerformanceManager.StartRecordingLoadingEvent(buildIndex);
}
private void CleanupLoadingScreen()
{
Debug.LogWarning("ADT Recording Stop - ");
gamePerformanceManager.StopRecordingLoadingEvent(eventHandle);
gamePerformanceManager.StopRecordingLoadingGroup(groupHandle);
}
}

씬을 바로 로드하는 경로에서는 기록을 시작한 뒤 SceneManager.LoadSceneAsync를 호출하고, sceneLoaded 콜백에서 기록을 멈춘다. 같은 구간을 Stopwatch로도 재서 로그로 비교한다.

public void LoadSceneImmediately(string scene, LoadSceneMode loadSceneMode = LoadSceneMode.Additive)
{
//SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive);
int sceneIndex = SceneUtility.GetBuildIndexByScenePath(scene);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
LoadScene(sceneIndex, loadSceneMode, scene);
SceneManager.LoadSceneAsync(scene, LoadSceneMode.Single);
SceneManager.sceneLoaded += (Scene sceneLoaded, LoadSceneMode mode) =>
{
CleanupLoadingScreen();
stopwatch.Stop();
Debug.LogWarning("LoadSceneImmediately 실행 시간: " + stopwatch.ElapsedMilliseconds + "ms");
};
sceneName = string.Empty;
}