Unity.Profiling.ProfilerRecorderOptions.SumAllSamplesInFrame

Unity · Версия 2020.3 LTS · Scripting · ProfilerRecorderOptions

Unity.Profiling.ProfilerRecorderOptions.SumAllSamplesInFrame

Описание

Используйте, чтобы суммировать все выборки в кадре и собирать их как одну выборку на кадр.

using System;
using Unity.Profiling;
using UnityEngine;

public class CollectGCAllocCountExample2
{
    static void PrintGCAllocCount(Action a)
    {
        using (var gcAllocRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Internal, "GC.Alloc", 1, ProfilerRecorderOptions.SumAllSamplesInFrame | ProfilerRecorderOptions.CollectOnlyOnCurrentThread))
        {
            a.Invoke();

            gcAllocRecorder.Stop();

            var count = gcAllocRecorder.Count == 0 ? 0 : gcAllocRecorder.GetSample(0).Count;
            Debug.Log("GC allocs count: " + count);
        }
    }
}

Обновлено 17 ноября 2026 г.