Ejemplo n.º 1
0
    public MemObject(ThingInMemory thing, CrawledMemorySnapshot unpacked)
    {
        _thing = thing;

        if (_thing != null)
        {
            var mo = thing as ManagedObject;

            if (mo != null && mo.typeDescription.name == "System.String")
            {
                InstanceName = StringTools.ReadString(unpacked.managedHeap.Find(mo.address, unpacked.virtualMachineInformation), unpacked.virtualMachineInformation);
            }
            else
            {
                InstanceName = _thing.caption;
            }

            Size     = _thing.size;
            RefCount = _thing.referencedBy.Length;
        }
    }
Ejemplo n.º 2
0
    public void ShowDiffedSnapshots(CrawledMemorySnapshot diff1st, CrawledMemorySnapshot diff2nd)
    {
        ClearTable();
        _unpacked = diff2nd;
        if (_unpacked == null)
        {
            return;
        }

        var types1st = SnapshotUtil.PopulateTypes(diff1st);
        var types2nd = SnapshotUtil.PopulateTypes(diff2nd);

        _types = SnapshotUtil.DiffTypes(types1st, types2nd);

        var categories1st = SnapshotUtil.PopulateCategories(diff1st);
        var categories2nd = SnapshotUtil.PopulateCategories(diff2nd);

        _categoryLiterals = SnapshotUtil.FormulateCategoryLiteralsDiffed(categories1st, categories2nd);

        RefreshTables();
    }
Ejemplo n.º 3
0
    public static string GetThingContent(ThingInMemory thing, CrawledMemorySnapshot unpacked)
    {
        var mo = thing as ManagedObject;

        if (mo != null)
        {
            switch (mo.typeDescription.name)
            {
            case "System.String":
                try
                {
                    return(StringTools.ReadString(unpacked.managedHeap.Find(mo.address, unpacked.virtualMachineInformation), unpacked.virtualMachineInformation));
                }
                catch (System.Exception ex)
                {
                    //UnityEngine.Debug.LogErrorFormat("StringTools.ReadString happens error .things caption = {0} ,ex ={1} ", thing.caption, ex.ToString());
                    var bo = unpacked.managedHeap.Find(mo.address, unpacked.virtualMachineInformation);
                    if (bo.bytes == null)
                    {
                        UnityEngine.Debug.LogErrorFormat("error string,find address bytes is null ,caption = {0},address = {1},exception ={2}", thing.caption, mo.address, ex.ToString());
                        return(string.Format("error string,find address bytes is null ,caption = {0},address = {1},exception ={2}", thing.caption, mo.address, ex.ToString()));
                    }
                    else
                    {
                        var lengthPointer = bo.Add(unpacked.virtualMachineInformation.objectHeaderSize);
                        var length        = lengthPointer.ReadInt32();
                        var firstChar     = lengthPointer.Add(4);
                        UnityEngine.Debug.LogErrorFormat("error string,expect caption = {0} ,length = {1},firstChar ={2},address = {3},exception ={4}", thing.caption, length, firstChar, mo.address, ex.ToString());
                        return(string.Format("error string,expect caption = {0} ,length = {1},firstChar ={2},address = {3},exception ={4}", thing.caption, length, firstChar, mo.address, ex.ToString()));
                    }
                }

            default:
                break;
            }
        }

        return(thing.caption);
    }
Ejemplo n.º 4
0
        void Unpack()
        {
            _unpackedCrawl = CrawlDataUnpacker.Unpack(_packedCrawled);
            m_Status       = "Loading snapshot in Grid .....";
#if !UNITY_5_6_OR_NEWER
            m_nodeView.ClearNodeView();
            bCheckHeapOnly = true;
#endif
            if (bCheckHeapOnly)
            {
                m_nodeView.CreateTreelessView(_unpackedCrawl);
            }
            else
            {
                Array.Sort(_unpackedCrawl.nativeObjects, new NativeUnityEngineObjectComparer());
                Array.Sort(_unpackedCrawl.managedObjects, new ManagedObjectComparer());
                m_nodeView.bShowMemHeap = false;
#if UNITY_5_6_OR_NEWER
                m_TreeModel.SetData(populateData(_unpackedCrawl.allObjects.Length));
                m_TreeView.Reload();
#endif
            }
            m_Status = "Snapshot Loaded!";
        }
