【小松教你手游开发】【unity实用技能】unity 内存调试方法

http://blog.theknightsofunity.com/profiling-unity-application-profiler-samples/


Profiling Unity Application with Profiler Samples

The Unity Profiler Samples is something that most of Unity users are unaware of. Yet it can be extremely helpful if you want to find out what amount of resources your code takes during the execution.

If you’re already familiar with built-in profiler then you might know that by default it is not profiling all method calls. Also, the Deep Profiling causes large overhead that will significantly slow down your application execution and it even may not be possible to perform the profiling activity at all (Unity can run out of memory). The Profiler Samples are quite useful here.

Profiler Sample is a block of code that starts with Profiler.BeginSample() and ends with Profiler.EndSample() calls. Just like this:

using UnityEngine;

public class NeedsProfiling : MonoBehaviour {

    void Update() {
        Profiler.BeginSample("My Sample");
        Debug.Log("This code is beign profiled");
        Profiler.EndSample();
    }
    
}

Normally, you would put it before and after the chunk of code that you want to be profiled. Profiler Sample will record the execution time for you and it will be displayed in the Profiler window without the need to use the Deep Profiling.As you can see, there’s a new entry in the Profiler Hierarchy!

Of course you can add as many Profiler Samples as you want. It’s completely up to you! Don’t worry about adding too many samples. These calls have zero overhead when they are deployed in non-development build.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值