博客
关于我
分享一个大佬们通用帧耗时检测工具,无论预制体还是粒子都能用
阅读量: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 的mysql_secure_installation安全脚本执行过程介绍
查看>>
MySQL 的Rename Table语句
查看>>
MySQL 的全局锁、表锁和行锁
查看>>
mysql 的存储引擎介绍
查看>>
MySQL 的存储引擎有哪些?为什么常用InnoDB?
查看>>
Mysql 知识回顾总结-索引
查看>>
Mysql 笔记
查看>>
MySQL 精选 60 道面试题(含答案)
查看>>
mysql 索引
查看>>
MySQL 索引失效的 15 种场景!
查看>>
MySQL 索引深入解析及优化策略
查看>>
MySQL 索引的面试题总结
查看>>
mysql 索引类型以及创建
查看>>
MySQL 索引连环问题,你能答对几个?
查看>>
Mysql 索引问题集锦
查看>>
Mysql 纵表转换为横表
查看>>
mysql 编译安装 window篇
查看>>
mysql 网络目录_联机目录数据库
查看>>
MySQL 聚簇索引&&二级索引&&辅助索引
查看>>
Mysql 脏页 脏读 脏数据
查看>>