unity的profile很方便但有时会出现找不到耗时操作的脚本的情况,如:
在代码中加入如下代码段,可以定位到耗时的代码
UnityEngine.Profiling.Profiler.BeginSample("225 SetDataContext");
// 耗时代码 ....balabala
UnityEngine.Profiling.Profiler.EndSample();
注意:BeginSample 和End之间不能有return 关键字 ,否则可能会定位错误。
这个可以更深层次的跟随
各种profile工具
https://docs.unity3d.com/Packages/com.unity.performance.profile-analyzer@1.1/manual/index.html
UNITY profile-analyzer // CPU
ARM MOBILE STUDIO // GPU