Esempio n. 1
0
        void Init()
        {
            if (data == null)
            {
                data = new PackedMemoryData();
            }

            if (!memoryFilters)
            {
                memoryFilters = AssetDatabase.LoadAssetAtPath <MemoryFilterSettings>("Assets/GoProfiler/Editor/MemoryFilters.asset");
            }

            if (toolBarStyle == null)
            {
                toolBarStyle                  = new GUIStyle();
                toolBarStyle.alignment        = TextAnchor.MiddleCenter;
                toolBarStyle.normal.textColor = Color.white;
                toolBarStyle.fontStyle        = FontStyle.Bold;
            }
            if (memoryRootNode == null)
            {
                Debug.Log("Go-Profiler Init");
                memoryRootNode = new PackedItemNode("Root");
                IncomingSnapshot(data.mSnapshot);
            }
        }
Esempio n. 2
0
 void LoadFromMindMap(string fileName)
 {
     //data = null;  //reset data
     using (FileStream stream = new FileStream(fileName, FileMode.Open))
     {
         using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8))
         {
             Stack <PackedItemNode> stack = new Stack <PackedItemNode>();
             int lastTabCount             = 0;
             while (reader.Peek() >= 0)
             {
                 int    tabCount   = 0;
                 int    spaceIndex = 0;
                 string line       = reader.ReadLine();
                 char[] charArray  = line.ToCharArray();
                 for (int i = 0; i < charArray.Length; i++)
                 {
                     if (charArray[i] == '\t')
                     {
                         tabCount++;
                         continue;
                     }
                     else if (charArray[i] == ' ')
                     {
                         spaceIndex = i;
                     }
                 }
                 string         itemName = line.Substring(tabCount, spaceIndex - tabCount);
                 string         sizeStr  = line.Substring(spaceIndex + 1);
                 PackedItemNode node     = new PackedItemNode(itemName);
                 node.sizeStr = sizeStr;
                 if (tabCount == 0 && lastTabCount == 0)
                 {
                     memoryRootNode = node;
                 }
                 else if (tabCount < lastTabCount)
                 {
                     while (lastTabCount-- > tabCount)
                     {
                         stack.Pop();
                     }
                     stack.Pop();
                     stack.Peek().AddNode(node);
                 }
                 else if (tabCount > lastTabCount)
                 {
                     stack.Peek().AddNode(node);
                 }
                 else
                 {
                     stack.Pop();
                     stack.Peek().AddNode(node);
                 }
                 stack.Push(node);
                 lastTabCount = tabCount;
             }
             memoryRootNode.SetCount();
             //memoryRootNode.Convert();
             //memoryRootNode.Sort();
         }
     }
 }
Esempio n. 3
0
        void SetNodeByClassID(int classID, PackedItemNode nodeRoot, List <PackedNativeUnityEngineObject> nativeUnityObjectList)
        {
            nodeRoot.Clear();
            nodeRoot.nativeType = data.mSnapshot.nativeTypes [classID];

            int index = -1;

            if (memoryFilters)
            {
                for (int i = 0; i < memoryFilters.memoryFilterList.Count; i++)
                {
                    if ((int)memoryFilters.memoryFilterList[i].classID == classID)
                    {
                        index = i;
                    }
                }
            }

            if (index > -1)            //这样写好蛋疼啊0.0
            {
                Dictionary <PackedItemNode, RegexElement> tempDict = new Dictionary <PackedItemNode, RegexElement>();
                PackedItemNode otherNode = new PackedItemNode("Others");
                otherNode.nativeType = data.mSnapshot.nativeTypes [classID];
                nodeRoot.AddNode(otherNode);
                MemoryFilter memoryFilter = memoryFilters.memoryFilterList[index];
                for (int i = 0; i < memoryFilter.regexElementList.Count; i++)
                {
                    PackedItemNode filterNode = new PackedItemNode(memoryFilter.regexElementList[i].key, true);
                    filterNode.nativeType = data.mSnapshot.nativeTypes [classID];
                    nodeRoot.AddNode(filterNode);
                    tempDict.Add(filterNode, memoryFilter.regexElementList[i]);
                }
                while (nativeUnityObjectList.Count > 0)
                {
                    PackedNativeUnityEngineObject item = nativeUnityObjectList[0];
                    string         name      = item.name;
                    PackedItemNode childNode = new PackedItemNode(name);
                    childNode.size       = item.size;
                    childNode.instanceID = item.instanceId;
                    childNode.nativeType = data.mSnapshot.nativeTypes [classID];

                    bool isMatch = false;
                    using (var i = tempDict.GetEnumerator())//replace foreach
                    {
                        while (i.MoveNext())
                        {
                            RegexElement regexElement = i.Current.Value;

                            for (int j = 0; j < regexElement.regexList.Count; j++)
                            {
                                if (StringMatchWith(name, regexElement.regexList[j]))
                                {
                                    i.Current.Key.AddNode(childNode);
                                    isMatch = true;
                                    break;
                                }
                            }
                            if (isMatch)
                            {
                                break;
                            }
                        }
                    }
                    if (!isMatch)
                    {
                        otherNode.AddNode(childNode);
                    }
                    nativeUnityObjectList.RemoveAt(0);
                }
            }
            else
            {
                for (int i = 0; i < nativeUnityObjectList.Count; i++)
                {
                    PackedNativeUnityEngineObject item = nativeUnityObjectList[i];
                    string         name = item.name;
                    PackedItemNode node = new PackedItemNode(name);
                    node.size       = item.size;
                    node.instanceID = item.instanceId;
                    node.nativeType = data.mSnapshot.nativeTypes [classID];
                    nodeRoot.AddNode(node);
                }
            }
        }
