private int CompareObject(ObjectAlloction a, ObjectAlloction b) { if (a == null && b != null) { return(1); } if (a != null && b == null) { return(-1); } if (a.allocated > b.allocated) { return(-1); } if (a.allocated < b.allocated) { return(1); } return(0); }
private void Update() { if (mbProfiling == false) { return; } mDeltaTime += Time.deltaTime; if (mDeltaTime > 1.0f) { // // 1. 清除当前数据 // mMethodAllocations.Clear(); mCurrentMethodCallStack = null; mCurrentMethodAlloction = null; // // 2. 重新获得数据 // MonoProfilerHelper.Pause(); MonoProfilerHelper.BeginMethodIterator(); { do { if (Filter(MonoProfilerHelper.GetMethodCallStackString())) { MethodAlloction method = new MethodAlloction(); { method.name = MonoProfilerHelper.GetMethodString(); method.stack = MonoProfilerHelper.GetMethodCallStackString(); method.allocated = MonoProfilerHelper.GetMethodAllocSize(); method.allocatedDelta = MonoProfilerHelper.GetMethodAllocSizeDelta(); MonoProfilerHelper.BeginObjectIterator(); { do { ObjectAlloction obj = new ObjectAlloction(); { obj.name = MonoProfilerHelper.GetObjectString(); obj.allocated = MonoProfilerHelper.GetObjectAllocSize(); } method.objects.Add(obj); } while (MonoProfilerHelper.NextObjectIterator()); } MonoProfilerHelper.EndObjectIterator(); } mMethodAllocations.Add(method); } } while (MonoProfilerHelper.NextMethodIterator()); } MonoProfilerHelper.EndMethodIterator(); MonoProfilerHelper.Resume(); // // 3. 排序 // if (mMethodAllocations.Count > 0) { mMethodAllocations.Sort(CompareMethod); mCurrentMethodCallStack = mMethodAllocations[0].stack; mCurrentMethodAlloction = mMethodAllocations[0]; } // // 4. 重绘 // Repaint(); // // 5. 重新计数 // mDeltaTime = 0.0f; } }