Android 프로파일링
앱인토스 Unity 게임을 Android 환경에서 효과적으로 프로파일링하여 성능 최적화 포인트를 찾는 방법을 제공합니다.
1. Android 프로파일링 도구
Unity Profiler with Android
c#
public class AndroidProfilerManager : MonoBehaviour
{
[Header("Android 프로파일링 설정")]
public bool enableDeepProfiling = true;
public bool enableGPUProfiling = true;
public ProfilerArea[] activeAreas = {
ProfilerArea.CPU,
ProfilerArea.GPU,
ProfilerArea.Rendering,
ProfilerArea.Memory,
ProfilerArea.Audio,
ProfilerArea.NetworkOperations
};
void Start()
{
#if UNITY_ANDROID && !UNITY_EDITOR
SetupAndroidProfiling();
#endif
}
void SetupAndroidProfiling()
{
// Android 전용 프로파일링 설정
Profiler.enableBinaryLog = true;
Profiler.logFile = Application.persistentDataPath + "/profiler.raw";
if (enableDeepProfiling)
{
Profiler.deepProfiling = true;
}
StartCoroutine(MonitorAndroidPerformance());
}
IEnumerator MonitorAndroidPerformance()
{
while (true)
{
// Android 특화 성능 데이터 수집
var perfData = CollectAndroidPerformanceData();
// 앱인토스 분석 시스템에 전송
AppsInToss.SendPerformanceData(perfData);
yield return new WaitForSeconds(1f);
}
}
AndroidPerformanceData CollectAndroidPerformanceData()
{
return new AndroidPerformanceData
{
cpuUsage = Profiler.GetTotalAllocatedMemory(false),
gpuUsage = SystemInfo.graphicsMemorySize,
thermalState = GetAndroidThermalState(),
batteryLevel = SystemInfo.batteryLevel,
networkType = Application.internetReachability.ToString()
};
}
string GetAndroidThermalState()
{
// Android 열 상태 확인
return AppsInToss.GetAndroidThermalState();
}
}
[System.Serializable]
public class AndroidPerformanceData
{
public long cpuUsage;
public int gpuUsage;
public string thermalState;
public float batteryLevel;
public string networkType;
}2. 메모리 프로파일링
Android 메모리 분석
c#
public class AndroidMemoryProfiler : MonoBehaviour
{
[Header("메모리 프로파일링")]
public bool enableMemoryProfiling = true;
public float profilingInterval = 5f;
private Dictionary<string, long> memorySnapshots = new Dictionary<string, long>();
void Start()
{
if (enableMemoryProfiling)
{
InvokeRepeating(nameof(TakeMemorySnapshot), profilingInterval, profilingInterval);
}
}
void TakeMemorySnapshot()
{
var snapshot = new AndroidMemorySnapshot
{
timestamp = System.DateTime.Now,
totalAllocated = Profiler.GetTotalAllocatedMemory(false),
totalReserved = Profiler.GetTotalReservedMemory(false),
totalUnused = Profiler.GetTotalUnusedReservedMemory(false),
monoUsed = Profiler.GetMonoUsedSize(),
monoHeap = Profiler.GetMonoHeapSize(),
tempAllocator = Profiler.GetTempAllocatorSize(),
gfxDriver = Profiler.GetAllocatedMemoryForGraphicsDriver(),
nativeMemory = GetNativeMemoryUsage()
};
AnalyzeMemorySnapshot(snapshot);
LogMemorySnapshot(snapshot);
}
long GetNativeMemoryUsage()
{
// Android 네이티브 메모리 사용량 확인
return Profiler.GetTotalAllocatedMemory(false) - Profiler.GetMonoUsedSize();
}
void AnalyzeMemorySnapshot(AndroidMemorySnapshot snapshot)
{
// 메모리 누수 감지
if (memorySnapshots.ContainsKey("previous"))
{
long previousTotal = memorySnapshots["previous"];
long currentTotal = snapshot.totalAllocated;
long growth = currentTotal - previousTotal;
if (growth > 10 * 1024 * 1024) // 10MB 이상 증가
{
Debug.LogWarning($"Android 메모리 급증 감지: +{growth / (1024*1024)}MB");
AppsInToss.ReportMemoryLeak(growth);
}
}
memorySnapshots["previous"] = snapshot.totalAllocated;
}
}
[System.Serializable]
public class AndroidMemorySnapshot
{
public System.DateTime timestamp;
public long totalAllocated;
public long totalReserved;
public long totalUnused;
public long monoUsed;
public long monoHeap;
public long tempAllocator;
public long gfxDriver;
public long nativeMemory;
}Android 환경에서의 정확한 프로파일링을 통해 앱인토스 게임의 성능 병목점을 식별하고 최적화하세요.