Ejemplo n.º 5
0
    public void RefreshData(CrawledMemorySnapshot unpackedCrawl, CrawledMemorySnapshot preUnpackedCrawl = null)
    {
        _unpacked    = unpackedCrawl;
        _preUnpacked = preUnpackedCrawl;
        _types.Clear();
        _categories.Clear();
        _staticDetailInfo.clear();
        foreach (ThingInMemory thingInMemory in _unpacked.allObjects)
        {
            string typeName = MemUtil.GetGroupName(thingInMemory);
            if (typeName.Length == 0)
            {
                continue;
            }

            int category = MemUtil.GetCategory(thingInMemory);

            MemObject item = new MemObject(thingInMemory, _unpacked);
            if (!_staticDetailInfo.isDetailStaticFileds(typeName, thingInMemory.caption, item.Size))
            {
                MemType theType;
                if (!_types.ContainsKey(typeName))
                {
                    theType          = new MemType();
                    theType.TypeName = MemUtil.GetCategoryLiteral(thingInMemory) + typeName;
                    theType.Category = category;
                    theType.Objects  = new List <object>();
                    _types.Add(typeName, theType);
                }
                else
                {
                    theType = _types[typeName];
                }
                theType.AddObject(item);
            }

            MemCategory theCategory;
            if (!_categories.TryGetValue(category, out theCategory))
            {
                theCategory          = new MemCategory();
                theCategory.Category = category;
                _categories.Add(category, theCategory);
            }
            theCategory.Size += item.Size;
            theCategory.Count++;
        }

        int[] sizes  = new int[MemConst.MemTypeCategories.Length];
        int[] counts = new int[MemConst.MemTypeCategories.Length];
        foreach (var item in _categories)
        {
            sizes[0]  += item.Value.Size;
            counts[0] += item.Value.Count;

            if (item.Key == 1)
            {
                sizes[1]  += item.Value.Size;
                counts[1] += item.Value.Count;
            }
            else if (item.Key == 2)
            {
                sizes[2]  += item.Value.Size;
                counts[2] += item.Value.Count;
            }
            else
            {
                sizes[3]  += item.Value.Size;
                counts[3] += item.Value.Count;
            }
        }

        for (int i = 0; i < _categoryLiterals.Length; i++)
        {
            _categoryLiterals[i] = string.Format("{0} ({1}, {2})", MemConst.MemTypeCategories[i], counts[i], EditorUtility.FormatBytes(sizes[i]));
        }
        freshUnpackInfos();
        checkAddtiveThings();
        checkNegativeThings();
        RefreshTables();
    }
Ejemplo n.º 6
0
 public UnPackedInfos(CrawledMemorySnapshot unpacked, CrawledMemorySnapshot preUnpacked)
 {
     this.unpacked    = unpacked;
     this.preUnpacked = preUnpacked;
 }
Ejemplo n.º 7
0
 public void setSnapshotPacked(CrawledMemorySnapshot ss)
 {
     unPacked = ss;
 }
 public void SetCompareTarget(UnityEditor.MemoryProfiler.PackedMemorySnapshot snapshot)
 {
     _snapshot      = snapshot;
     _packedCrawled = new Crawler().Crawl(_snapshot);
     _unpackedCrawl = CrawlDataUnpacker.Unpack(_packedCrawled);
 }
Ejemplo n.º 9
0
 public virtual bool SaveSessionInfo(PackedMemorySnapshot packed, CrawledMemorySnapshot unpacked)
 {
     return(false);
 }
Ejemplo n.º 10
0
    public override bool SaveSessionJson(CrawledMemorySnapshot Unpacked)
    {
        string sessionName = _sessionTimeStr + TrackerModeConsts.EditorTag;

        return(TrackerModeUtil.SaveSnapshotJson(sessionName, _selected.ToString() + ".json", Unpacked));
    }
    public override bool SaveSessionInfo(PackedMemorySnapshot packed, CrawledMemorySnapshot unpacked)
    {
        string sessionName = _sessionTimeStr + TrackerModeConsts.RemoteTag + _IPField;

        return(TrackerModeUtil.SaveSnapshotFiles(sessionName, _selected.ToString(), packed, unpacked));
    }
