博客
关于我
分享一个大佬们通用帧耗时检测工具,无论预制体还是粒子都能用
阅读量:539 次
发布时间:2019-03-08

本文共 4011 字,大约阅读时间需要 13 分钟。

大佬的出品,这个界面见过很多次

 

自己实践了一遍,很多数据不知道原理,初步代码如下:

IEnumerator AnalyseSingleFx(GameObject fxObj,float fxLoadTime, string fxPath)    {        var report =new EffectPerformance();        reports.Add(report);        report.Path = fxPath;        System.GC.Collect();        AsyncOperation ao = Resources.UnloadUnusedAssets();        yield return ao;        yield return new WaitForEndOfFrame();                //加载        float t1 = 0;//        float t1 = Time.realtimeSinceStartup;//        //GameObject fxObj = null;//        //var fxRes = App loadobject//        report.LoadTime = Time.realtimeSinceStartup - t1;//        yield return new WaitForEndOfFrame();        report.LoadTime = fxLoadTime;                if(fxObj==null) yield break;        report.totalPsCount = fxObj.GetComponentsInChildren
(true).Length; Renderer[] fxRenderers = fxObj.GetComponentsInChildren
(); Dictionary
fxMaterials = new Dictionary
(); int active = 0; foreach (var r in fxRenderers) { bool has = false; if(r.sharedMaterial!=null && fxMaterials.TryGetValue(r.sharedMaterial,out has)==false){ fxMaterials.Add(r.sharedMaterial,true); } if (r.enabled) active++; } report.activeRendercount = active; report.materialCount = fxMaterials.Count; yield return new WaitForEndOfFrame(); GameObject someFxInst = null; t1 = Time.realtimeSinceStartup; //实例化 for (int i = 0; i < testCount; i++) { GameObject go = Instantiate(fxObj); go.transform.position = Vector3.zero; fxCopies.Add(go); if (i == 0) someFxInst = go; } report.InstTime = (Time.realtimeSinceStartup - t1) * 1000f / testCount; ParticleSystem[] psInsts = someFxInst.GetComponentsInChildren
(); //渲染,只采样一个?? yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); float t4 = 0; int frame = 0; report.MinRenderTime = float.MaxValue; report.MaxRenderTime = float.MinValue; List
timeList = new List
(); while (t4
report.MaxRenderTime) { report.MaxRenderTime = dt; report.maxRenderOccurTime = t4; } timeList.Add(dt*1000); t4 += dt; int particleCount = 0; for (int i = 0; i < psInsts.Length; i++ ) { particleCount += psInsts[i].particleCount; } if (report.maxParticleCount < particleCount) report.maxParticleCount = particleCount; yield return new WaitForEndOfFrame(); } report.MinRenderTime *= 1000 / testCount; report.maxRenderOccurTime *= 1000 / testCount; timeList.Sort(); timeList.Reverse(); float avg = 0; int topN = Mathf.Min(topNFrame, timeList.Count); for(int i=0;i
texNames = GetTextureMemAndCount(); foreach (var t in texNames) { if (localTexNames.ContainsKey(t.Key) == false) { report.TexNameList.Add(t.Key,t.Value); report.texMemBytes +=t.Value.bytes; report.texMemCount++; } } //清理// foreach (var fx in fxCopies)// {// UnityEngine.Object.DestroyImmediate(fx);// }// fxCopies.Clear(); reportDoneCount++; Debug.Log("完成测算过+1"); yield return new WaitForEndOfFrame(); }
public class EffectPerformance{    public string Path;    ///     /// 加载时间    ///     public float LoadTime;    ///     /// 平均实例化时间    ///     public float InstTime;    public float MinRenderTime;    public float MaxRenderTime;        //最长渲染帧耗时    public float topNFramesAvgRenderTime;    public float maxRenderOccurTime;    //渲染的最长时间的一帧发生在第几秒    ///     /// 激活的渲染个数    ///     public int activeRendercount;        //激活的渲染个数    public int totalPsCount;            //全部粒子个数,包括未激活    public int materialCount;            //材质个数    public int maxParticleCount;        //最大粒子个数    public int texMemBytes;            //所用贴图内存    public int texMemCount;            //所用贴图个数    public  Dictionary
TexNameList = new Dictionary
();}

 

转载地址:http://eoiiz.baihongyu.com/

你可能感兴趣的文章
Mysql Row_Format 参数讲解
查看>>
mysql select, from ,join ,on ,where groupby,having ,order by limit的执行顺序和书写顺序
查看>>
MySQL Server 5.5安装记录
查看>>
mysql server has gone away
查看>>
mysql slave 停了_slave 停止。求解决方法
查看>>
MySQL SQL 优化指南:主键、ORDER BY、GROUP BY 和 UPDATE 优化详解
查看>>
MYSQL sql语句针对数据记录时间范围查询的效率对比
查看>>
mysql sum 没返回,如果没有找到任何值,我如何在MySQL中获得SUM函数以返回'0'?
查看>>
mysql Timestamp时间隔了8小时
查看>>
Mysql tinyint(1)与tinyint(4)的区别
查看>>
mysql union orderby 无效
查看>>
mysql v$session_Oracle 进程查看v$session
查看>>
mysql where中如何判断不为空
查看>>
MySQL Workbench 使用手册:从入门到精通
查看>>
mysql workbench6.3.5_MySQL Workbench
查看>>
MySQL Workbench安装教程以及菜单汉化
查看>>
MySQL Xtrabackup 安装、备份、恢复
查看>>
mysql [Err] 1436 - Thread stack overrun: 129464 bytes used of a 286720 byte stack, and 160000 bytes
查看>>
MySQL _ MySQL常用操作
查看>>
MySQL – 导出数据成csv
查看>>