博客
关于我
分享一个大佬们通用帧耗时检测工具,无论预制体还是粒子都能用
阅读量: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/

你可能感兴趣的文章
Myeclipse常用快捷键
查看>>
MyEclipse更改项目名web发布名字不改问题
查看>>
MyEclipse用(JDBC)连接SQL出现的问题~
查看>>
mt-datetime-picker type="date" 时间格式 bug
查看>>
myeclipse的新建severlet不见解决方法
查看>>
MyEclipse设置当前行背景颜色、选中单词前景色、背景色
查看>>
Mtab书签导航程序 LinkStore/getIcon SQL注入漏洞复现
查看>>
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>
MySQL
查看>>
mysql
查看>>
MTK Android 如何获取系统权限
查看>>
MySQL - 4种基本索引、聚簇索引和非聚索引、索引失效情况、SQL 优化
查看>>
MySQL - ERROR 1406
查看>>
mysql - 视图
查看>>