博客
关于我
分享一个大佬们通用帧耗时检测工具,无论预制体还是粒子都能用
阅读量: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 备份 Xtrabackup
查看>>
mYSQL 外键约束
查看>>
mysql 多个表关联查询查询时间长的问题
查看>>
mySQL 多个表求多个count
查看>>
mysql 多字段删除重复数据,保留最小id数据
查看>>
MySQL 多表联合查询:UNION 和 JOIN 分析
查看>>
MySQL 大数据量快速插入方法和语句优化
查看>>
mysql 如何给SQL添加索引
查看>>
mysql 字段区分大小写
查看>>
mysql 字段合并问题(group_concat)
查看>>
mysql 字段类型类型
查看>>
MySQL 字符串截取函数,字段截取,字符串截取
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>