UnityRuntimeProfiler

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:40   1060   0

一.插件

1.uwa

https://www.uwa4d.com/

一个账号一个月有一次免费使用的机会,还没用过。

----------------------

2.SRDebugger

一个视频教程看到的,

https://assetstore.unity.com/packages/tools/gui/srdebugger-console-tools-on-device-27688

淘宝上有

3.Advanced FPS Counter

https://assetstore.unity.com/packages/tools/utilities/advanced-fps-counter-14656

淘宝有

4.Mesh Profiler

https://assetstore.unity.com/packages/tools/modeling/mesh-profiler-158255

淘宝没找到,不是Runtime

2.2020.2的新特性

Capturing Profiler Stats at Runtime

官方教程:https://resources.unity.com/unitenow/onlinesessions/capturing-profiler-stats-at-runtime

在官方的基础上封装了一下,添加新的性能参数会方便一点

using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using UnityEngine;
using Unity.Profiling;
using Unity.Profiling.LowLevel.Unsafe;
using UnityEngine.Profiling;

public class ProfilerController : MonoBehaviour
{
    /************************************************************************************************************
    * Source: https://docs.unity3d.com/2020.2/Documentation/ScriptReference/Unity.Profiling.ProfilerRecorder.html
    *************************************************************************************************************/
    
    //public static ProfilerMarker UpdatePlayerProfilerMarker = new ProfilerMarker("Player.Update");

    string statsText;
    //ProfilerRecorder mainThreadTimeRecorder;
    //ProfilerRecorder drawCallsCountRecorder;

    static double GetRecorderFrameAverage(ProfilerRecorder recorder)
    {
        var samplesCount = recorder.Capacity;
        if (samplesCount == 0)
            return 0;

        double r = 0;
        var samples = new List<ProfilerRecorderSample>(samplesCount);
        recorder.CopyTo(samples);
        for (var i = 0; i < samples.Count; ++i)
            r += samples[i].Value;
        r /= samplesCount;

        return r;
    }

    private Dictionary<string,StatInfo> statDict;

    private Dictionary<StatInfo,ProfilerRecorder> Recorders=new Dictionary<StatInfo,ProfilerRecorder>();

    private void AddProfiler(string statName){
        if(statDict==null){
            statDict=GetAvailableProfilerStats.EnumerateProfilerStats();
        }
        if(statDict.ContainsKey(statName))
        {
            StatInfo info=statDict[statName];
            //Debug.Log("AddProfiler:"+statName)
            ProfilerRecorder recorder = ProfilerRecorder.StartNew(info.Cat, statName);
            Recorders.Add(info,recorder);
        }
        else{
            Debug.LogError("No StatName:"+statName);
        }
    }

    private void AddMemoryProfiler(string statName){
        AddProfiler(statName,ProfilerCategory.Memory,ProfilerMarkerDataUnit.Bytes);
    }

    private void AddProfiler(string statName,ProfilerCategory pc,ProfilerMarkerDataUnit unit){
        if(statDict==null){
            statDict=GetAvailableProfilerStats.EnumerateProfilerStats();
        }
        if(statDict.ContainsKey(statName))
        {
            StatInfo info=statDict[statName];
            //Debug.Log("AddProfiler:"+statName)
            ProfilerRecorder recorder = ProfilerRecorder.StartNew(info.Cat, statName);
            Recorders.Add(info,recorder);
        }
        else{
            // StatInfo info=new StatInfo
            // {
            //     Name="*"+statName,
            //     Cat=pc,
            //     Unit=unit
            // };
            // ProfilerRecorder recorder = ProfilerRecorder.StartNew(info.Cat, statName);
            // Recorders.Add(info,recorder);
            Debug.LogError("No StatName:"+statName);
        }
    }

    void OnEnable()
    {
        //systemMemoryRecorder = ProfilerRecorder.StartNew(new ProfilerCategory("Memory"), "System Used Memory");
        // gcReservedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCate`MIAA5M(Tń(M
)M
MQ)UUA5
	)1U=ЙQ=1U=Й1515(5Q((I5(M	Q=((销5M1锥(销5M1锥5QQM5Q((MхЁ(Mх(I5U(=U$(U$QIР5QФ锤(销(销(销(销(>G:=b{=b=jIj5>[\**+=njc_(~j"U=jC(
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP