Exemple #1
0
    private void DrawMethodMemory(int index, string name, uint size, uint delta, uint totalSize)
    {
        Color lastColor = GUI.color;

        {
            Rect rect = new Rect(0, index * 22, 0.5f * Screen.width * size / totalSize, 20);

            Color color;
            color.r = 1.0f * size / totalSize;
            color.g = 1.0f - color.r;
            color.b = 0;
            color.a = 1;

            GUIStyle style = new GUIStyle("label");
            style.clipping = TextClipping.Overflow;

            GUI.color = color;
            if (GUI.Button(rect, ""))
            {
                mbProfiling             = false;
                mCurrentMethodCallStack = mMethodAllocations[index].stack;
                mCurrentMethodAlloction = mMethodAllocations[index];
                MonoProfilerHelper.Pause();
            }
            GUI.Label(rect, name + ": " + (size / 1024.0f / 1024.0f).ToString() + "MB" + " Delta: " + (delta / 1024.0f / 1024.0f) + "MB", style);
        }
        GUI.color = lastColor;
    }
Exemple #2
0
 private void OnDisable()
 {
     MonoProfilerHelper.Pause();
     mMethodAllocations.Clear();
     mCurrentMethodCallStack = null;
     mCurrentMethodAlloction = null;
 }
Exemple #3
0
 private void OnEnable()
 {
     MonoProfilerHelper.Init("C:\\Program Files (x86)\\Unity\\Editor\\Data\\Mono\\EmbedRuntime\\mono.dll");
     MonoProfilerHelper.Pause();
     mMethodAllocations.Clear();
     mCurrentMethodCallStack = null;
     mCurrentMethodAlloction = null;
 }
Exemple #4
0
    private void DrawToolBar()
    {
        //
        // 1. 自适应窗口
        //
        int pos   = 0;
        int space = 5;
        int width = (int)(Screen.width * 0.1f);

        width = Mathf.Max(width, 75);
        width = Mathf.Min(width, 100);
        pos   = (Screen.width - width * 3 - space * 2) / 2;

        //
        // 2. 分析按钮
        //
        bool bProfiling = GUI.Toggle(new Rect(pos, 5, width, 20), mbProfiling, "Profiler", "button");

        if (mbProfiling != bProfiling)
        {
            if (bProfiling)
            {
                mDeltaTime  = 0.0f;
                mbProfiling = true;
                MonoProfilerHelper.Resume();
            }
            else
            {
                mDeltaTime  = 0.0f;
                mbProfiling = false;
                MonoProfilerHelper.Pause();
            }
        }

        //
        // 3. 清除数据
        //
        if (GUI.Button(new Rect(pos + width + space, 5, width, 20), "Clear"))
        {
            mMethodAllocations.Clear();
            mCurrentMethodCallStack = null;
            mCurrentMethodAlloction = null;
            MonoProfilerHelper.Clear();
        }

        //
        // 4. 输出到文件
        //
        if (GUI.Button(new Rect(pos + 2 * (width + space), 5, width, 20), "Dump"))
        {
            string path = EditorUtility.SaveFilePanel("Dump mono memory", "", "mono", "txt");
            if (path != null)
            {
                MonoProfilerHelper.Dump(path);
            }
        }
    }
Exemple #5
0
 private int CompareMethod(MethodAlloction a, MethodAlloction 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);
 }
Exemple #6
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;
        }
    }