using UnityEngine;
using System.Collections.Generic;
using UnityEngine.Profiling;

public class TestProfiler : MonoBehaviour
{
int t = 10000;

// 每帧Update都会进行校验和运行
void Update()
{
Check(t); // 校验
Run(); // 运行
}

void Check(int n)
{
Profiler.BeginSample("Check");
CheckA(); // 校验模块A

Profiler.BeginSample("Calculate b");
// 数值运算
int b = n - 100;
if (b < 10)
b = 10;
Profiler.EndSample();

CheckB(b); // 校验模块B
Profiler.EndSample();
}

void CheckA()
{
Profiler.BeginSample("CheckA");
Debug.Log("校验模块A");
Profiler.EndSample();
}

void CheckB(int loopCount)
{
Profiler.BeginSample("CheckB");
Debug.Log("校验模块B");

Profiler.BeginSample("new List<string>");
List<string> strList = new List<string>();
Profiler.EndSample();

for (int i = 0; i < loopCount; ++i)
{
Profiler.BeginSample("Add str to list");
string str = string.Format("CheckB:{0}", i);
strList.Add(str);
Profiler.EndSample();
}

Debug.Log(string.Format("list count: {0}", strList.Count));
Profiler.EndSample();
}

void Run()
{
Profiler.BeginSample("Run");
Debug.Log("开始运行");
DoSomething();
Profiler.EndSample();
}

void DoSomething()
{
}

}