Ejemplo n.º 12
0
 public void CreateTreelessView(CrawledMemorySnapshot unpackedCrawl)
 {
     _unpackedCrawl = unpackedCrawl;
     bShowMemHeap   = true;
 }
Ejemplo n.º 13
0
 public virtual bool SaveSessionJson(CrawledMemorySnapshot Unpacked)
 {
     return(false);
 }
 public void CreateTreelessView(CrawledMemorySnapshot unpackedCrawl)
 {
     _unpackedCrawl = unpackedCrawl;
     bShowMemHeap   = true;
     memUsageSectors.Clear();
 }
Ejemplo n.º 15
0
    private void _handleModifyObj(ref Dictionary <int, ManagedObject> exceptNativeDict, KeyValuePair <int, ManagedObject> orginNat, CrawledMemorySnapshot resultPacked)
    {
        ManagedObject exceptObj;

        exceptNativeDict.TryGetValue(orginNat.Key, out exceptObj);

        if (exceptObj.address == orginNat.Value.address)
        {
            _handleDiffManangeObj(orginNat.Value, sDiffType.ModificationType, resultPacked);
        }
    }
Ejemplo n.º 16
0
    private string resolvePackedForJson(CrawledMemorySnapshot packed)
    {
        if (packed == null)
        {
            return(null);
        }
        var _unpacked = packed;

        _types.Clear();
        _categories.Clear();
        foreach (ThingInMemory thingInMemory in packed.allObjects)
        {
            string typeName = MemUtil.GetGroupName(thingInMemory);
            if (typeName.Length == 0)
            {
                continue;
            }
            int       category = MemUtil.GetCategory(thingInMemory);
            MemObject item     = new MemObject(thingInMemory, _unpacked);
            MemType   theType;
            if (!_types.ContainsKey(typeName))
            {
                theType          = new MemType();
                theType.TypeName = MemUtil.GetCategoryLiteral(thingInMemory) + typeName;
                theType.Category = category;
                theType.Objects  = new List <object>();
                _types.Add(typeName, theType);
            }
            else
            {
                theType = _types[typeName];
            }
            theType.AddObject(item);
        }

        //协议格式:
        //Data:
        //"obj" = "TypeName,Category,Count,size"
        //"info" ="RefCount,size,InstanceName,address,typeDescriptionIndex"
        //TypeDescs:
        //InstanceNames:

        Dictionary <int, string> typeDescDict     = new Dictionary <int, string>();
        Dictionary <int, string> instanceNameDict = new Dictionary <int, string>();
        var jsonData = new JsonData();

        foreach (var type in _types)
        {
            var typeData = new JsonData();
            typeData["Obj"] = type.Key + "," + type.Value.Category + "," + type.Value.Count + "," + type.Value.Size;

            var objectDatas = new JsonData();
            foreach (var obj in type.Value.Objects)
            {
                var    objectData = new JsonData();
                var    memObj     = obj as MemObject;
                string dataInfo;
                var    instanceNameHash = memObj.InstanceName.GetHashCode();
                if (!instanceNameDict.ContainsKey(instanceNameHash))
                {
                    instanceNameDict.Add(instanceNameHash, memObj.InstanceName);
                }

                dataInfo = memObj.RefCount + "," + memObj.Size + "," + instanceNameDict[instanceNameHash];
                if (type.Value.Category == 2)
                {
                    var manged = memObj._thing as ManagedObject;
                    var typeDescriptionHash = manged.typeDescription.name.GetHashCode();
                    if (!typeDescDict.ContainsKey(typeDescriptionHash))
                    {
                        typeDescDict.Add(typeDescriptionHash, manged.typeDescription.name);
                    }
                    dataInfo += "," + Convert.ToString((int)manged.address, 16) + "," + typeDescriptionHash;
                }
                objectData["info"] = dataInfo;
                objectDatas.Add(objectData);
            }
            typeData["memObj"] = objectDatas;
            jsonData.Add(typeData);
        }
        var resultJson = new JsonData();

        resultJson["Data"] = jsonData;

        StringBuilder sb = new StringBuilder();

        foreach (var key in typeDescDict.Keys)
        {
            sb.Append("[[" + key + "]:" + typeDescDict[key] + "],");
        }
        resultJson["TypeDescs"] = sb.ToString();
        sb.Remove(0, sb.Length);

        foreach (var key in instanceNameDict.Keys)
        {
            sb.Append("[[" + key + "]:" + instanceNameDict[key] + "],");
        }
        resultJson["InstanceNames"] = sb.ToString();
        return(resultJson.ToJson());
    }
