Esempio n. 1
0
    public bool AcceptSnapshot(PackedMemorySnapshot packed)
    {
        _totalCount = 0;
        _totalSize  = 0;

        try
        {
            MemUtil.LoadSnapshotProgress(0.01f, "crawling");
            var crawled = new Crawler().Crawl(packed);

            MemUtil.LoadSnapshotProgress(0.7f, "unpacking");
            _unpacked = CrawlDataUnpacker.Unpack(crawled);

            MemUtil.LoadSnapshotProgress(0.9f, "populating");
            foreach (var thing in _unpacked.allObjects)
            {
                _totalSize += thing.size;
                _totalCount++;
            }
            MemUtil.LoadSnapshotProgress(1.0f, "done");
        }
        catch (System.Exception ex)
        {
            Debug.LogException(ex);
            _unpacked = null;
        }

        return(true);
    }
        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
            }
            //Debug.Log("Snapshot Loaded! " + _unpackedCrawl);
            m_Status = "Snapshot Loaded!";
        }
Esempio n. 3
0
    bool savePackedInfoByJson(string output, PackedMemorySnapshot packed)
    {
        MemUtil.LoadSnapshotProgress(0.01f, "creating Crawler");

        var tempCrawled = new Crawler().Crawl(packed);

        MemUtil.LoadSnapshotProgress(0.7f, "unpacking");

        var unPacked = CrawlDataUnpacker.Unpack(tempCrawled);

        MemUtil.LoadSnapshotProgress(1.0f, "done");

        try
        {
            var resolveJson = resolvePackedForJson(unPacked);
            if (string.IsNullOrEmpty(resolveJson))
            {
                throw  new Exception("Resolve Json Data Failed");
            }

            StreamWriter sw;
            FileInfo     fileInfo = new FileInfo(output);
            sw = fileInfo.CreateText();
            sw.Write(resolveJson);
            sw.Close();
            sw.Dispose();
            UnityEngine.Debug.Log("write Json successed");
            return(true);
        }
        catch (System.Exception ex)
        {
            UnityEngine.Debug.LogErrorFormat("write json file error {0},errMsg = {1}", output, ex.Message);
            return(false);
        }
    }
        void Unpack()
        {
            _unpackedCrawl = CrawlDataUnpacker.Unpack(_packedCrawled);
            m_Status       = "Loading snapshot in Grid .....";

            m_TreeModel.SetData(populateData(_unpackedCrawl.allObjects.Length));
            m_TreeView.Reload();
            m_Status = "Snapshot Loaded!";
        }
        void Unpack()
        {
            _unpackedCrawl = CrawlDataUnpacker.Unpack(_packedCrawled);
            m_Status       = "Loading snapshot in Grid .....";
#if !UNITY_5_6_OR_NEWER
            m_nodeView.ClearNodeView();
#endif
            m_nodeView.CreateTreelessView(_unpackedCrawl);
            m_nodeView.bShowMemHeap = false;
            Array.Sort(_unpackedCrawl.nativeObjects, new NativeUnityEngineObjectComparer());
            Array.Sort(_unpackedCrawl.managedObjects, new ManagedObjectComparer());
            m_Status = "Snapshot Loaded!";
        }
Esempio n. 6
0
    public static void ConvertMemorySnapshotIntoTab(string filepath, string targetTab = "")
    {
        try
        {
            // this block is copied from MemUtil.Load
            if (string.IsNullOrEmpty(filepath))
            {
                throw new Exception("bad_load: filename is empty.");
            }

            if (!File.Exists(filepath))
            {
                throw new Exception(string.Format("bad_load: file not found. ({0})", filepath));
            }

            PackedMemorySnapshot packed;
            using (Stream stream = File.Open(filepath, FileMode.Open))
            {
                packed = new BinaryFormatter().Deserialize(stream) as PackedMemorySnapshot;
            }
            Debug.LogFormat("file '{0}' loaded.", filepath);

            MemUtil.LoadSnapshotProgress(0.01f, "crawling");
            var crawled = new Crawler().Crawl(packed);
            Debug.LogFormat("Crawler created.");

            MemUtil.LoadSnapshotProgress(0.7f, "unpacking");
            CrawledMemorySnapshot _unpacked = CrawlDataUnpacker.Unpack(crawled);
            Debug.LogFormat("Snapshot unpacked.");

            MemUtil.LoadSnapshotProgress(0.9f, "populating");
            string targetPath = string.IsNullOrEmpty(targetTab) ? filepath + ".tab" : targetTab;
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(targetPath))
            {
                file.Write("caption\tsize\ttype\tcategory\tcontent\n");
                foreach (var thing in _unpacked.allObjects)
                {
                    file.Write("{0}\t{1}\t{2}\t{3}\t{4}\n", thing.caption, thing.size,
                               MemUtil.GetGroupName(thing), MemUtil.GetCategoryLiteral(thing), MemUtil.GetThingContent(thing, _unpacked));
                }
            }
            Debug.LogFormat("ConvertMemorySnapshotIntoTab() done. ({0})", targetPath);
            MemUtil.LoadSnapshotProgress(1.0f, "done");
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
            Debug.LogFormat("ConvertMemorySnapshotIntoTab() interrupted.");
            MemUtil.LoadSnapshotProgress(1.0f, "done");
        }
    }
 public void SetCompareTarget(UnityEditor.MemoryProfiler.PackedMemorySnapshot snapshot)
 {
     _snapshot      = snapshot;
     _packedCrawled = new Crawler().Crawl(_snapshot);
     _unpackedCrawl = CrawlDataUnpacker.Unpack(_packedCrawled);
 }