用于将一帧内的所有样本相加,并将这些样本作为每帧一个样本进行收集。
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); } } }