Пример #1
0
    private void SnapShot()
    {
        if (!Application.isPlaying)
        {
            ShowNotification(new GUIContent("请先运行游戏"));
            return;
        }

        LuaEnv      luaEnv = MemoryProfileTest.GetLuaEnv();
        LuaFunction lf     = luaEnv.Global.GetInPath <LuaFunction>("memory.snapshot");

        if (lf == null)
        {
            Debug.LogError("不存在lua函数");
        }
        string text = lf.Func <string, string>("");


        LuaMemory memory = new LuaMemory(++m_snapCount);

        string[] lines = text.Split(new string[] { "\n" }, StringSplitOptions.None);
        for (int i = 1; i < lines.Length; i++)
        {
            string line = lines[i];
            if (string.IsNullOrEmpty(line))
            {
                continue;
            }

            string[]      fields = line.Split(new char[] { ':' }, 5);
            LuaMemoryItem item   = new LuaMemoryItem();
            item.RawText = line;
            item.Name    = fields[0].Trim();
            item.Size    = long.Parse(fields[1].Trim());
            item.Type    = fields[2].Trim();
            item.ID      = fields[3].Trim();
            item.Info    = fields[4].Trim();

            //Debug.Log(line);
            //Debug.Log(item.Name + "  " + item.Size + "  " + item.Type + "  " + item.ID + "  " + item.Info);
            //Debug.Log(item.Name + ":" + item.Size + ":" + item.Type + ":" + item.ID + ":" + item.Info);

            memory.MemoryList.Add(item);
        }

        m_selectSnap = memory;
        m_snaps.Add(memory);
        SetSortType(m_sortType);
    }
Пример #2
0
    private void CalculateDiffByID(LuaMemory lm1, LuaMemory lm2)
    {
        ItemSortType rawSort = m_sortType;

        if (ItemSortType.ID == m_sortType)
        {
            m_sortDir = !m_sortDir;
        }
        SetSortType(ItemSortType.ID, lm1.MemoryList);

        if (ItemSortType.ID == m_sortType)
        {
            m_sortDir = !m_sortDir;
        }
        SetSortType(ItemSortType.ID, lm2.MemoryList);

        changeList.Clear();
        for (int i = 0, j = 0; i < lm1.MemoryList.Count || j < lm2.MemoryList.Count;)
        {
            if (i >= lm1.MemoryList.Count)
            {
                ChangeItem addItem = new ChangeItem();
                addItem.CType      = ChangeType.Add;
                addItem.Item       = lm2.MemoryList[j];
                addItem.SizeChange = lm2.MemoryList[j].Size;
                j++;
                changeList.Add(addItem);
                continue;
            }

            if (j >= lm2.MemoryList.Count)
            {
                ChangeItem removeItem = new ChangeItem();
                removeItem.CType      = ChangeType.Remove;
                removeItem.Item       = lm1.MemoryList[i];
                removeItem.SizeChange = -lm1.MemoryList[i].Size;
                i++;
                changeList.Add(removeItem);
                continue;
            }

            LuaMemoryItem item1 = lm1.MemoryList[i];
            LuaMemoryItem item2 = lm2.MemoryList[j];

            ChangeItem changeItem = new ChangeItem();
            changeList.Add(changeItem);
            if (string.Compare(item1.ID, item2.ID) > 0)//add
            {
                changeItem.CType      = ChangeType.Add;
                changeItem.Item       = item2;
                changeItem.SizeChange = item2.Size;
                j++;
            }
            else if (string.Compare(item1.ID, item2.ID) < 0)//remove
            {
                changeItem.CType      = ChangeType.Remove;
                changeItem.Item       = item1;
                changeItem.SizeChange = -item1.Size;
                i++;
            }
            else if (string.Compare(item1.ID, item2.ID) == 0)
            {
                if (item1.Size > item2.Size)
                {
                    changeItem.CType         = ChangeType.SizeSub;
                    changeItem.SizeChangeStr = item1.Size + "->" + item2.Size;
                }
                else if (item1.Size < item2.Size)
                {
                    changeItem.CType         = ChangeType.SizeAdd;
                    changeItem.SizeChangeStr = item1.Size + "->" + item2.Size;
                }
                else
                {
                    changeItem.CType = ChangeType.None;
                }
                changeItem.SizeChange = item2.Size - item1.Size;
                changeItem.Item       = item1;
                i++;
                j++;
            }
        }

        m_sortType = rawSort;
        SortChangeList();
    }