Ejemplo n.º 17
0
        void TopToolBar(Rect rect)
        {
            GUILayout.BeginArea(rect);
            using (new EditorGUILayout.HorizontalScope()) {
                var style = "miniButton";
                if (GUILayout.Button("Take Snapshot", style))
                {
                    m_Status = "Taking snapshot.....";
                    UnityEditor.MemoryProfiler.MemorySnapshot.RequestNewSnapshot();
                }

                if (GUILayout.Button("Load Snapshot", style))
                {
                    m_Status = "Loading snapshot.....";
                    PackedMemorySnapshot packedSnapshot = PackedMemorySnapshotUtility.LoadFromFile();
                    if (packedSnapshot != null)
                    {
                        IncomingSnapshot(packedSnapshot);
                    }
                }

                if (_snapshot != null)
                {
                    if (GUILayout.Button("Save Snapshot", style))
                    {
                        m_Status = "Saving snapshot.....";
                        PackedMemorySnapshotUtility.SaveToFile(_snapshot);
                    }
                }

                if (GUILayout.Button("Load CrawlerData", style))
                {
                    m_Status       = "Loading CrawlerData.....";
                    _packedCrawled = PackedMemorySnapshotUtility.LoadCrawlerDataFromFile();
                    if (null != _packedCrawled)
                    {
                        m_nodeView.ClearNodeView();
                        _snapshot                = _packedCrawled.packedMemorySnapshot;
                        _unpackedCrawl           = null;
                        _packedCrawlGenerating   = true;
                        _unpackedCrawlGenerating = false;
                    }
                }

                if (_packedCrawled != null)
                {
                    if (GUILayout.Button("Save CrawlerData", style))
                    {
                        m_Status = "Saving CrawlerData.....";
                        PackedMemorySnapshotUtility.SaveCrawlerDataToFile(_packedCrawled);
                    }
                }

                if (_unpackedCrawl != null)
                {
                    if (GUILayout.Button("Show Heap Usage", style))
                    {
                        bshowPlainData = false;
                        m_nodeView.ClearNodeView();
                        m_nodeView.CreateTreelessView(_unpackedCrawl);
                    }

                    if (GUILayout.Button("Show Plain Data", style))
                    {
                        bshowPlainData = true;
                    }
                }
            }
            GUILayout.EndArea();
        }
Ejemplo n.º 18
0
    public static bool SaveSnapshotFiles(string targetSession, string targetName, PackedMemorySnapshot packed, CrawledMemorySnapshot unpacked)
    {
        string targetDir = Path.Combine(MemUtil.SnapshotsDir, targetSession);

        if (!Directory.Exists(targetDir))
        {
            Directory.CreateDirectory(targetDir);
        }

        if (!TrackerModeUtil.SaveSnapshotBin(targetDir, targetName + TrackerModeConsts.SnapshotBinPostfix, packed))
        {
            return(false);
        }

        /*if (!TrackerModeUtil.SaveSnapshotJson(targetDir, targetName + TrackerModeConsts.SnapshotJsonPostfix, unpacked))
         *  return false;*/

        Debug.LogFormat("Snapshot saved successfully. (dir: {0}, name: {1})", targetDir, targetName);
        return(true);
    }
Ejemplo n.º 19
0
    public override bool SaveSessionJson(CrawledMemorySnapshot Unpacked)
    {
        string sessionName = _sessionTimeStr + TrackerModeConsts.RemoteTag + _IPField;

        return(TrackerModeUtil.SaveSnapshotJson(sessionName, _selected.ToString(), Unpacked));
    }