Esempio n. 4
0
        void IncomingSnapshot(PackedMemorySnapshot snapshot)
        {
            if (null == snapshot)
            {
                return;
            }
            lastRefreshTime = DateTime.Now;
            Debug.Log("GoProfilerWindow.IncomingSnapshot");
            data.mSnapshot = snapshot;
            memoryRootNode = new PackedItemNode("Root");
            PackedItemNode assetsRoot           = new PackedItemNode("Assets");
            PackedItemNode sceneMemoryRoot      = new PackedItemNode("SceneMemory");
            PackedItemNode notSavedRoot         = new PackedItemNode("NotSaved");
            PackedItemNode builtinResourcesRoot = new PackedItemNode("BuiltinResources");
            PackedItemNode unknownRoot          = new PackedItemNode("Unknown");

            //PackedItemNode managerNode = PackedItemNode.BuildNode<PackedItemNode>("Managers");
            memoryRootNode.AddNode(assetsRoot);
            memoryRootNode.AddNode(sceneMemoryRoot);
            memoryRootNode.AddNode(notSavedRoot);
            memoryRootNode.AddNode(builtinResourcesRoot);
            //assetsRoot.AddNode(managerNode);
            Dictionary <int, Group> assetGroup                         = new Dictionary <int, Group>();
            Dictionary <int, Group> sceneMemoryGroup                   = new Dictionary <int, Group>();
            Dictionary <int, Group> notSavedGroup                      = new Dictionary <int, Group>();
            Dictionary <int, Group> builtinResourcesGroup              = new Dictionary <int, Group>();
            Dictionary <int, Group> unknownGroup                       = new Dictionary <int, Group>();//I can't find any unknown object yet.
            List <PackedNativeUnityEngineObject> assetsObjectList      = new List <PackedNativeUnityEngineObject>();
            List <PackedNativeUnityEngineObject> sceneMemoryObjectList = new List <PackedNativeUnityEngineObject>();
            List <PackedNativeUnityEngineObject> notSavedObjectList    = new List <PackedNativeUnityEngineObject>();
            List <PackedNativeUnityEngineObject> builtinResourcesList  = new List <PackedNativeUnityEngineObject>();
            List <PackedNativeUnityEngineObject> unknownObjectList     = new List <PackedNativeUnityEngineObject>();

            //List<PackedNativeUnityEngineObject> managerList = new List<PackedNativeUnityEngineObject>();
            for (int i = 0; i < snapshot.nativeObjects.Length; i++)
            {
                PackedNativeUnityEngineObject obj = snapshot.nativeObjects[i];
                if (obj.isPersistent && ((obj.hideFlags & HideFlags.DontUnloadUnusedAsset) == 0))
                {
                    assetsObjectList.Add(obj);
                }
                else if (!obj.isPersistent && obj.hideFlags == HideFlags.None)
                {
                    sceneMemoryObjectList.Add(obj);
                }
                else if (!obj.isPersistent && (obj.hideFlags & HideFlags.HideAndDontSave) != 0)
                {
                    notSavedObjectList.Add(obj);
                }
                else if (obj.isPersistent && (obj.hideFlags & HideFlags.HideAndDontSave) != 0)
                {
                    builtinResourcesList.Add(obj);
                }
                else
                {
                    unknownObjectList.Add(obj);
                }
            }
            if (unknownObjectList.Count > 0)//I can't find any unknown object yet.
            {
                memoryRootNode.AddNode(unknownRoot);
            }
            for (int i = 0; i < assetsObjectList.Count; i++)
            {
                PackedNativeUnityEngineObject assetsObject = assetsObjectList[i];
                if (!assetGroup.ContainsKey(assetsObject.nativeTypeArrayIndex))
                {
                    assetGroup.Add(assetsObject.nativeTypeArrayIndex, new Group(assetsObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[assetsObject.nativeTypeArrayIndex].name));
                }
                assetGroup[assetsObject.nativeTypeArrayIndex].packedNativeObjectList.Add(assetsObject);
            }
            for (int i = 0; i < sceneMemoryObjectList.Count; i++)
            {
                PackedNativeUnityEngineObject sceneObject = sceneMemoryObjectList[i];
                if (!sceneMemoryGroup.ContainsKey(sceneObject.nativeTypeArrayIndex))
                {
                    sceneMemoryGroup.Add(sceneObject.nativeTypeArrayIndex, new Group(sceneObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[sceneObject.nativeTypeArrayIndex].name));
                }
                sceneMemoryGroup[sceneObject.nativeTypeArrayIndex].packedNativeObjectList.Add(sceneObject);
            }
            for (int i = 0; i < notSavedObjectList.Count; i++)
            {
                PackedNativeUnityEngineObject notSavedObject = notSavedObjectList[i];
                if (!notSavedGroup.ContainsKey(notSavedObject.nativeTypeArrayIndex))
                {
                    notSavedGroup.Add(notSavedObject.nativeTypeArrayIndex, new Group(notSavedObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[notSavedObject.nativeTypeArrayIndex].name));
                }
                notSavedGroup[notSavedObject.nativeTypeArrayIndex].packedNativeObjectList.Add(notSavedObject);
            }
            for (int i = 0; i < builtinResourcesList.Count; i++)
            {
                PackedNativeUnityEngineObject builtinResourcesObject = builtinResourcesList[i];
                if (!builtinResourcesGroup.ContainsKey(builtinResourcesObject.nativeTypeArrayIndex))
                {
                    builtinResourcesGroup.Add(builtinResourcesObject.nativeTypeArrayIndex, new Group(builtinResourcesObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[builtinResourcesObject.nativeTypeArrayIndex].name));
                }
                builtinResourcesGroup[builtinResourcesObject.nativeTypeArrayIndex].packedNativeObjectList.Add(builtinResourcesObject);
            }
            for (int i = 0; i < unknownObjectList.Count; i++)
            {
                PackedNativeUnityEngineObject unknownObject = unknownObjectList[i];
                if (!unknownGroup.ContainsKey(unknownObject.nativeTypeArrayIndex))
                {
                    unknownGroup.Add(unknownObject.nativeTypeArrayIndex, new Group(unknownObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[unknownObject.nativeTypeArrayIndex].name));
                }
                unknownGroup[unknownObject.nativeTypeArrayIndex].packedNativeObjectList.Add(unknownObject);
            }
            using (var i = assetGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        assetsRoot.AddNode(group.itemNode);
                    }
                }
            }
            using (var i = sceneMemoryGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        sceneMemoryRoot.AddNode(group.itemNode);
                    }
                }
            }
            using (var i = notSavedGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        notSavedRoot.AddNode(group.itemNode);
                    }
                }
            }
            using (var i = builtinResourcesGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        builtinResourcesRoot.AddNode(group.itemNode);
                    }
                }
            }
            using (var i = unknownGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        unknownRoot.AddNode(group.itemNode);
                    }
                }
            }
            memoryRootNode.SetCount();
            memoryRootNode.Convert();
            memoryRootNode.Sort();
            //ClearEditorReferences();//To release gc and memory.
            RemoveNotification();
        }
Esempio n. 5
0
 public void OnDisable()
 {
     MemorySnapshot.OnSnapshotReceived -= IncomingSnapshot;
     selectedObject = null;
 }
Esempio n. 6
0
 public Group(int classId, string typeName)
 {
     this.classId           = classId;
     packedNativeObjectList = new List <PackedNativeUnityEngineObject> ();
     itemNode = new PackedItemNode(typeName);
 }