Пример #3
0
    private void DrawItemRow(float width)
    {
        m_itemScroll = GUILayout.BeginScrollView(m_itemScroll);
        if (m_showChange)
        {
            List <ChangeItem> showList = null;
            if (m_showNoneChange)
            {
                showList = changeList;
            }
            else
            {
                if (m_ignoreRegistry)
                {
                    showList = changeList.FindAll(p => { return(p.CType != ChangeType.None && !p.Item.Type.Equals("REGISTRY")); });
                }
                else
                {
                    showList = changeList.FindAll(p => { return(p.CType != ChangeType.None); });
                }
            }

            for (int i = 0; i < showList.Count; i++)
            {
                LuaMemoryItem item = showList[i].Item;

                GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f);
                if (m_selectSnap != null && m_selectSnap.SelectItem == item)
                {
                    GUI.backgroundColor = new Color(120 / 255f, 146 / 255f, 190 / 255f);
                }

                Rect rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(20f));
                if (GUI.Button(rect, "", EditorStyles.textArea) && m_selectSnap != null)
                {
                    m_selectSnap.SelectItem = item;
                }

                GUI.backgroundColor = Color.white;
                //GUILayout.BeginHorizontal();


                SetItemColor(showList[i].CType);
                GUILayout.Label(item.Name, GUILayout.Width(itemWidth + 40));
                if (showList[i].CType == ChangeType.SizeAdd || showList[i].CType == ChangeType.SizeSub)
                {
                    GUILayout.Label(showList[i].SizeChange + "(" + showList[i].SizeChangeStr + ")", GUILayout.Width(itemWidth - 40));
                }
                else
                {
                    GUILayout.Label(item.Size.ToString(), GUILayout.Width(itemWidth - 40));
                }
                GUILayout.Label(item.Type, GUILayout.Width(itemWidth));
                GUILayout.Label(item.ID, GUILayout.Width(itemWidth));
                GUILayout.Label(item.Info);
                GUILayout.EndHorizontal();
            }
        }
        else if (m_selectSnap != null)
        {
            List <LuaMemoryItem> showList = null;
            if (m_ignoreRegistry)
            {
                showList = m_selectSnap.MemoryList.FindAll(p => { return(!p.Type.Equals("REGISTRY")); });
            }
            else
            {
                showList = m_selectSnap.MemoryList;
            }

            for (int i = 0; i < showList.Count; i++)
            {
                LuaMemoryItem item = showList[i];
                GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f);
                //GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f));
                if (m_selectSnap.SelectItem == item)
                {
                    GUI.backgroundColor = new Color(120 / 255f, 146 / 255f, 190 / 255f);
                }

                Rect rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(20f));
                if (GUI.Button(rect, "", EditorStyles.textArea))
                {
                    m_selectSnap.SelectItem = item;
                }

                GUI.backgroundColor = Color.white;
                //GUILayout.BeginHorizontal();

                GUILayout.Label(item.Name, GUILayout.Width(itemWidth + 40));
                GUILayout.Label(item.Size.ToString(), GUILayout.Width(itemWidth - 40));
                GUILayout.Label(item.Type, GUILayout.Width(itemWidth));
                GUILayout.Label(item.ID, GUILayout.Width(itemWidth));
                GUILayout.Label(item.Info);
                GUILayout.EndHorizontal();
            }
        }
        GUILayout.EndScrollView();
        GUI.contentColor = Color.white;
    }